Skip to content

Commit dd17c6e

Browse files
ryehawkrives
authored andcommitted
parseTime: Handle dayOfYear wraparound
Previously, `now`'s `dayOfYear` would be applied to the parsed time, and when `now` and the parsed time were in different years the `dayOfYear` from the parsed `now` would be applied, thereby wrapping the parsed date back around to the beginning of the year. This commit checks if our parsed date is more than six months before `now`, and if so, it adds a year to it. Signed-off-by: Kristofer Rye <[email protected]> Tested-by: Kristofer Rye <[email protected]>
1 parent 39bb75c commit dd17c6e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

source/views/transportation/bus/lib/parse-time.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ export const parseTime = (now: moment) => (
1818
// and set the date to today
1919
m.dayOfYear(now.dayOfYear())
2020

21+
let sixMonthsAgo = moment(now).subtract(6, 'months')
22+
23+
if (m.isBefore(sixMonthsAgo)) {
24+
m.add(1, 'year')
25+
}
26+
2127
return m
2228
}

0 commit comments

Comments
 (0)