chronos-ts 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,289 @@
1
+ /**
2
+ * ChronosTimezone - Timezone handling and conversions
3
+ * @module ChronosTimezone
4
+ */
5
+ import { TimezoneInfo, TimezoneOffset, DSTransition } from '../types';
6
+ /**
7
+ * Common timezone identifiers
8
+ */
9
+ export declare const TIMEZONES: {
10
+ readonly UTC: "UTC";
11
+ readonly GMT: "GMT";
12
+ readonly 'America/New_York': "America/New_York";
13
+ readonly 'America/Chicago': "America/Chicago";
14
+ readonly 'America/Denver': "America/Denver";
15
+ readonly 'America/Los_Angeles': "America/Los_Angeles";
16
+ readonly 'America/Phoenix': "America/Phoenix";
17
+ readonly 'America/Anchorage': "America/Anchorage";
18
+ readonly 'America/Toronto': "America/Toronto";
19
+ readonly 'America/Vancouver': "America/Vancouver";
20
+ readonly 'America/Mexico_City': "America/Mexico_City";
21
+ readonly 'America/Sao_Paulo': "America/Sao_Paulo";
22
+ readonly 'America/Buenos_Aires': "America/Buenos_Aires";
23
+ readonly 'America/Lima': "America/Lima";
24
+ readonly 'America/Bogota': "America/Bogota";
25
+ readonly 'Europe/London': "Europe/London";
26
+ readonly 'Europe/Paris': "Europe/Paris";
27
+ readonly 'Europe/Berlin': "Europe/Berlin";
28
+ readonly 'Europe/Madrid': "Europe/Madrid";
29
+ readonly 'Europe/Rome': "Europe/Rome";
30
+ readonly 'Europe/Amsterdam': "Europe/Amsterdam";
31
+ readonly 'Europe/Brussels': "Europe/Brussels";
32
+ readonly 'Europe/Vienna': "Europe/Vienna";
33
+ readonly 'Europe/Warsaw': "Europe/Warsaw";
34
+ readonly 'Europe/Prague': "Europe/Prague";
35
+ readonly 'Europe/Moscow': "Europe/Moscow";
36
+ readonly 'Europe/Istanbul': "Europe/Istanbul";
37
+ readonly 'Europe/Athens': "Europe/Athens";
38
+ readonly 'Europe/Helsinki': "Europe/Helsinki";
39
+ readonly 'Europe/Stockholm': "Europe/Stockholm";
40
+ readonly 'Europe/Oslo': "Europe/Oslo";
41
+ readonly 'Europe/Copenhagen': "Europe/Copenhagen";
42
+ readonly 'Europe/Dublin': "Europe/Dublin";
43
+ readonly 'Europe/Zurich': "Europe/Zurich";
44
+ readonly 'Asia/Tokyo': "Asia/Tokyo";
45
+ readonly 'Asia/Shanghai': "Asia/Shanghai";
46
+ readonly 'Asia/Hong_Kong': "Asia/Hong_Kong";
47
+ readonly 'Asia/Singapore': "Asia/Singapore";
48
+ readonly 'Asia/Seoul': "Asia/Seoul";
49
+ readonly 'Asia/Taipei': "Asia/Taipei";
50
+ readonly 'Asia/Bangkok': "Asia/Bangkok";
51
+ readonly 'Asia/Jakarta': "Asia/Jakarta";
52
+ readonly 'Asia/Manila': "Asia/Manila";
53
+ readonly 'Asia/Kuala_Lumpur': "Asia/Kuala_Lumpur";
54
+ readonly 'Asia/Ho_Chi_Minh': "Asia/Ho_Chi_Minh";
55
+ readonly 'Asia/Dubai': "Asia/Dubai";
56
+ readonly 'Asia/Kolkata': "Asia/Kolkata";
57
+ readonly 'Asia/Mumbai': "Asia/Mumbai";
58
+ readonly 'Asia/Karachi': "Asia/Karachi";
59
+ readonly 'Asia/Dhaka': "Asia/Dhaka";
60
+ readonly 'Asia/Tehran': "Asia/Tehran";
61
+ readonly 'Asia/Riyadh': "Asia/Riyadh";
62
+ readonly 'Asia/Jerusalem': "Asia/Jerusalem";
63
+ readonly 'Australia/Sydney': "Australia/Sydney";
64
+ readonly 'Australia/Melbourne': "Australia/Melbourne";
65
+ readonly 'Australia/Brisbane': "Australia/Brisbane";
66
+ readonly 'Australia/Perth': "Australia/Perth";
67
+ readonly 'Australia/Adelaide': "Australia/Adelaide";
68
+ readonly 'Pacific/Auckland': "Pacific/Auckland";
69
+ readonly 'Pacific/Fiji': "Pacific/Fiji";
70
+ readonly 'Pacific/Honolulu': "Pacific/Honolulu";
71
+ readonly 'Africa/Cairo': "Africa/Cairo";
72
+ readonly 'Africa/Johannesburg': "Africa/Johannesburg";
73
+ readonly 'Africa/Lagos': "Africa/Lagos";
74
+ readonly 'Africa/Nairobi': "Africa/Nairobi";
75
+ readonly 'Africa/Casablanca': "Africa/Casablanca";
76
+ };
77
+ export type TimezoneId = keyof typeof TIMEZONES | string;
78
+ /**
79
+ * ChronosTimezone - Handles timezone operations and conversions
80
+ *
81
+ * This class provides comprehensive timezone handling including:
82
+ * - Timezone information retrieval
83
+ * - Offset calculations
84
+ * - DST detection
85
+ * - Timezone conversions
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Get timezone info
90
+ * const tz = ChronosTimezone.create('America/New_York');
91
+ * console.log(tz.offset); // -5 or -4 depending on DST
92
+ *
93
+ * // Check DST
94
+ * console.log(tz.isDST(new Date())); // true/false
95
+ *
96
+ * // Convert between timezones
97
+ * const utcDate = new Date();
98
+ * const localDate = ChronosTimezone.convert(utcDate, 'UTC', 'America/New_York');
99
+ * ```
100
+ */
101
+ export declare class ChronosTimezone {
102
+ private _identifier;
103
+ private _originalOffset;
104
+ private _cachedOffset;
105
+ private _cachedDate;
106
+ /**
107
+ * Create a new ChronosTimezone
108
+ */
109
+ constructor(identifier?: TimezoneId);
110
+ /**
111
+ * Normalize timezone identifier
112
+ */
113
+ private _normalizeIdentifier;
114
+ /**
115
+ * Parse offset string to hours
116
+ */
117
+ private _parseOffsetString;
118
+ /**
119
+ * Create a timezone instance
120
+ */
121
+ static create(identifier?: TimezoneId): ChronosTimezone;
122
+ /**
123
+ * Create UTC timezone
124
+ */
125
+ static utc(): ChronosTimezone;
126
+ /**
127
+ * Create timezone from local system timezone
128
+ */
129
+ static local(): ChronosTimezone;
130
+ /**
131
+ * Create timezone from offset in hours
132
+ */
133
+ static fromOffset(offsetHours: number): ChronosTimezone;
134
+ /**
135
+ * Get the local system timezone identifier
136
+ */
137
+ static localIdentifier(): string;
138
+ /**
139
+ * Get timezone identifier
140
+ * Returns the original offset string if created from an offset, otherwise returns the IANA identifier
141
+ */
142
+ get identifier(): string;
143
+ /**
144
+ * Get the internal IANA timezone identifier (used for Intl operations)
145
+ */
146
+ get ianaIdentifier(): string;
147
+ /**
148
+ * Get timezone name (alias for identifier)
149
+ */
150
+ get name(): string;
151
+ /**
152
+ * Get timezone abbreviation for a given date
153
+ */
154
+ getAbbreviation(date?: Date): string;
155
+ /**
156
+ * Get full timezone name for a given date
157
+ */
158
+ getFullName(date?: Date): string;
159
+ /**
160
+ * Get UTC offset in minutes for a given date
161
+ */
162
+ getOffsetMinutes(date?: Date): number;
163
+ /**
164
+ * Parse Intl formatter parts to components
165
+ */
166
+ private _parseIntlParts;
167
+ /**
168
+ * Get UTC offset in hours for a given date
169
+ */
170
+ getOffsetHours(date?: Date): number;
171
+ /**
172
+ * Get UTC offset as string (e.g., "+05:30", "-08:00")
173
+ */
174
+ getOffsetString(date?: Date): string;
175
+ /**
176
+ * Get complete offset information
177
+ */
178
+ getOffset(date?: Date): TimezoneOffset;
179
+ /**
180
+ * Check if DST is in effect for a given date
181
+ */
182
+ isDST(date?: Date): boolean;
183
+ /**
184
+ * Check if timezone observes DST
185
+ */
186
+ observesDST(): boolean;
187
+ /**
188
+ * Get the next DST transition
189
+ */
190
+ getNextDSTTransition(from?: Date): DSTransition | null;
191
+ /**
192
+ * Binary search to find exact DST transition time
193
+ */
194
+ private _findExactTransition;
195
+ /**
196
+ * Convert a date to this timezone (returns formatted string)
197
+ */
198
+ format(date: Date, formatOptions?: Intl.DateTimeFormatOptions): string;
199
+ /**
200
+ * Get date components in this timezone
201
+ */
202
+ getComponents(date: Date): {
203
+ year: number;
204
+ month: number;
205
+ day: number;
206
+ hour: number;
207
+ minute: number;
208
+ second: number;
209
+ dayOfWeek: number;
210
+ };
211
+ /**
212
+ * Convert a date from one timezone to another
213
+ */
214
+ static convert(date: Date, from: TimezoneId, to: TimezoneId): Date;
215
+ /**
216
+ * Convert a UTC date to this timezone
217
+ */
218
+ fromUTC(date: Date): Date;
219
+ /**
220
+ * Convert a date in this timezone to UTC
221
+ */
222
+ toUTC(date: Date): Date;
223
+ /**
224
+ * Get comprehensive timezone information
225
+ */
226
+ getInfo(date?: Date): TimezoneInfo;
227
+ /**
228
+ * Check if two timezones are equivalent at a given moment
229
+ */
230
+ equals(other: ChronosTimezone | string, date?: Date): boolean;
231
+ /**
232
+ * Check if this is the same timezone identifier
233
+ */
234
+ isSame(other: ChronosTimezone | string): boolean;
235
+ /**
236
+ * Get all available timezone identifiers
237
+ * Note: This returns common timezones. Use Intl.supportedValuesOf('timeZone') for all.
238
+ */
239
+ static getAvailableTimezones(): string[];
240
+ /**
241
+ * Check if a timezone identifier is valid
242
+ */
243
+ static isValid(identifier: string): boolean;
244
+ /**
245
+ * Get timezones grouped by region
246
+ */
247
+ static getTimezonesByRegion(): Record<string, string[]>;
248
+ /**
249
+ * Find timezones that match a given offset
250
+ */
251
+ static findByOffset(offsetHours: number, date?: Date): ChronosTimezone[];
252
+ /**
253
+ * Get current time in a specific timezone
254
+ */
255
+ static now(identifier: TimezoneId): Date;
256
+ /**
257
+ * Convert to string
258
+ */
259
+ toString(): string;
260
+ /**
261
+ * Convert to JSON
262
+ */
263
+ toJSON(): object;
264
+ /**
265
+ * Get primitive value
266
+ */
267
+ valueOf(): string;
268
+ }
269
+ /**
270
+ * Pre-created timezone instances for common timezones
271
+ */
272
+ export declare const Timezones: {
273
+ readonly UTC: ChronosTimezone;
274
+ readonly Local: ChronosTimezone;
275
+ readonly Eastern: ChronosTimezone;
276
+ readonly Central: ChronosTimezone;
277
+ readonly Mountain: ChronosTimezone;
278
+ readonly Pacific: ChronosTimezone;
279
+ readonly London: ChronosTimezone;
280
+ readonly Paris: ChronosTimezone;
281
+ readonly Berlin: ChronosTimezone;
282
+ readonly Tokyo: ChronosTimezone;
283
+ readonly Shanghai: ChronosTimezone;
284
+ readonly Singapore: ChronosTimezone;
285
+ readonly Dubai: ChronosTimezone;
286
+ readonly Mumbai: ChronosTimezone;
287
+ readonly Sydney: ChronosTimezone;
288
+ readonly Auckland: ChronosTimezone;
289
+ };