Skip to content

Commit

Permalink
Account for DST changes
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
skjiisa committed Mar 19, 2021
1 parent 146bf09 commit 797d54c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Tickmate/Tickmate/Controllers/TickController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class TickController: NSObject, ObservableObject {
let startDateString = track.startDate,
let startDate = DateInRegion(startDateString, region: .current)?.dateTruncated(at: [.hour, .minute, .second]),
let today = trackController?.date.in(region: .current).dateTruncated(at: [.hour, .minute, .second]),
let todayOffset = (today - startDate).toUnit(.day) else { return }
// Subtract 2 hours here to overestimate the offset to account for for any daylight savings time changes.
// Because we're truncating at the number of days, having one or two hours extra won't increase
// the day offset, but having one hour less because of DST would incorrectly offset the day.
let todayOffset = (today - (startDate - 2.hours)).toUnit(.day) else { return }
self.todayOffset = todayOffset

var ticks = [Tick?]()
Expand Down

0 comments on commit 797d54c

Please sign in to comment.