[engine] Sun: nextInvitation checks yesterday, today and tomorrow; addDays steps the calendar; NamedPlace
This commit is contained in:
@@ -61,6 +61,14 @@ export function localDay(epochMs: number, timeZone: string): LocalDay {
|
||||
return day;
|
||||
}
|
||||
|
||||
/** The calendar day `days` after `day` (before, if negative). A calendar step: no zone, no DST. */
|
||||
export function addDays(day: LocalDay, days: number): LocalDay {
|
||||
if (!isLocalDay(day)) throw new RangeError(`addDays: '${day}' is not a LocalDay`);
|
||||
if (!Number.isInteger(days)) throw new RangeError(`addDays: ${days} is not a whole number of days`);
|
||||
const [y, m, d] = day.split('-').map(Number) as [number, number, number];
|
||||
return localDay(Date.UTC(y, m - 1, d + days), 'UTC');
|
||||
}
|
||||
|
||||
/** Whether `value` has the shape of a LocalDay. Does not check that the date exists. */
|
||||
export function isLocalDay(value: string): value is LocalDay {
|
||||
return LOCAL_DAY.test(value);
|
||||
|
||||
Reference in New Issue
Block a user