1 | export interface ZoneOffsetOptions {
|
2 | /**
|
3 | * What style of offset to return.
|
4 | */
|
5 | format?: 'short' | 'long' | undefined;
|
6 | /**
|
7 | * What locale to return the offset name in.
|
8 | */
|
9 | locale?: string | undefined;
|
10 | }
|
11 |
|
12 | /**
|
13 | * What style of offset to return.
|
14 | * Returning '+6', '+06:00', or '+0600' respectively
|
15 | */
|
16 | export type ZoneOffsetFormat = 'narrow' | 'short' | 'techie';
|
17 |
|
18 | export abstract class Zone {
|
19 | /**
|
20 | * The type of zone
|
21 | */
|
22 | get type(): string;
|
23 |
|
24 | /**
|
25 | * The name of this zone.
|
26 | */
|
27 | get name(): string;
|
28 |
|
29 | /**
|
30 | * Returns whether the offset is known to be fixed for the whole year.
|
31 | */
|
32 | get isUniversal(): boolean;
|
33 |
|
34 | /**
|
35 | * Returns the offset's common name (such as EST) at the specified timestamp
|
36 | *
|
37 | * @param ts - Epoch milliseconds for which to get the name
|
38 | * @param options - Options to affect the format
|
39 | * @param options.format - What style of offset to return.
|
40 | * @param options.locale - What locale to return the offset name in.
|
41 | */
|
42 | offsetName(ts: number, options: ZoneOffsetOptions): string;
|
43 |
|
44 | /**
|
45 | * Returns the offset's value as a string
|
46 | *
|
47 | * @param ts - Epoch milliseconds for which to get the offset
|
48 | * @param format - What style of offset to return.
|
49 | * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
|
50 | */
|
51 | formatOffset(ts: number, format: ZoneOffsetFormat): string;
|
52 |
|
53 | /**
|
54 | * Return the offset in minutes for this zone at the specified timestamp.
|
55 | *
|
56 | * @param ts - Epoch milliseconds for which to compute the offset
|
57 | */
|
58 | offset(ts: number): number;
|
59 |
|
60 | /**
|
61 | * Return whether this Zone is equal to another zone
|
62 | *
|
63 | * @param other - the zone to compare
|
64 | */
|
65 | equals(other: Zone): boolean;
|
66 |
|
67 | /**
|
68 | * Return whether this Zone is valid.
|
69 | */
|
70 | get isValid(): boolean;
|
71 | }
|
72 |
|
73 | /**
|
74 | * A zone identified by an IANA identifier, like America/New_York
|
75 | */
|
76 | export class IANAZone extends Zone {
|
77 | /**
|
78 | * Same as constructor but has caching.
|
79 | */
|
80 | static create(name: string): IANAZone;
|
81 |
|
82 | /**
|
83 | * Reset local caches. Should only be necessary in testing scenarios.
|
84 | */
|
85 | static resetCache(): void;
|
86 |
|
87 | /**
|
88 | * Returns whether the provided string is a valid specifier.
|
89 | * This only checks the string's format, not that the specifier
|
90 | * identifies a known zone; see {@link isValidZone} for that.
|
91 | *
|
92 | * @param s - The string to check validity on
|
93 | *
|
94 | * @example
|
95 | * IANAZone.isValidSpecifier("America/New_York") //=> true
|
96 | * @example
|
97 | * IANAZone.isValidSpecifier("Fantasia/Castle") //=> true
|
98 | * @example
|
99 | * IANAZone.isValidSpecifier("Sport~~blorp") //=> false
|
100 | */
|
101 | static isValidSpecifier(s: string): boolean;
|
102 |
|
103 | /**
|
104 | * Returns whether the provided string identifies a real zone
|
105 | *
|
106 | * @param zone - The string to check
|
107 | *
|
108 | * @example
|
109 | * IANAZone.isValidZone("America/New_York") //=> true
|
110 | * @example
|
111 | * IANAZone.isValidZone("Fantasia/Castle") //=> false
|
112 | * @example
|
113 | * IANAZone.isValidZone("Sport~~blorp") //=> false
|
114 | */
|
115 | static isValidZone(zone: string): boolean;
|
116 |
|
117 | constructor(name: string);
|
118 | }
|
119 |
|
120 | /**
|
121 | * A zone with a fixed offset (meaning no DST)
|
122 | */
|
123 | export class FixedOffsetZone extends Zone {
|
124 | /**
|
125 | * Get a singleton instance of UTC
|
126 | */
|
127 | static get utcInstance(): FixedOffsetZone;
|
128 |
|
129 | /**
|
130 | * Get an instance with a specified offset
|
131 | *
|
132 | * @param offset - The offset in minutes
|
133 | */
|
134 | static instance(offset: number): FixedOffsetZone;
|
135 |
|
136 | /**
|
137 | * Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6"
|
138 | *
|
139 | * @param s - The offset string to parse
|
140 | *
|
141 | * @example
|
142 | * FixedOffsetZone.parseSpecifier("UTC+6")
|
143 | * @example
|
144 | * FixedOffsetZone.parseSpecifier("UTC+06")
|
145 | * @example
|
146 | * FixedOffsetZone.parseSpecifier("UTC-6:00")
|
147 | */
|
148 | static parseSpecifier(s: string): FixedOffsetZone;
|
149 | }
|
150 |
|
151 | /**
|
152 | * A zone that failed to parse. You should never need to instantiate this.
|
153 | */
|
154 | export class InvalidZone extends Zone {}
|
155 |
|
156 | /**
|
157 | * Represents the system zone for this JavaScript environment.
|
158 | */
|
159 | export class SystemZone extends Zone {
|
160 | /**
|
161 | * Get a singleton instance of the system zone
|
162 | */
|
163 | static get instance(): SystemZone;
|
164 | }
|