From c460a3dbc0a867992c4f6376ace13b45d1f9424a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Sun, 15 Oct 2023 17:24:27 +0200 Subject: [PATCH] fix: safari crashes with long opening hours change times --- frontend/app/src/app/util/opening-hours.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/app/src/app/util/opening-hours.ts b/frontend/app/src/app/util/opening-hours.ts index c67244e3..1cb9235d 100644 --- a/frontend/app/src/app/util/opening-hours.ts +++ b/frontend/app/src/app/util/opening-hours.ts @@ -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();