import {Instant} from './instant.js'; import {PlainDateTime} from './plain-date-time.js'; import {PlainDate} from './plain-date.js'; import {PlainTime} from './plain-time.js'; import type {TimeZone} from './time-zone.js'; import {ZonedDateTime} from './zoned-date-time.js'; let timeZone: string | null; export const Now = { instant() { return new Instant(Date.now()); }, timeZoneId() { if (timeZone) { return timeZone; } let dateTimeFormatter = new Intl.DateTimeFormat(); let {timeZone: timeZoneResolved} = dateTimeFormatter.resolvedOptions(); timeZone = timeZoneResolved; return timeZoneResolved; }, zonedDateTimeISO(timeZoneLike?: string | TimeZone) { return new ZonedDateTime(Date.now(), timeZoneLike ?? Now.timeZoneId()); }, plainDateISO() { let now = new Date(); return new PlainDate(now.getFullYear(), now.getMonth() + 1, now.getDate()); }, plainDateTimeISO() { let now = new Date(); return new PlainDateTime( now.getFullYear(), now.getMonth() + 1, now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds(), ); }, plainTimeISO() { let now = new Date(); return new PlainTime(now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds()); }, }; Object.defineProperty(Now, Symbol.toStringTag, { value: 'Temporal.Now', writable: false, enumerable: false, configurable: true, });