Skip to content

Commit 990fe65

Browse files
ryehawkrives
authored andcommitted
parseHours: Guard against open times far in the future
Similar to #3376, this commit prevents an open time from showing up more than six months in the future, by subtracting a year from any that are more than 6 months ahead of the provided context moment. Signed-off-by: Kristofer Rye <[email protected]> Tested-by: Kristofer Rye <[email protected]>
1 parent 903db9e commit 990fe65

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

source/views/building-hours/lib/parse-hours.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ export function parseHours(
2323
open.dayOfYear(dayOfYear)
2424

2525
let sixMonthsAgo = moment(m).subtract(6, 'months')
26+
let sixMonthsFromNow = moment(m).add(6, 'months')
2627

2728
if (open.isBefore(sixMonthsAgo)) {
2829
open.add(1, 'year')
30+
} else if (open.isAfter(sixMonthsFromNow)) {
31+
open.subtract(1, 'year')
2932
}
3033

3134
let close = moment.tz(toTime, TIME_FORMAT, true, CENTRAL_TZ)
3235
close.dayOfYear(dayOfYear)
3336

3437
if (close.isBefore(sixMonthsAgo)) {
3538
close.add(1, 'year')
39+
} else if (close.isAfter(sixMonthsFromNow)) {
40+
close.subtract(1, 'year')
3641
}
3742

3843
if (close.isBefore(open)) {

0 commit comments

Comments
 (0)