aboutsummaryrefslogtreecommitdiff
path: root/src/temporal-ambient.d.ts
blob: f6080b0c830a930ffc792d0a7235dc7efa054812 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

// Minimal ambient Temporal declarations (native runtime, no polyfill).
// Covers only what this app uses; extend as needed. If a future TS lib
// ships Temporal types, these merge with them.

declare global {
	namespace Temporal {
		type TimeZoneId = string;
		type DurationLike = {
			days?: number;
			hours?: number;
			milliseconds?: number;
		};

		interface Duration {
			total(options: { unit: 'millisecond' | 'day' }): number;
		}
		namespace Duration {
			function from(durationLike: DurationLike): Duration;
		}

		interface Instant {
			readonly epochMilliseconds: number;
			add(durationLike: { hours?: number; milliseconds?: number }): Instant;
			toString(options?: { smallestUnit?: 'millisecond' }): string;
			toZonedDateTimeISO(timeZone: TimeZoneId): ZonedDateTime;
			toLocaleString(
				locales?: string | string[],
				options?: Intl.DateTimeFormatOptions,
			): string;
		}
		namespace Instant {
			function compare(a: string | Instant, b: string | Instant): number;
			function from(iso: string): Instant;
			function fromEpochMilliseconds(ms: number): Instant;
		}

		interface ZonedDateTime {
			add(durationLike: DurationLike): ZonedDateTime;
			startOfDay(): ZonedDateTime;
			toInstant(): Instant;
			toLocaleString(
				locales?: string | string[],
				options?: Intl.DateTimeFormatOptions,
			): string;
		}

		namespace Now {
			function instant(): Instant;
			function timeZoneId(): TimeZoneId;
		}
	}
}

export {};