@f-o-t/datetime 0.1.0 → 0.1.4
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.
- package/dist/core/datetime.d.ts +341 -0
- package/dist/core/datetime.d.ts.map +1 -0
- package/{src/core/factory.ts → dist/core/factory.d.ts} +2 -4
- package/dist/core/factory.d.ts.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index-77f5wgyc.js +41 -0
- package/dist/index-77f5wgyc.js.map +10 -0
- package/dist/index-9jdtsp4s.js +55 -0
- package/dist/index-9jdtsp4s.js.map +10 -0
- package/dist/index-a78jd9k6.js +64 -0
- package/dist/index-a78jd9k6.js.map +10 -0
- package/dist/index-rtm7bpky.js +86 -0
- package/dist/index-rtm7bpky.js.map +10 -0
- package/dist/index-v3cytzbp.js +105 -0
- package/dist/index-v3cytzbp.js.map +11 -0
- package/{src/index.ts → dist/index.d.ts} +2 -15
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +390 -0
- package/dist/index.js.map +13 -0
- package/dist/plugins/business-days/index.d.ts +45 -0
- package/dist/plugins/business-days/index.d.ts.map +1 -0
- package/dist/plugins/business-days/index.js +10 -0
- package/dist/plugins/business-days/index.js.map +9 -0
- package/dist/plugins/format/index.d.ts +54 -0
- package/dist/plugins/format/index.d.ts.map +1 -0
- package/dist/plugins/format/index.js +10 -0
- package/dist/plugins/format/index.js.map +9 -0
- package/dist/plugins/format/tokens.d.ts +20 -0
- package/dist/plugins/format/tokens.d.ts.map +1 -0
- package/{src/plugins/index.ts → dist/plugins/index.d.ts} +1 -2
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/plugin-base.d.ts +49 -0
- package/dist/plugins/plugin-base.d.ts.map +1 -0
- package/dist/plugins/relative-time/index.d.ts +61 -0
- package/dist/plugins/relative-time/index.d.ts.map +1 -0
- package/dist/plugins/relative-time/index.js +10 -0
- package/dist/plugins/relative-time/index.js.map +9 -0
- package/dist/plugins/timezone/index.d.ts +59 -0
- package/dist/plugins/timezone/index.d.ts.map +1 -0
- package/dist/plugins/timezone/index.js +10 -0
- package/dist/plugins/timezone/index.js.map +9 -0
- package/dist/schemas.d.ts +66 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +50 -45
- package/CHANGELOG.md +0 -13
- package/biome.json +0 -39
- package/bunup.config.ts +0 -14
- package/examples/plugins-demo.ts +0 -85
- package/fot.config.ts +0 -5
- package/src/core/datetime.test.ts +0 -1498
- package/src/core/datetime.ts +0 -694
- package/src/core/factory.test.ts +0 -167
- package/src/errors.ts +0 -82
- package/src/plugins/business-days/business-days.test.ts +0 -225
- package/src/plugins/business-days/index.ts +0 -126
- package/src/plugins/format/format.test.ts +0 -173
- package/src/plugins/format/index.ts +0 -78
- package/src/plugins/format/tokens.ts +0 -153
- package/src/plugins/plugin-base.test.ts +0 -211
- package/src/plugins/plugin-base.ts +0 -104
- package/src/plugins/relative-time/index.ts +0 -169
- package/src/plugins/relative-time/relative-time.test.ts +0 -164
- package/src/plugins/timezone/index.ts +0 -152
- package/src/plugins/timezone/timezone.test.ts +0 -135
- package/src/schemas.test.ts +0 -283
- package/src/schemas.ts +0 -104
- package/src/types.ts +0 -122
- package/tsconfig.json +0 -29
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import type { DateInput, DateTimePlugin, TimeUnit } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Core DateTime class that wraps the native JavaScript Date object
|
|
4
|
+
* Provides immutable operations and extensibility through plugins
|
|
5
|
+
*/
|
|
6
|
+
export declare class DateTime {
|
|
7
|
+
/**
|
|
8
|
+
* Internal date storage
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
private readonly _date;
|
|
12
|
+
/**
|
|
13
|
+
* Static registry of installed plugins
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
private static readonly plugins;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new DateTime instance
|
|
19
|
+
* @param input - Date input (Date, ISO string, timestamp, DateTime, or undefined for current time)
|
|
20
|
+
* @throws {InvalidDateError} When input fails Zod validation
|
|
21
|
+
*/
|
|
22
|
+
constructor(input?: DateInput);
|
|
23
|
+
/**
|
|
24
|
+
* Type guard to check if value is a DateTime instance
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private isDateTimeInstance;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the date is valid
|
|
30
|
+
* @returns true if the date is valid, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
isValid(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the native JavaScript Date object (cloned for immutability)
|
|
35
|
+
* @returns A clone of the internal Date object
|
|
36
|
+
*/
|
|
37
|
+
toDate(): Date;
|
|
38
|
+
/**
|
|
39
|
+
* Returns ISO 8601 string representation
|
|
40
|
+
* @returns ISO 8601 formatted string
|
|
41
|
+
*/
|
|
42
|
+
toISO(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the Unix timestamp in milliseconds
|
|
45
|
+
* @returns Unix timestamp
|
|
46
|
+
*/
|
|
47
|
+
valueOf(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Adds milliseconds to the date
|
|
50
|
+
* @param amount - Number of milliseconds to add (can be negative)
|
|
51
|
+
* @returns New DateTime instance with added milliseconds
|
|
52
|
+
*/
|
|
53
|
+
addMilliseconds(amount: number): DateTime;
|
|
54
|
+
/**
|
|
55
|
+
* Adds seconds to the date
|
|
56
|
+
* @param amount - Number of seconds to add (can be negative)
|
|
57
|
+
* @returns New DateTime instance with added seconds
|
|
58
|
+
*/
|
|
59
|
+
addSeconds(amount: number): DateTime;
|
|
60
|
+
/**
|
|
61
|
+
* Adds minutes to the date
|
|
62
|
+
* @param amount - Number of minutes to add (can be negative)
|
|
63
|
+
* @returns New DateTime instance with added minutes
|
|
64
|
+
*/
|
|
65
|
+
addMinutes(amount: number): DateTime;
|
|
66
|
+
/**
|
|
67
|
+
* Adds hours to the date
|
|
68
|
+
* @param amount - Number of hours to add (can be negative)
|
|
69
|
+
* @returns New DateTime instance with added hours
|
|
70
|
+
*/
|
|
71
|
+
addHours(amount: number): DateTime;
|
|
72
|
+
/**
|
|
73
|
+
* Adds days to the date
|
|
74
|
+
* @param amount - Number of days to add (can be negative)
|
|
75
|
+
* @returns New DateTime instance with added days
|
|
76
|
+
*/
|
|
77
|
+
addDays(amount: number): DateTime;
|
|
78
|
+
/**
|
|
79
|
+
* Adds weeks to the date
|
|
80
|
+
* @param amount - Number of weeks to add (can be negative)
|
|
81
|
+
* @returns New DateTime instance with added weeks
|
|
82
|
+
*/
|
|
83
|
+
addWeeks(amount: number): DateTime;
|
|
84
|
+
/**
|
|
85
|
+
* Adds months to the date
|
|
86
|
+
* @param amount - Number of months to add (can be negative)
|
|
87
|
+
* @returns New DateTime instance with added months
|
|
88
|
+
*/
|
|
89
|
+
addMonths(amount: number): DateTime;
|
|
90
|
+
/**
|
|
91
|
+
* Adds years to the date
|
|
92
|
+
* @param amount - Number of years to add (can be negative)
|
|
93
|
+
* @returns New DateTime instance with added years
|
|
94
|
+
*/
|
|
95
|
+
addYears(amount: number): DateTime;
|
|
96
|
+
/**
|
|
97
|
+
* Subtracts milliseconds from the date
|
|
98
|
+
* @param amount - Number of milliseconds to subtract (can be negative)
|
|
99
|
+
* @returns New DateTime instance with subtracted milliseconds
|
|
100
|
+
*/
|
|
101
|
+
subtractMilliseconds(amount: number): DateTime;
|
|
102
|
+
/**
|
|
103
|
+
* Subtracts seconds from the date
|
|
104
|
+
* @param amount - Number of seconds to subtract (can be negative)
|
|
105
|
+
* @returns New DateTime instance with subtracted seconds
|
|
106
|
+
*/
|
|
107
|
+
subtractSeconds(amount: number): DateTime;
|
|
108
|
+
/**
|
|
109
|
+
* Subtracts minutes from the date
|
|
110
|
+
* @param amount - Number of minutes to subtract (can be negative)
|
|
111
|
+
* @returns New DateTime instance with subtracted minutes
|
|
112
|
+
*/
|
|
113
|
+
subtractMinutes(amount: number): DateTime;
|
|
114
|
+
/**
|
|
115
|
+
* Subtracts hours from the date
|
|
116
|
+
* @param amount - Number of hours to subtract (can be negative)
|
|
117
|
+
* @returns New DateTime instance with subtracted hours
|
|
118
|
+
*/
|
|
119
|
+
subtractHours(amount: number): DateTime;
|
|
120
|
+
/**
|
|
121
|
+
* Subtracts days from the date
|
|
122
|
+
* @param amount - Number of days to subtract (can be negative)
|
|
123
|
+
* @returns New DateTime instance with subtracted days
|
|
124
|
+
*/
|
|
125
|
+
subtractDays(amount: number): DateTime;
|
|
126
|
+
/**
|
|
127
|
+
* Subtracts weeks from the date
|
|
128
|
+
* @param amount - Number of weeks to subtract (can be negative)
|
|
129
|
+
* @returns New DateTime instance with subtracted weeks
|
|
130
|
+
*/
|
|
131
|
+
subtractWeeks(amount: number): DateTime;
|
|
132
|
+
/**
|
|
133
|
+
* Subtracts months from the date
|
|
134
|
+
* @param amount - Number of months to subtract (can be negative)
|
|
135
|
+
* @returns New DateTime instance with subtracted months
|
|
136
|
+
*/
|
|
137
|
+
subtractMonths(amount: number): DateTime;
|
|
138
|
+
/**
|
|
139
|
+
* Subtracts years from the date
|
|
140
|
+
* @param amount - Number of years to subtract (can be negative)
|
|
141
|
+
* @returns New DateTime instance with subtracted years
|
|
142
|
+
*/
|
|
143
|
+
subtractYears(amount: number): DateTime;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if this date is before another date
|
|
146
|
+
* @param other - DateTime instance to compare against
|
|
147
|
+
* @returns true if this date is before the other date, false otherwise
|
|
148
|
+
*/
|
|
149
|
+
isBefore(other: DateTime): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Checks if this date is after another date
|
|
152
|
+
* @param other - DateTime instance to compare against
|
|
153
|
+
* @returns true if this date is after the other date, false otherwise
|
|
154
|
+
*/
|
|
155
|
+
isAfter(other: DateTime): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Checks if this date is the same as another date
|
|
158
|
+
* @param other - DateTime instance to compare against
|
|
159
|
+
* @returns true if this date is the same as the other date, false otherwise
|
|
160
|
+
*/
|
|
161
|
+
isSame(other: DateTime): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if this date is the same as or before another date
|
|
164
|
+
* @param other - DateTime instance to compare against
|
|
165
|
+
* @returns true if this date is the same as or before the other date, false otherwise
|
|
166
|
+
*/
|
|
167
|
+
isSameOrBefore(other: DateTime): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if this date is the same as or after another date
|
|
170
|
+
* @param other - DateTime instance to compare against
|
|
171
|
+
* @returns true if this date is the same as or after the other date, false otherwise
|
|
172
|
+
*/
|
|
173
|
+
isSameOrAfter(other: DateTime): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Checks if this date is between two dates
|
|
176
|
+
* @param start - Start date of the range
|
|
177
|
+
* @param end - End date of the range
|
|
178
|
+
* @param inclusive - Whether to include the start and end dates in the comparison (default: false)
|
|
179
|
+
* @returns true if this date is between start and end, false otherwise
|
|
180
|
+
*/
|
|
181
|
+
isBetween(start: DateTime, end: DateTime, inclusive?: boolean): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Gets the UTC year
|
|
184
|
+
* @returns The year (e.g., 2024)
|
|
185
|
+
*/
|
|
186
|
+
year(): number;
|
|
187
|
+
/**
|
|
188
|
+
* Gets the UTC month (0-indexed)
|
|
189
|
+
* @returns The month (0-11, where 0=January)
|
|
190
|
+
*/
|
|
191
|
+
month(): number;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the UTC day of the month
|
|
194
|
+
* @returns The day of month (1-31)
|
|
195
|
+
*/
|
|
196
|
+
date(): number;
|
|
197
|
+
/**
|
|
198
|
+
* Gets the UTC day of the week (0-indexed)
|
|
199
|
+
* @returns The day of week (0-6, where 0=Sunday)
|
|
200
|
+
*/
|
|
201
|
+
day(): number;
|
|
202
|
+
/**
|
|
203
|
+
* Gets the UTC hour
|
|
204
|
+
* @returns The hour (0-23)
|
|
205
|
+
*/
|
|
206
|
+
hour(): number;
|
|
207
|
+
/**
|
|
208
|
+
* Gets the UTC minute
|
|
209
|
+
* @returns The minute (0-59)
|
|
210
|
+
*/
|
|
211
|
+
minute(): number;
|
|
212
|
+
/**
|
|
213
|
+
* Gets the UTC second
|
|
214
|
+
* @returns The second (0-59)
|
|
215
|
+
*/
|
|
216
|
+
second(): number;
|
|
217
|
+
/**
|
|
218
|
+
* Gets the UTC millisecond
|
|
219
|
+
* @returns The millisecond (0-999)
|
|
220
|
+
*/
|
|
221
|
+
millisecond(): number;
|
|
222
|
+
/**
|
|
223
|
+
* Sets the UTC year
|
|
224
|
+
* @param year - The year to set
|
|
225
|
+
* @returns New DateTime instance with updated year
|
|
226
|
+
*/
|
|
227
|
+
setYear(year: number): DateTime;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the UTC month (0-indexed)
|
|
230
|
+
* @param month - The month to set (0-11, where 0=January)
|
|
231
|
+
* @returns New DateTime instance with updated month
|
|
232
|
+
*/
|
|
233
|
+
setMonth(month: number): DateTime;
|
|
234
|
+
/**
|
|
235
|
+
* Sets the UTC day of the month
|
|
236
|
+
* @param date - The day to set (1-31)
|
|
237
|
+
* @returns New DateTime instance with updated date
|
|
238
|
+
*/
|
|
239
|
+
setDate(date: number): DateTime;
|
|
240
|
+
/**
|
|
241
|
+
* Sets the UTC hour
|
|
242
|
+
* @param hour - The hour to set (0-23)
|
|
243
|
+
* @returns New DateTime instance with updated hour
|
|
244
|
+
*/
|
|
245
|
+
setHour(hour: number): DateTime;
|
|
246
|
+
/**
|
|
247
|
+
* Sets the UTC minute
|
|
248
|
+
* @param minute - The minute to set (0-59)
|
|
249
|
+
* @returns New DateTime instance with updated minute
|
|
250
|
+
*/
|
|
251
|
+
setMinute(minute: number): DateTime;
|
|
252
|
+
/**
|
|
253
|
+
* Sets the UTC second
|
|
254
|
+
* @param second - The second to set (0-59)
|
|
255
|
+
* @returns New DateTime instance with updated second
|
|
256
|
+
*/
|
|
257
|
+
setSecond(second: number): DateTime;
|
|
258
|
+
/**
|
|
259
|
+
* Sets the UTC millisecond
|
|
260
|
+
* @param millisecond - The millisecond to set (0-999)
|
|
261
|
+
* @returns New DateTime instance with updated millisecond
|
|
262
|
+
*/
|
|
263
|
+
setMillisecond(millisecond: number): DateTime;
|
|
264
|
+
/**
|
|
265
|
+
* Returns a new DateTime at the start of the day (00:00:00.000)
|
|
266
|
+
* @returns New DateTime instance at start of day
|
|
267
|
+
*/
|
|
268
|
+
startOfDay(): DateTime;
|
|
269
|
+
/**
|
|
270
|
+
* Returns a new DateTime at the end of the day (23:59:59.999)
|
|
271
|
+
* @returns New DateTime instance at end of day
|
|
272
|
+
*/
|
|
273
|
+
endOfDay(): DateTime;
|
|
274
|
+
/**
|
|
275
|
+
* Returns a new DateTime at the start of the hour (XX:00:00.000)
|
|
276
|
+
* @returns New DateTime instance at start of hour
|
|
277
|
+
*/
|
|
278
|
+
startOfHour(): DateTime;
|
|
279
|
+
/**
|
|
280
|
+
* Returns a new DateTime at the end of the hour (XX:59:59.999)
|
|
281
|
+
* @returns New DateTime instance at end of hour
|
|
282
|
+
*/
|
|
283
|
+
endOfHour(): DateTime;
|
|
284
|
+
/**
|
|
285
|
+
* Returns a new DateTime at the start of the week (Sunday 00:00:00.000)
|
|
286
|
+
* @returns New DateTime instance at start of week
|
|
287
|
+
*/
|
|
288
|
+
startOfWeek(): DateTime;
|
|
289
|
+
/**
|
|
290
|
+
* Returns a new DateTime at the end of the week (Saturday 23:59:59.999)
|
|
291
|
+
* @returns New DateTime instance at end of week
|
|
292
|
+
*/
|
|
293
|
+
endOfWeek(): DateTime;
|
|
294
|
+
/**
|
|
295
|
+
* Returns a new DateTime at the start of the month (day 1, 00:00:00.000)
|
|
296
|
+
* @returns New DateTime instance at start of month
|
|
297
|
+
*/
|
|
298
|
+
startOfMonth(): DateTime;
|
|
299
|
+
/**
|
|
300
|
+
* Returns a new DateTime at the end of the month (last day, 23:59:59.999)
|
|
301
|
+
* @returns New DateTime instance at end of month
|
|
302
|
+
*/
|
|
303
|
+
endOfMonth(): DateTime;
|
|
304
|
+
/**
|
|
305
|
+
* Returns a new DateTime at the start of the year (Jan 1, 00:00:00.000)
|
|
306
|
+
* @returns New DateTime instance at start of year
|
|
307
|
+
*/
|
|
308
|
+
startOfYear(): DateTime;
|
|
309
|
+
/**
|
|
310
|
+
* Returns a new DateTime at the end of the year (Dec 31, 23:59:59.999)
|
|
311
|
+
* @returns New DateTime instance at end of year
|
|
312
|
+
*/
|
|
313
|
+
endOfYear(): DateTime;
|
|
314
|
+
/**
|
|
315
|
+
* Calculates the difference between this date and another date
|
|
316
|
+
* @param other - DateTime instance to compare against
|
|
317
|
+
* @param unit - Unit of measurement (default: 'millisecond')
|
|
318
|
+
* @returns The difference (can be negative)
|
|
319
|
+
*/
|
|
320
|
+
diff(other: DateTime, unit?: TimeUnit): number;
|
|
321
|
+
/**
|
|
322
|
+
* Registers a plugin to extend DateTime functionality
|
|
323
|
+
* @param plugin - The plugin to register
|
|
324
|
+
* @param options - Optional plugin configuration
|
|
325
|
+
* @throws {PluginError} When plugin with same name already exists
|
|
326
|
+
*/
|
|
327
|
+
static extend(plugin: DateTimePlugin, options?: Record<string, unknown>): void;
|
|
328
|
+
/**
|
|
329
|
+
* Checks if a plugin is registered
|
|
330
|
+
* @param name - Plugin name
|
|
331
|
+
* @returns true if plugin is registered, false otherwise
|
|
332
|
+
*/
|
|
333
|
+
static hasPlugin(name: string): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Gets a registered plugin
|
|
336
|
+
* @param name - Plugin name
|
|
337
|
+
* @returns The plugin if found, undefined otherwise
|
|
338
|
+
*/
|
|
339
|
+
static getPlugin(name: string): DateTimePlugin | undefined;
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=datetime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../../src/core/datetime.ts"],"names":[],"mappings":"AA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;IAMtC;;;;OAIG;IACI,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IAMtC;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ;IAM1C;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ;IAM1C;;;;OAIG;IACI,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ;IAUpD;;;OAGG;IACI,UAAU,IAAI,QAAQ;IAM7B;;;OAGG;IACI,QAAQ,IAAI,QAAQ;IAM3B;;;OAGG;IACI,WAAW,IAAI,QAAQ;IAM9B;;;OAGG;IACI,SAAS,IAAI,QAAQ;IAM5B;;;OAGG;IACI,WAAW,IAAI,QAAQ;IAQ9B;;;OAGG;IACI,SAAS,IAAI,QAAQ;IAQ5B;;;OAGG;IACI,YAAY,IAAI,QAAQ;IAO/B;;;OAGG;IACI,UAAU,IAAI,QAAQ;IAQ7B;;;OAGG;IACI,WAAW,IAAI,QAAQ;IAO9B;;;OAGG;IACI,SAAS,IAAI,QAAQ;IAW5B;;;;;OAKG;IACI,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAE,QAAwB,GAAG,MAAM;IAmCpE;;;;;OAKG;WACW,MAAM,CACjB,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,IAAI;IAgBP;;;;OAIG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9C;;;;OAIG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;CAGnE"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { DateInput } from "../types.ts";
|
|
2
2
|
import { DateTime } from "./datetime.ts";
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Factory function to create a DateTime instance
|
|
6
5
|
* Provides a convenient alternative to using the constructor
|
|
@@ -27,6 +26,5 @@ import { DateTime } from "./datetime.ts";
|
|
|
27
26
|
* const dt4 = datetime(dt1);
|
|
28
27
|
* ```
|
|
29
28
|
*/
|
|
30
|
-
export function datetime(input?: DateInput): DateTime
|
|
31
|
-
|
|
32
|
-
}
|
|
29
|
+
export declare function datetime(input?: DateInput): DateTime;
|
|
30
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/core/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,CAEpD"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all DateTime-related errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class DateTimeError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when an invalid date is provided
|
|
9
|
+
*/
|
|
10
|
+
export declare class InvalidDateError extends DateTimeError {
|
|
11
|
+
readonly input?: unknown | undefined;
|
|
12
|
+
constructor(message?: string, input?: unknown | undefined);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when a date string doesn't match the expected format
|
|
16
|
+
*/
|
|
17
|
+
export declare class InvalidFormatError extends DateTimeError {
|
|
18
|
+
readonly input?: string | undefined;
|
|
19
|
+
readonly expectedFormat?: string | undefined;
|
|
20
|
+
constructor(message: string, input?: string | undefined, expectedFormat?: string | undefined);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when an invalid timezone is specified
|
|
24
|
+
*/
|
|
25
|
+
export declare class InvalidTimezoneError extends DateTimeError {
|
|
26
|
+
readonly timezone?: string | undefined;
|
|
27
|
+
constructor(message: string, timezone?: string | undefined);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown when a plugin operation fails
|
|
31
|
+
*/
|
|
32
|
+
export declare class PluginError extends DateTimeError {
|
|
33
|
+
readonly pluginName?: string | undefined;
|
|
34
|
+
constructor(message: string, pluginName?: string | undefined);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when attempting to use functionality that requires a plugin that isn't installed
|
|
38
|
+
*/
|
|
39
|
+
export declare class MissingPluginError extends PluginError {
|
|
40
|
+
readonly requiredPlugin: string;
|
|
41
|
+
constructor(requiredPlugin: string, message?: string);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAQ7B;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;aAG7B,KAAK,CAAC,EAAE,OAAO;gBAD/B,OAAO,SAAiB,EACR,KAAK,CAAC,EAAE,OAAO,YAAA;CAKpC;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;aAG/B,KAAK,CAAC,EAAE,MAAM;aACd,cAAc,CAAC,EAAE,MAAM;gBAFvC,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,MAAM,YAAA,EACd,cAAc,CAAC,EAAE,MAAM,YAAA;CAK5C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;aAGjC,QAAQ,CAAC,EAAE,MAAM;gBADjC,OAAO,EAAE,MAAM,EACC,QAAQ,CAAC,EAAE,MAAM,YAAA;CAKtC;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,aAAa;aAGxB,UAAU,CAAC,EAAE,MAAM;gBADnC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA;CAKxC;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;aAE7B,cAAc,EAAE,MAAM;gBAAtB,cAAc,EAAE,MAAM,EACtC,OAAO,CAAC,EAAE,MAAM;CAQrB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/plugins/plugin-base.ts
|
|
3
|
+
function createPlugin(name, install) {
|
|
4
|
+
if (!name || typeof name !== "string") {
|
|
5
|
+
throw new Error("Plugin name must be a non-empty string");
|
|
6
|
+
}
|
|
7
|
+
if (typeof install !== "function") {
|
|
8
|
+
throw new Error("Plugin install must be a function");
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
name,
|
|
12
|
+
install
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function isPlugin(obj) {
|
|
16
|
+
if (!obj || typeof obj !== "object") {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const plugin = obj;
|
|
20
|
+
return typeof plugin.name === "string" && plugin.name.length > 0 && typeof plugin.install === "function";
|
|
21
|
+
}
|
|
22
|
+
function isValidPluginName(name) {
|
|
23
|
+
if (!name || typeof name !== "string") {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const validNamePattern = /^[a-zA-Z0-9-_]+$/;
|
|
27
|
+
if (!validNamePattern.test(name)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (name.length < 2) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (/^[-_]|[-_]$/.test(name)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { createPlugin, isPlugin, isValidPluginName };
|
|
40
|
+
|
|
41
|
+
//# debugId=B3B751489D65C8A464756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/plugins/plugin-base.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { DateTimeClass, DateTimePlugin } from \"../types.ts\";\n\n/**\n * Helper function to create a DateTime plugin\n *\n * @param name - Unique plugin name\n * @param install - Installation function that extends the DateTime class\n * @returns A DateTimePlugin object\n *\n * @example\n * ```ts\n * const myPlugin = createPlugin(\"myPlugin\", (DateTimeClass, options) => {\n * // Extend DateTime prototype\n * DateTimeClass.prototype.myMethod = function() {\n * return this.valueOf();\n * };\n *\n * // Add static methods\n * DateTimeClass.myStaticMethod = function() {\n * return new DateTimeClass();\n * };\n * });\n *\n * // Register the plugin\n * DateTime.extend(myPlugin);\n * ```\n */\nexport function createPlugin(\n name: string,\n install: (\n DateTimeClass: DateTimeClass,\n options?: Record<string, unknown>,\n ) => void,\n): DateTimePlugin {\n if (!name || typeof name !== \"string\") {\n throw new Error(\"Plugin name must be a non-empty string\");\n }\n\n if (typeof install !== \"function\") {\n throw new Error(\"Plugin install must be a function\");\n }\n\n return {\n name,\n install,\n };\n}\n\n/**\n * Type guard to check if an object is a valid DateTimePlugin\n *\n * @param obj - Object to check\n * @returns true if object is a valid DateTimePlugin\n */\nexport function isPlugin(obj: unknown): obj is DateTimePlugin {\n if (!obj || typeof obj !== \"object\") {\n return false;\n }\n\n const plugin = obj as Partial<DateTimePlugin>;\n\n return (\n typeof plugin.name === \"string\" &&\n plugin.name.length > 0 &&\n typeof plugin.install === \"function\"\n );\n}\n\n/**\n * Validates that a plugin name follows naming conventions\n *\n * @param name - Plugin name to validate\n * @returns true if name is valid, false otherwise\n *\n * @remarks\n * Valid plugin names:\n * - Must be a non-empty string\n * - Should use kebab-case or camelCase\n * - Should not contain spaces or special characters (except hyphens)\n * - Should be descriptive and unique\n */\nexport function isValidPluginName(name: string): boolean {\n if (!name || typeof name !== \"string\") {\n return false;\n }\n\n // Check for valid characters (alphanumeric, hyphens, underscores)\n const validNamePattern = /^[a-zA-Z0-9-_]+$/;\n if (!validNamePattern.test(name)) {\n return false;\n }\n\n // Check minimum length\n if (name.length < 2) {\n return false;\n }\n\n // Should not start or end with special characters\n if (/^[-_]|[-_]$/.test(name)) {\n return false;\n }\n\n return true;\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AA2BO,SAAS,YAAY,CACzB,MACA,SAIe;AAAA,EACf,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;AAAA,IACpC,MAAM,IAAI,MAAM,wCAAwC;AAAA,EAC3D;AAAA,EAEA,IAAI,OAAO,YAAY,YAAY;AAAA,IAChC,MAAM,IAAI,MAAM,mCAAmC;AAAA,EACtD;AAAA,EAEA,OAAO;AAAA,IACJ;AAAA,IACA;AAAA,EACH;AAAA;AASI,SAAS,QAAQ,CAAC,KAAqC;AAAA,EAC3D,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU;AAAA,IAClC,OAAO;AAAA,EACV;AAAA,EAEA,MAAM,SAAS;AAAA,EAEf,OACG,OAAO,OAAO,SAAS,YACvB,OAAO,KAAK,SAAS,KACrB,OAAO,OAAO,YAAY;AAAA;AAiBzB,SAAS,iBAAiB,CAAC,MAAuB;AAAA,EACtD,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;AAAA,IACpC,OAAO;AAAA,EACV;AAAA,EAGA,MAAM,mBAAmB;AAAA,EACzB,IAAI,CAAC,iBAAiB,KAAK,IAAI,GAAG;AAAA,IAC/B,OAAO;AAAA,EACV;AAAA,EAGA,IAAI,KAAK,SAAS,GAAG;AAAA,IAClB,OAAO;AAAA,EACV;AAAA,EAGA,IAAI,cAAc,KAAK,IAAI,GAAG;AAAA,IAC3B,OAAO;AAAA,EACV;AAAA,EAEA,OAAO;AAAA;",
|
|
8
|
+
"debugId": "B3B751489D65C8A464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
createPlugin
|
|
4
|
+
} from "./index-77f5wgyc.js";
|
|
5
|
+
|
|
6
|
+
// src/plugins/business-days/index.ts
|
|
7
|
+
function isWeekdayDay(dayOfWeek) {
|
|
8
|
+
return dayOfWeek >= 1 && dayOfWeek <= 5;
|
|
9
|
+
}
|
|
10
|
+
var businessDaysPlugin = createPlugin("business-days", (DateTimeClass) => {
|
|
11
|
+
DateTimeClass.prototype.isWeekday = function() {
|
|
12
|
+
const dayOfWeek = this.day();
|
|
13
|
+
return isWeekdayDay(dayOfWeek);
|
|
14
|
+
};
|
|
15
|
+
DateTimeClass.prototype.isWeekend = function() {
|
|
16
|
+
const dayOfWeek = this.day();
|
|
17
|
+
return dayOfWeek === 0 || dayOfWeek === 6;
|
|
18
|
+
};
|
|
19
|
+
DateTimeClass.prototype.addBusinessDays = function(n) {
|
|
20
|
+
if (n === 0) {
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
let current = new DateTimeClass(this.valueOf());
|
|
24
|
+
let daysToAdd = Math.abs(n);
|
|
25
|
+
const direction = n > 0 ? 1 : -1;
|
|
26
|
+
while (daysToAdd > 0) {
|
|
27
|
+
current = current.addDays(direction);
|
|
28
|
+
if (current.isWeekday()) {
|
|
29
|
+
daysToAdd--;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return current;
|
|
33
|
+
};
|
|
34
|
+
DateTimeClass.prototype.subtractBusinessDays = function(n) {
|
|
35
|
+
return this.addBusinessDays(-n);
|
|
36
|
+
};
|
|
37
|
+
DateTimeClass.prototype.diffBusinessDays = function(other) {
|
|
38
|
+
const start = this.valueOf() < other.valueOf() ? this : other;
|
|
39
|
+
const end = this.valueOf() < other.valueOf() ? other : this;
|
|
40
|
+
const isReversed = this.valueOf() > other.valueOf();
|
|
41
|
+
let businessDays = 0;
|
|
42
|
+
let current = new DateTimeClass(start.valueOf());
|
|
43
|
+
while (current.startOfDay().valueOf() < end.startOfDay().valueOf()) {
|
|
44
|
+
if (current.isWeekday()) {
|
|
45
|
+
businessDays++;
|
|
46
|
+
}
|
|
47
|
+
current = current.addDays(1);
|
|
48
|
+
}
|
|
49
|
+
return isReversed ? -businessDays : businessDays;
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export { businessDaysPlugin };
|
|
54
|
+
|
|
55
|
+
//# debugId=E77EEE3251E2711B64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/plugins/business-days/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { DateTime } from \"../../core/datetime\";\nimport type { DateTimeClass } from \"../../types\";\nimport { createPlugin } from \"../plugin-base\";\n\n/**\n * Checks if a given day of week is a weekday (Monday-Friday)\n * @param dayOfWeek - Day of week (0=Sunday, 6=Saturday)\n * @returns true if weekday, false otherwise\n */\nfunction isWeekdayDay(dayOfWeek: number): boolean {\n return dayOfWeek >= 1 && dayOfWeek <= 5;\n}\n\n/**\n * Extended DateTime interface with business days methods\n */\ndeclare module \"../../core/datetime\" {\n interface DateTime {\n /**\n * Checks if this date is a weekday (Monday-Friday)\n * @returns true if weekday, false otherwise\n */\n isWeekday(): boolean;\n\n /**\n * Checks if this date is a weekend (Saturday-Sunday)\n * @returns true if weekend, false otherwise\n */\n isWeekend(): boolean;\n\n /**\n * Adds business days to this date\n * Skips weekends (Saturday and Sunday)\n * @param n - Number of business days to add\n * @returns New DateTime instance with business days added\n */\n addBusinessDays(n: number): DateTime;\n\n /**\n * Subtracts business days from this date\n * Skips weekends (Saturday and Sunday)\n * @param n - Number of business days to subtract\n * @returns New DateTime instance with business days subtracted\n */\n subtractBusinessDays(n: number): DateTime;\n\n /**\n * Calculates the number of business days between this date and another\n * Excludes weekends from the calculation\n * @param other - DateTime instance to compare against\n * @returns Number of business days (positive if other is after, negative if before)\n */\n diffBusinessDays(other: DateTime): number;\n }\n}\n\n/**\n * Business Days plugin for DateTime\n * Adds methods for working with business days (weekdays only)\n * Week is defined as Monday-Friday (weekdays), Saturday-Sunday (weekend)\n */\nexport const businessDaysPlugin = createPlugin(\n \"business-days\",\n (DateTimeClass: DateTimeClass) => {\n // Add instance methods\n DateTimeClass.prototype.isWeekday = function (): boolean {\n const dayOfWeek = this.day(); // 0=Sunday, 6=Saturday\n return isWeekdayDay(dayOfWeek);\n };\n\n DateTimeClass.prototype.isWeekend = function (): boolean {\n const dayOfWeek = this.day();\n return dayOfWeek === 0 || dayOfWeek === 6;\n };\n\n DateTimeClass.prototype.addBusinessDays = function (n: number): DateTime {\n if (n === 0) {\n return this;\n }\n\n let current = new DateTimeClass(this.valueOf());\n let daysToAdd = Math.abs(n);\n const direction = n > 0 ? 1 : -1;\n\n while (daysToAdd > 0) {\n // Move one day in the specified direction\n current = current.addDays(direction);\n\n // Only count weekdays\n if ((current as any).isWeekday()) {\n daysToAdd--;\n }\n }\n\n return current;\n };\n\n DateTimeClass.prototype.subtractBusinessDays = function (\n n: number,\n ): DateTime {\n return (this as any).addBusinessDays(-n);\n };\n\n DateTimeClass.prototype.diffBusinessDays = function (\n other: DateTime,\n ): number {\n // Get start and end dates (normalized to start of day for consistency)\n const start = this.valueOf() < other.valueOf() ? this : other;\n const end = this.valueOf() < other.valueOf() ? other : this;\n const isReversed = this.valueOf() > other.valueOf();\n\n let businessDays = 0;\n let current = new DateTimeClass(start.valueOf());\n\n // Iterate through each day and count weekdays\n while (current.startOfDay().valueOf() < end.startOfDay().valueOf()) {\n if ((current as any).isWeekday()) {\n businessDays++;\n }\n current = current.addDays(1);\n }\n\n return isReversed ? -businessDays : businessDays;\n };\n },\n);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;AASA,SAAS,YAAY,CAAC,WAA4B;AAAA,EAC/C,OAAO,aAAa,KAAK,aAAa;AAAA;AAmDlC,IAAM,qBAAqB,aAC/B,iBACA,CAAC,kBAAiC;AAAA,EAE/B,c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,QAAQ,QAAQ,CAAC;AAAA,IAC9B;AAAA,IAEA,OAAO,aAAa,CAAC,eAAe;AAAA;AAAA,CAG7C;",
|
|
8
|
+
"debugId": "E77EEE3251E2711B64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
createPlugin
|
|
4
|
+
} from "./index-77f5wgyc.js";
|
|
5
|
+
|
|
6
|
+
// src/plugins/timezone/index.ts
|
|
7
|
+
function isValidTimezone(timezone) {
|
|
8
|
+
if (!timezone || typeof timezone !== "string") {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone });
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function getLocalTimezone() {
|
|
19
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
20
|
+
}
|
|
21
|
+
var timezonePlugin = createPlugin("timezone", (DateTimeClass) => {
|
|
22
|
+
DateTimeClass.prototype.tz = function(timezone) {
|
|
23
|
+
if (!isValidTimezone(timezone)) {
|
|
24
|
+
throw new Error(`Invalid timezone: ${timezone}`);
|
|
25
|
+
}
|
|
26
|
+
const newInstance = new DateTimeClass(this.valueOf());
|
|
27
|
+
newInstance._timezone = timezone;
|
|
28
|
+
return newInstance;
|
|
29
|
+
};
|
|
30
|
+
DateTimeClass.prototype.toTimezone = function(timezone) {
|
|
31
|
+
if (!isValidTimezone(timezone)) {
|
|
32
|
+
throw new Error(`Invalid timezone: ${timezone}`);
|
|
33
|
+
}
|
|
34
|
+
const newInstance = new DateTimeClass(this.valueOf());
|
|
35
|
+
newInstance._timezone = timezone;
|
|
36
|
+
return newInstance;
|
|
37
|
+
};
|
|
38
|
+
DateTimeClass.prototype.utc = function() {
|
|
39
|
+
const newInstance = new DateTimeClass(this.valueOf());
|
|
40
|
+
newInstance._timezone = "UTC";
|
|
41
|
+
return newInstance;
|
|
42
|
+
};
|
|
43
|
+
DateTimeClass.prototype.local = function() {
|
|
44
|
+
const localTz = getLocalTimezone();
|
|
45
|
+
const newInstance = new DateTimeClass(this.valueOf());
|
|
46
|
+
newInstance._timezone = localTz;
|
|
47
|
+
return newInstance;
|
|
48
|
+
};
|
|
49
|
+
DateTimeClass.prototype.getTimezone = function() {
|
|
50
|
+
return this._timezone || "UTC";
|
|
51
|
+
};
|
|
52
|
+
DateTimeClass.tz = (input, timezone) => {
|
|
53
|
+
if (!isValidTimezone(timezone)) {
|
|
54
|
+
throw new Error(`Invalid timezone: ${timezone}`);
|
|
55
|
+
}
|
|
56
|
+
const instance = new DateTimeClass(input);
|
|
57
|
+
instance._timezone = timezone;
|
|
58
|
+
return instance;
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export { timezonePlugin };
|
|
63
|
+
|
|
64
|
+
//# debugId=ED6E64E60878500964756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/plugins/timezone/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { DateTime } from \"../../core/datetime\";\nimport type { DateTimeClass } from \"../../types\";\nimport { createPlugin } from \"../plugin-base\";\n\n/**\n * Validates a timezone string using Intl.DateTimeFormat\n * @param timezone - IANA timezone string to validate\n * @returns true if valid, false otherwise\n */\nfunction isValidTimezone(timezone: string): boolean {\n if (!timezone || typeof timezone !== \"string\") {\n return false;\n }\n\n try {\n // Use Intl.DateTimeFormat to validate timezone\n new Intl.DateTimeFormat(\"en-US\", { timeZone: timezone });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Gets the system's local timezone\n * @returns IANA timezone string for local timezone\n */\nfunction getLocalTimezone(): string {\n return Intl.DateTimeFormat().resolvedOptions().timeZone;\n}\n\n/**\n * Extended DateTime interface with timezone methods\n */\ndeclare module \"../../core/datetime\" {\n interface DateTime {\n /**\n * Sets the timezone for this DateTime instance\n * @param timezone - IANA timezone string (e.g., \"America/New_York\")\n * @returns New DateTime instance with timezone set\n */\n tz(timezone: string): DateTime;\n\n /**\n * Converts this DateTime to a different timezone\n * @param timezone - IANA timezone string\n * @returns New DateTime instance in the specified timezone\n */\n toTimezone(timezone: string): DateTime;\n\n /**\n * Converts this DateTime to UTC timezone\n * @returns New DateTime instance in UTC\n */\n utc(): DateTime;\n\n /**\n * Converts this DateTime to local system timezone\n * @returns New DateTime instance in local timezone\n */\n local(): DateTime;\n\n /**\n * Gets the current timezone of this DateTime instance\n * @returns IANA timezone string\n */\n getTimezone(): string;\n\n /**\n * Internal timezone storage\n * @private\n */\n _timezone?: string;\n }\n}\n\n/**\n * Extended DateTimeClass interface with static timezone method\n */\ndeclare module \"../../types\" {\n interface DateTimeClass {\n /**\n * Creates a DateTime instance in a specific timezone\n * @param input - Date input\n * @param timezone - IANA timezone string\n * @returns DateTime instance in the specified timezone\n */\n tz(input: any, timezone: string): DateTime;\n }\n}\n\n/**\n * Timezone plugin for DateTime\n * Adds timezone support using IANA timezone strings\n */\nexport const timezonePlugin = createPlugin(\n \"timezone\",\n (DateTimeClass: DateTimeClass) => {\n // Add instance methods\n DateTimeClass.prototype.tz = function (timezone: string): DateTime {\n if (!isValidTimezone(timezone)) {\n throw new Error(`Invalid timezone: ${timezone}`);\n }\n\n // Create new instance with same timestamp but different timezone\n const newInstance = new DateTimeClass(this.valueOf());\n (newInstance as any)._timezone = timezone;\n return newInstance;\n };\n\n DateTimeClass.prototype.toTimezone = function (\n timezone: string,\n ): DateTime {\n if (!isValidTimezone(timezone)) {\n throw new Error(`Invalid timezone: ${timezone}`);\n }\n\n // Convert to the new timezone (same as tz for now, as we preserve moment in time)\n const newInstance = new DateTimeClass(this.valueOf());\n (newInstance as any)._timezone = timezone;\n return newInstance;\n };\n\n DateTimeClass.prototype.utc = function (): DateTime {\n const newInstance = new DateTimeClass(this.valueOf());\n (newInstance as any)._timezone = \"UTC\";\n return newInstance;\n };\n\n DateTimeClass.prototype.local = function (): DateTime {\n const localTz = getLocalTimezone();\n const newInstance = new DateTimeClass(this.valueOf());\n (newInstance as any)._timezone = localTz;\n return newInstance;\n };\n\n DateTimeClass.prototype.getTimezone = function (): string {\n return (this as any)._timezone || \"UTC\";\n };\n\n // Add static method\n (DateTimeClass as any).tz = (input: any, timezone: string): DateTime => {\n if (!isValidTimezone(timezone)) {\n throw new Error(`Invalid timezone: ${timezone}`);\n }\n\n const instance = new DateTimeClass(input);\n (instance as any)._timezone = timezone;\n return instance;\n };\n },\n);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;AASA,SAAS,eAAe,CAAC,UAA2B;AAAA,EACjD,IAAI,CAAC,YAAY,OAAO,aAAa,UAAU;AAAA,IAC5C,OAAO;AAAA,EACV;AAAA,EAEA,IAAI;AAAA,IAED,IAAI,KAAK,eAAe,SAAS,EAAE,UAAU,SAAS,CAAC;AAAA,IACvD,OAAO;AAAA,IACR,MAAM;AAAA,IACL,OAAO;AAAA;AAAA;AAQb,SAAS,gBAAgB,GAAW;AAAA,EACjC,OAAO,KAAK,eAAe,EAAE,gBAAgB,EAAE;AAAA;AAmE3C,IAAM,iBAAiB,aAC3B,YACA,CAAC,kBAAiC;AAAA,EAE/B,cAAc,UAAU,KAAK,QAAS,CAAC,UAA4B;AAAA,IAChE,IAAI,CAAC,gBAAgB,QAAQ,GAAG;AAAA,MAC7B,MAAM,IAAI,MAAM,qBAAqB,UAAU;AAAA,IAClD;AAAA,IAGA,MAAM,cAAc,IAAI,cAAc,KAAK,QAAQ,CAAC;AAAA,IACnD,YAAoB,YAAY;AAAA,IACjC,OAAO;AAAA;AAAA,EAGV,cAAc,UAAU,aAAa,QAAS,CAC3C,UACS;AAAA,IACT,IAAI,CAAC,gBAAgB,QAAQ,GAAG;AAAA,MAC7B,MAAM,IAAI,MAAM,qBAAqB,U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