melvitax/DateHelper

Bizarre time math on leap hour day (today)

ccavnor opened this issue · 0 comments

let now: Date = Date()
let then: Date = now.adjust(second: 30)!
print("NOW: (now.toString(dateStyle: .full, timeStyle: .full)!)")
print("THEN: (then.toString(dateStyle: .full, timeStyle: .full)!)")

NOW: Sunday, March 12, 2023 at 11:42:48 AM Pacific Daylight Time
THEN: Sunday, March 12, 2023 at 11:42:30 AM Pacific Daylight Time

then is somehow 18 seconds BEHIND now. I understand neither the incorrect offset nor the negative time, but I strongly suspect that it has to do with today being a leap hour day (Spring forward in time).

if I instead do:
let then: Date = now + 30 // add 30 seconds

then all is as expected:

NOW: Sunday, March 12, 2023 at 11:50:08 AM Pacific Daylight Time
THEN: Sunday, March 12, 2023 at 11:50:38 AM Pacific Daylight Time