fix: safari crashes with long opening hours change times

This commit is contained in:
2023-10-15 17:24:27 +02:00
committed by Rainer Killinger
parent 5db3b7948a
commit c460a3dbc0

View File

@@ -15,7 +15,7 @@
import type {nominatim_object} from 'opening_hours';
import {from, Observable, map, expand, of, delay} from 'rxjs';
import {lazy} from './rxjs/lazy';
import {isAfter, subHours} from 'date-fns';
import {differenceInMilliseconds, isAfter, subHours} from 'date-fns';
export const OPENING_HOURS_REFERENCE = {
address: {
@@ -54,7 +54,13 @@ export function fromOpeningHours(openingHours: string, soonThresholdHours = 1):
const changesSoon = nextChange ? isAfter(now, subHours(nextChange, soonThresholdHours)) : false;
const changeTime = nextChange && !changesSoon ? subHours(nextChange, soonThresholdHours) : nextChange;
return changeTime ? of(it).pipe(delay(changeTime)) : of();
if (!changeTime) return of();
// Safari has issues with this. The value comes out to about 24 days
const maxSafeValue = 0x7f_ff_ff_ff;
const timeDifference = differenceInMilliseconds(changeTime, Date.now());
return of(it).pipe(delay(timeDifference >= maxSafeValue ? maxSafeValue : changeTime));
}),
map(it => {
const now = new Date();