Preserve civil daypart clocks across DST
This commit is contained in:
@@ -72,10 +72,17 @@ func CivilDay(date time.Time, location *time.Location) Period {
|
||||
|
||||
func ClockWindow(date time.Time, location *time.Location, startClock time.Duration, endClock time.Duration) Period {
|
||||
day := CivilDay(date, location)
|
||||
start := day.Start.Add(startClock)
|
||||
end := day.Start.Add(endClock)
|
||||
start := civilClock(day.Start, location, startClock)
|
||||
end := civilClock(day.Start, location, endClock)
|
||||
if !end.After(start) {
|
||||
end = end.AddDate(0, 0, 1)
|
||||
end = civilClock(day.Start.AddDate(0, 0, 1), location, endClock)
|
||||
}
|
||||
return Period{Start: start, End: end}
|
||||
}
|
||||
|
||||
func civilClock(date time.Time, location *time.Location, clock time.Duration) time.Time {
|
||||
local := date.In(location)
|
||||
hour := int(clock / time.Hour)
|
||||
minute := int(clock%time.Hour) / int(time.Minute)
|
||||
return time.Date(local.Year(), local.Month(), local.Day(), hour, minute, 0, 0, location)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user