mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
fix(notifications): take today from the instance's TZ and catch up missed trip reminders
The reminder crons run at 09:00 in the instance's TZ but computed today in UTC, so east of Greenwich a trip reminder arrived a day late. A day the job did not run also lost that day's trip reminders for good: the match was 'starts exactly N days from today'. Trips now record the start date a reminder went out for, and the job sends every reminder that is due and not yet sent. The active-trip redirect and the upcoming reservations use the instance's date and clock as well.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import tzlookup from 'tz-lookup';
|
||||
import { readEnv } from '../../app-config';
|
||||
|
||||
/** Local calendar date and clock time for an instant in an IANA timezone. */
|
||||
export function localParts(iso: string | null, timezone: string | null): { date: string | null; time: string | null } {
|
||||
@@ -34,3 +35,14 @@ export function resolveTimeZone(lat: unknown, lng: unknown): string | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Today's date and the clock time where the instance runs, in the TZ the crons
|
||||
* are scheduled in (CronRegistrarService). A UTC "today" disagreed with the
|
||||
* schedule: east of Greenwich a 09:00 job saw the previous date.
|
||||
*/
|
||||
export function appClock(now: Date = new Date()): { date: string; time: string } {
|
||||
const { date, time } = localParts(now.toISOString(), readEnv().app.tz || null);
|
||||
return { date: date ?? now.toISOString().slice(0, 10), time: time ?? now.toISOString().slice(11, 16) };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user