-
Notifications
You must be signed in to change notification settings - Fork 82
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
Late sunsets give incorrect date for time zone #26
Comments
Fixes problem described in ceeK#26.
Hi Tal! Thanks for the report and including a test, super helpful! Apologies for the delay. I've had a look at your test and as far as I can tell it seems to be working as expected, in that it always returns a UTC date that you have to format 🤔 maybe I am misunderstanding though. I've added a little debug code to the bottom of your test. Can you check my logic: func testLateTimeCorrectReturnDate() {
let lateTime = Date(timeIntervalSince1970: 1499130000) // Tuesday, 4 July 2017 01:00:00 UTC
let city = cities.first(where: { $0.name == "Washington, D. C." })!
let calendar: Calendar = {
var calendar = Calendar.current
calendar.timeZone = TimeZone(identifier: "EST")!
return calendar
}()
guard let solar = Solar(for: lateTime, latitude: city.latitude, longitude: city.longitude) else {
XCTFail("Cannot get solar")
return
}
let sameDate = calendar.compare(lateTime, to: solar.sunset!, toGranularity: .day)
XCTAssertTrue(sameDate == .orderedSame, "The sunset given \(solar.sunset!) is not same day as given date \(lateTime)")
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full
dateFormatter.timeStyle = .full
dateFormatter.timeZone = TimeZone(identifier: "EST")!
let string = dateFormatter.string(from: solar.sunset!)
print("Date: \(string)")
} This outputs After running your pull request test and checking Solar's date, I get: Tell me if I'm missing something! 🙈 |
I'm getting an issue with putting in a date that is after midnight UTC but before midnight local. It returns a solar instance for the following day. I've tried passing in a custom calendar but that doesn't seem to fix the issue. I'll continue working on it but for now here's a test I wrote to recreate this failure case.
The text was updated successfully, but these errors were encountered: