Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date().add(components:) doesn't work when daylight saving time changes #315

Closed
jsslai opened this issue Oct 24, 2016 · 1 comment
Closed

Comments

@jsslai
Copy link

jsslai commented Oct 24, 2016

I noticed Date().add method returns incorrect date when daylight saving time changes between start and end dates. Test case:

func test_additionDuringDaylightSavingTimeChange() {
        let d_helsinki = Region(tz: TimeZoneName.europeHelsinki, cal: CalendarName.gregorian, loc: LocaleName.finnishFinland)
        Date.setDefaultRegion(d_helsinki)

        let date1 = try! DateInRegion(components: [.year: 2016, .month: 10, .day: 24], fromRegion: d_helsinki).absoluteDate // 2016-10-24 00:00:00 GMT+3
        let date2 = try! DateInRegion(components: [.year: 2016, .month: 10, .day: 31], fromRegion: d_helsinki).absoluteDate // 2016-10-31 00:00:00 GMT+2
        let date3 = date1.add(components: [Calendar.Component.weekOfYear: 1]) // 2016-10-30 23:00:00 GMT+2

        let isDaylightSavingForDate1 = TimeZoneName.europeHelsinki.timeZone.isDaylightSavingTime(for: date1)
        let isDaylightSavingForDate2 = TimeZoneName.europeHelsinki.timeZone.isDaylightSavingTime(for: date2)
        XCTAssert(isDaylightSavingForDate1 != isDaylightSavingForDate2, "Daylight saving should change between dates")

        XCTAssert(date2 == date3, "Dates should be equal when adding a week in date") // Now dates are different by 1 hour
    }

I guess date2 and date3 should be equal and the date should be 2016-10-31 00:00:00 GMT+2.

jsslai pushed a commit to jsslai/SwiftDate that referenced this issue Oct 24, 2016
@jsslai
Copy link
Author

jsslai commented Oct 24, 2016

See #316

malcommac added a commit that referenced this issue Nov 14, 2016
Fix bug #315: Date().add(components:) doesn't work when daylight savi…
@jsslai jsslai closed this as completed Nov 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant