@jsarc/timez 0.0.0

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/web/timez.js ADDED
@@ -0,0 +1,740 @@
1
+ const globalFunct = (function (global) {
2
+ 'use strict';
3
+ class Timez {
4
+ _date;
5
+ static FORMAT_TOKENS = {
6
+ '%Y': (t) => t.year()?.toString().padStart(4, '0'),
7
+ '%y': (t) => t.year()?.toString().slice(-2).padStart(2, '0'),
8
+ '%m': (t) => t.month()?.toString().padStart(2, '0'),
9
+ '%d': (t) => t.date()?.toString().padStart(2, '0'),
10
+ '%H': (t) => t.hour()?.toString().padStart(2, '0'),
11
+ '%M': (t) => t.minute()?.toString().padStart(2, '0'),
12
+ '%S': (t) => t.second()?.toString().padStart(2, '0'),
13
+ '%f': (t) => t.millisecond()?.toString().padStart(3, '0'),
14
+ '%z': (t) => {
15
+ const offset = t.utcOffset();
16
+ if (!offset) {
17
+ return undefined;
18
+ }
19
+ const sign = offset >= 0 ? '+' : '-';
20
+ const hours = Math.floor(Math.abs(offset) / 60).toString().padStart(2, '0');
21
+ const minutes = (Math.abs(offset) % 60).toString().padStart(2, '0');
22
+ return `${sign}${hours}${minutes}`;
23
+ },
24
+ '%s': (t) => {
25
+ const val = t.valueOf();
26
+ return !!val ? Math.floor(val / 1000).toString() : undefined;
27
+ },
28
+ };
29
+ static PREDEFINED_FORMATS = {
30
+ ISO: '%Y-%m-%dT%H:%M:%S.%fZ',
31
+ ISO_DATE: '%Y-%m-%d',
32
+ ISO_TIME: '%H:%M:%S.%fZ',
33
+ COMPACT: '%Y%m%d%H%M%S',
34
+ SLASH_DATETIME: '%Y/%m/%d %H:%M:%S.%fZ',
35
+ SLASH_DATETIME_SEC: '%Y/%m/%d %H:%M:%S',
36
+ SLASH_DATETIME_MIN: '%Y/%m/%d %H:%M',
37
+ EUROPEAN: '%d/%m/%Y %H:%M:%S GMT%z',
38
+ SLASH_DATE: '%Y/%m/%d',
39
+ TIME_MICRO: '%H:%M:%S.%fZ',
40
+ TIME_SEC: '%H:%M:%S',
41
+ CUSTOM_GREETING: '[Bonjour celestin, ][la date actuelle est:: le] %d/%m/%Y [à] %H:%M:%S.%f[Z]',
42
+ };
43
+ constructor(input, enableException = false) {
44
+ if (this.dateChecker(input) === false) {
45
+ this._date = undefined;
46
+ }
47
+ else {
48
+ if (input instanceof Timez && !!input && !!input?._date) {
49
+ this._date = new Date(input?._date);
50
+ }
51
+ else if (input instanceof Date) {
52
+ this._date = new Date(input);
53
+ }
54
+ else if (typeof input === 'string') {
55
+ this._date = Timez.parseString(input, enableException);
56
+ }
57
+ else if (typeof input === 'number') {
58
+ this._date = new Date(input);
59
+ }
60
+ else if (input === undefined ||
61
+ input === null ||
62
+ (typeof input === 'number' && isNaN(input))) {
63
+ this._date = new Date();
64
+ }
65
+ else {
66
+ this._date = undefined;
67
+ }
68
+ }
69
+ }
70
+ static now() {
71
+ return new Timez();
72
+ }
73
+ static parse(dateString, format) {
74
+ if (typeof format === 'string' &&
75
+ format.length > 0 && ((dateString instanceof Timez &&
76
+ !!dateString &&
77
+ !!dateString?._date) ||
78
+ dateString instanceof Date ||
79
+ typeof dateString === 'string' ||
80
+ typeof dateString === 'number' || (dateString === undefined ||
81
+ dateString === null ||
82
+ (typeof dateString === 'number' && isNaN(dateString))))) {
83
+ return Timez.parseWithFormat(dateString, format) || new Timez(dateString);
84
+ }
85
+ return new Timez(dateString);
86
+ }
87
+ static unix(timestamp) {
88
+ return new Timez(timestamp * 1000);
89
+ }
90
+ static utc() {
91
+ const now = new Date();
92
+ return new Timez(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds()));
93
+ }
94
+ year() {
95
+ return this._date?.getFullYear();
96
+ }
97
+ month() {
98
+ return !!this._date ? this._date.getMonth() + 1 : undefined;
99
+ }
100
+ date() {
101
+ return this._date?.getDate();
102
+ }
103
+ hour() {
104
+ return this._date?.getHours();
105
+ }
106
+ minute() {
107
+ return this._date?.getMinutes();
108
+ }
109
+ second() {
110
+ return this._date?.getSeconds();
111
+ }
112
+ millisecond() {
113
+ return this._date?.getMilliseconds();
114
+ }
115
+ day() {
116
+ return this._date?.getDay();
117
+ }
118
+ add(amount, unit) {
119
+ if (!this._date) {
120
+ return new Timez(undefined);
121
+ }
122
+ const newDate = new Date(this._date);
123
+ switch (unit) {
124
+ case 'years':
125
+ newDate.setFullYear(newDate.getFullYear() + amount);
126
+ break;
127
+ case 'months':
128
+ newDate.setMonth(newDate.getMonth() + amount);
129
+ break;
130
+ case 'days':
131
+ newDate.setDate(newDate.getDate() + amount);
132
+ break;
133
+ case 'hours':
134
+ newDate.setHours(newDate.getHours() + amount);
135
+ break;
136
+ case 'minutes':
137
+ newDate.setMinutes(newDate.getMinutes() + amount);
138
+ break;
139
+ case 'seconds':
140
+ newDate.setSeconds(newDate.getSeconds() + amount);
141
+ break;
142
+ case 'milliseconds':
143
+ newDate.setMilliseconds(newDate.getMilliseconds() + amount);
144
+ break;
145
+ }
146
+ return new Timez(newDate);
147
+ }
148
+ subtract(amount, unit) {
149
+ return this.add(-amount, unit);
150
+ }
151
+ startOf(unit) {
152
+ if (!this._date) {
153
+ return new Timez(undefined);
154
+ }
155
+ const newDate = new Date(this._date);
156
+ switch (unit) {
157
+ case 'year':
158
+ newDate.setMonth(0, 1);
159
+ newDate.setHours(0, 0, 0, 0);
160
+ break;
161
+ case 'month':
162
+ newDate.setDate(1);
163
+ newDate.setHours(0, 0, 0, 0);
164
+ break;
165
+ case 'day':
166
+ newDate.setHours(0, 0, 0, 0);
167
+ break;
168
+ case 'hour':
169
+ newDate.setMinutes(0, 0, 0);
170
+ break;
171
+ case 'minute':
172
+ newDate.setSeconds(0, 0);
173
+ break;
174
+ case 'second':
175
+ newDate.setMilliseconds(0);
176
+ break;
177
+ }
178
+ return new Timez(newDate);
179
+ }
180
+ endOf(unit) {
181
+ const start = this.startOf(unit);
182
+ switch (unit) {
183
+ case 'year':
184
+ return start.add(1, 'years').subtract(1, 'milliseconds');
185
+ case 'month':
186
+ return start.add(1, 'months').subtract(1, 'milliseconds');
187
+ case 'day':
188
+ return start.add(1, 'days').subtract(1, 'milliseconds');
189
+ case 'hour':
190
+ return start.add(1, 'hours').subtract(1, 'milliseconds');
191
+ case 'minute':
192
+ return start.add(1, 'minutes').subtract(1, 'milliseconds');
193
+ case 'second':
194
+ return start.add(1, 'seconds').subtract(1, 'milliseconds');
195
+ default:
196
+ return start;
197
+ }
198
+ }
199
+ isBefore(other, inclusivity = '()') {
200
+ const isIncluded = inclusivity[1] === ']';
201
+ const otherTimez = other instanceof Timez ? other : new Timez(other);
202
+ if (!this._date || !otherTimez._date) {
203
+ return false;
204
+ }
205
+ return ((!isIncluded &&
206
+ this._date < otherTimez._date) ||
207
+ (!!isIncluded &&
208
+ this._date <= otherTimez._date));
209
+ }
210
+ isAfter(other, inclusivity = '()') {
211
+ const isIncluded = inclusivity[0] === '[';
212
+ const otherTimez = other instanceof Timez ? other : new Timez(other);
213
+ if (!this._date || !otherTimez._date) {
214
+ return false;
215
+ }
216
+ return ((!isIncluded &&
217
+ this._date > otherTimez._date) ||
218
+ (!!isIncluded &&
219
+ this._date >= otherTimez._date));
220
+ }
221
+ isSame(other, unit) {
222
+ const otherTimez = other instanceof Timez ? other : new Timez(other);
223
+ if (!unit && this._date && otherTimez._date) {
224
+ return this._date.getTime() === otherTimez._date.getTime();
225
+ }
226
+ const thisStart = !!unit ? this.startOf(unit) : undefined;
227
+ const otherStart = !!unit ? otherTimez.startOf(unit) : undefined;
228
+ if (!thisStart || !thisStart?._date || !otherStart || !otherStart?._date) {
229
+ return false;
230
+ }
231
+ return thisStart._date.getTime() === otherStart._date.getTime();
232
+ }
233
+ isBetween(start, end, inclusivity = '()') {
234
+ const startTimez = start instanceof Timez ? start : new Timez(start);
235
+ const endTimez = end instanceof Timez ? end : new Timez(end);
236
+ const startIncluded = inclusivity[0] === '[';
237
+ const endIncluded = inclusivity[1] === ']';
238
+ const afterStart = startIncluded ?
239
+ this.isSame(startTimez) || this.isAfter(startTimez) :
240
+ this.isAfter(startTimez);
241
+ const beforeEnd = endIncluded ?
242
+ this.isSame(endTimez) || this.isBefore(endTimez) :
243
+ this.isBefore(endTimez);
244
+ return afterStart && beforeEnd;
245
+ }
246
+ format(formatString) {
247
+ if (!formatString) {
248
+ return this.toISOString();
249
+ }
250
+ const predefinedFormat = Timez.PREDEFINED_FORMATS[formatString];
251
+ if (predefinedFormat) {
252
+ return this.format(predefinedFormat);
253
+ }
254
+ let result = '';
255
+ let i = 0;
256
+ while (i < formatString.length) {
257
+ if (formatString[i] === '[') {
258
+ const endIndex = formatString.indexOf(']', i);
259
+ if (endIndex === -1) {
260
+ result += formatString[i];
261
+ i++;
262
+ continue;
263
+ }
264
+ const literal = formatString.substring(i + 1, endIndex);
265
+ result += literal;
266
+ i = endIndex + 1;
267
+ }
268
+ else if (formatString[i] === '%' && i + 1 < formatString.length) {
269
+ const token = `%${formatString[i + 1]}`;
270
+ const formatter = Timez.FORMAT_TOKENS[token];
271
+ if (formatter) {
272
+ result += formatter(this);
273
+ }
274
+ else {
275
+ result += token;
276
+ }
277
+ i += 2;
278
+ }
279
+ else {
280
+ result += formatString[i];
281
+ i++;
282
+ }
283
+ }
284
+ return result;
285
+ }
286
+ setTimezone(timezone) {
287
+ if (!this._date) {
288
+ return new Timez(undefined);
289
+ }
290
+ const currentOffset = this._date.getTimezoneOffset();
291
+ const targetOffset = this.parseTimezoneOffset(timezone);
292
+ const adjustedDate = new Date(this._date.getTime() + (targetOffset - currentOffset) * 60000);
293
+ return new Timez(adjustedDate);
294
+ }
295
+ utc() {
296
+ if (!this._date) {
297
+ return new Timez(undefined);
298
+ }
299
+ return new Timez(new Date(Date.UTC(this._date.getUTCFullYear(), this._date.getUTCMonth(), this._date.getUTCDate(), this._date.getUTCHours(), this._date.getUTCMinutes(), this._date.getUTCSeconds(), this._date.getUTCMilliseconds())));
300
+ }
301
+ local() {
302
+ if (!this._date) {
303
+ return new Timez(undefined);
304
+ }
305
+ return new Timez(new Date(this._date.getFullYear(), this._date.getMonth(), this._date.getDate(), this._date.getHours(), this._date.getMinutes(), this._date.getSeconds(), this._date.getMilliseconds()));
306
+ }
307
+ toString() {
308
+ return this._date?.toString();
309
+ }
310
+ toISOString() {
311
+ return this._date?.toISOString();
312
+ }
313
+ toDate() {
314
+ return !!this._date ? new Date(this._date) : undefined;
315
+ }
316
+ valueOf() {
317
+ return this._date?.getTime();
318
+ }
319
+ unix() {
320
+ return !!this._date ? Math.floor(this._date.getTime() / 1000) : undefined;
321
+ }
322
+ utcOffset() {
323
+ return this._date ? -this._date.getTimezoneOffset() : undefined;
324
+ }
325
+ isCorrect() {
326
+ return !!this._date && !isNaN(this._date.getTime());
327
+ }
328
+ timezone() {
329
+ if (!this._date)
330
+ return undefined;
331
+ try {
332
+ const formatter = new Intl.DateTimeFormat();
333
+ const timezone = formatter.resolvedOptions().timeZone;
334
+ return timezone || undefined;
335
+ }
336
+ catch (error) {
337
+ return this.timezoneFromOffset();
338
+ }
339
+ }
340
+ timezoneAbbr() {
341
+ if (!this._date)
342
+ return undefined;
343
+ try {
344
+ const formatter = new Intl.DateTimeFormat('en', {
345
+ timeZoneName: 'short'
346
+ });
347
+ const parts = formatter.formatToParts(this._date);
348
+ const timezonePart = parts.find(part => part.type === 'timeZoneName');
349
+ return timezonePart?.value || undefined;
350
+ }
351
+ catch (error) {
352
+ return this.timezoneAbbrFromOffset();
353
+ }
354
+ }
355
+ timezoneName() {
356
+ if (!this._date)
357
+ return undefined;
358
+ try {
359
+ const formatter = new Intl.DateTimeFormat('en', {
360
+ timeZoneName: 'long'
361
+ });
362
+ const parts = formatter.formatToParts(this._date);
363
+ const timezonePart = parts.find(part => part.type === 'timeZoneName');
364
+ return timezonePart?.value || undefined;
365
+ }
366
+ catch (error) {
367
+ return this.timezoneNameFromOffset();
368
+ }
369
+ }
370
+ timezoneOffsetString() {
371
+ const offset = this.utcOffset();
372
+ if (offset === undefined)
373
+ return undefined;
374
+ const sign = offset >= 0 ? '+' : '-';
375
+ const hours = Math.floor(Math.abs(offset) / 60).toString().padStart(2, '0');
376
+ const minutes = (Math.abs(offset) % 60).toString().padStart(2, '0');
377
+ return `${sign}${hours}:${minutes}`;
378
+ }
379
+ dateChecker(input) {
380
+ return ((input instanceof Timez &&
381
+ !!input &&
382
+ !!input?._date) ||
383
+ input instanceof Date ||
384
+ typeof input === 'string' ||
385
+ typeof input === 'number' || (input === undefined ||
386
+ input === null ||
387
+ (typeof input === 'number' && isNaN(input))));
388
+ }
389
+ timezoneFromOffset() {
390
+ const offset = this.utcOffset();
391
+ if (offset === undefined)
392
+ return undefined;
393
+ const offsetToTimezone = {
394
+ 0: 'Etc/UTC',
395
+ 60: 'Europe/Paris',
396
+ 120: 'Europe/Athens',
397
+ 180: 'Europe/Moscow',
398
+ 240: 'Asia/Dubai',
399
+ 270: 'Asia/Tehran',
400
+ 300: 'Asia/Karachi',
401
+ 330: 'Asia/Kolkata',
402
+ 345: 'Asia/Rangoon',
403
+ 360: 'Asia/Dhaka',
404
+ 390: 'Asia/Yangon',
405
+ 420: 'Asia/Bangkok',
406
+ 480: 'Asia/Shanghai',
407
+ 525: 'Asia/Kathmandu',
408
+ 540: 'Asia/Tokyo',
409
+ 570: 'Australia/Adelaide',
410
+ 600: 'Australia/Sydney',
411
+ 630: 'Australia/Lord_Howe',
412
+ 660: 'Pacific/Noumea',
413
+ 675: 'Australia/Eucla',
414
+ 720: 'Pacific/Auckland',
415
+ 780: 'Pacific/Chatham',
416
+ [-60]: 'Atlantic/Azores',
417
+ [-120]: 'America/Noronha',
418
+ [-180]: 'America/Argentina/Buenos_Aires',
419
+ [-210]: 'America/St_Johns',
420
+ [-240]: 'America/Halifax',
421
+ [-270]: 'America/Caracas',
422
+ [-300]: 'America/New_York',
423
+ [-360]: 'America/Chicago',
424
+ [-420]: 'America/Denver',
425
+ [-480]: 'America/Los_Angeles',
426
+ [-540]: 'America/Anchorage',
427
+ [-600]: 'Pacific/Honolulu',
428
+ [-660]: 'Pacific/Pago_Pago',
429
+ [-720]: 'Pacific/Kiritimati',
430
+ };
431
+ return offsetToTimezone[offset] || `Etc/GMT${offset >= 0 ? '-' : '+'}${Math.abs(offset) / 60}`;
432
+ }
433
+ timezoneAbbrFromOffset() {
434
+ const offset = this.utcOffset();
435
+ if (offset === undefined)
436
+ return undefined;
437
+ const offsetToAbbr = {
438
+ 0: 'GMT',
439
+ 60: 'CET',
440
+ [-300]: 'EST',
441
+ [-360]: 'CST',
442
+ [-420]: 'MST',
443
+ [-480]: 'PST',
444
+ };
445
+ return offsetToAbbr[offset] || `GMT${offset >= 0 ? '+' : ''}${offset / 60}`;
446
+ }
447
+ timezoneNameFromOffset() {
448
+ const offset = this.utcOffset();
449
+ if (offset === undefined)
450
+ return undefined;
451
+ const offsetToName = {
452
+ 0: 'Greenwich Mean Time',
453
+ 60: 'Central European Time',
454
+ [-300]: 'Eastern Standard Time',
455
+ [-360]: 'Central Standard Time',
456
+ [-420]: 'Mountain Standard Time',
457
+ [-480]: 'Pacific Standard Time',
458
+ };
459
+ return offsetToName[offset] || `GMT${offset >= 0 ? '+' : ''}${offset / 60}`;
460
+ }
461
+ isDST() {
462
+ if (!this._date)
463
+ return undefined;
464
+ try {
465
+ const jan = new Date(this._date.getFullYear(), 0, 1);
466
+ const jul = new Date(this._date.getFullYear(), 6, 1);
467
+ const stdOffset = Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
468
+ return this._date.getTimezoneOffset() < stdOffset;
469
+ }
470
+ catch (error) {
471
+ return undefined;
472
+ }
473
+ }
474
+ static parseString(dateString, enableException = false) {
475
+ const isoDate = new Date(dateString);
476
+ if (!isNaN(isoDate.getTime())) {
477
+ return isoDate;
478
+ }
479
+ const formats = [
480
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})Z$/,
481
+ /^(\d{4})-(\d{2})-(\d{2})$/,
482
+ /^(\d{4})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
483
+ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
484
+ ];
485
+ for (const regex of formats) {
486
+ const match = dateString.match(regex);
487
+ if (match) {
488
+ const components = match.slice(1).map(Number);
489
+ if (regex === formats[0]) {
490
+ return new Date(Date.UTC(components[0], components[1] - 1, components[2], components[3], components[4], components[5], components[6]));
491
+ }
492
+ else if (regex === formats[1]) {
493
+ return new Date(components[0], components[1] - 1, components[2]);
494
+ }
495
+ else if (regex === formats[2]) {
496
+ return new Date(components[0], components[1] - 1, components[2], components[3], components[4], components[5]);
497
+ }
498
+ else if (regex === formats[3]) {
499
+ return new Date(components[0], components[1] - 1, components[2], components[3], components[4], components[5]);
500
+ }
501
+ }
502
+ }
503
+ const fallback = new Date(dateString);
504
+ if (!isNaN(fallback.getTime())) {
505
+ return fallback;
506
+ }
507
+ if (!!enableException) {
508
+ throw new Error(`Unable to parse date string: ${dateString}`);
509
+ }
510
+ }
511
+ static parseWithFormat(value, format) {
512
+ if (!value || !format)
513
+ return undefined;
514
+ const valueStr = String(value).trim();
515
+ if (!valueStr)
516
+ return undefined;
517
+ const tokenHandlers = {
518
+ 'Y': {
519
+ regex: /\d{4}/,
520
+ extract: (match) => parseInt(match, 10)
521
+ },
522
+ 'y': {
523
+ regex: /\d{2}/,
524
+ extract: (match) => {
525
+ const year = parseInt(match, 10);
526
+ return year >= 70 ? 1900 + year : 2000 + year;
527
+ }
528
+ },
529
+ 'm': {
530
+ regex: /\d{1,2}/,
531
+ extract: (match) => parseInt(match, 10)
532
+ },
533
+ 'd': {
534
+ regex: /\d{1,2}/,
535
+ extract: (match) => parseInt(match, 10)
536
+ },
537
+ 'H': {
538
+ regex: /\d{1,2}/,
539
+ extract: (match) => parseInt(match, 10)
540
+ },
541
+ 'M': {
542
+ regex: /\d{1,2}/,
543
+ extract: (match) => parseInt(match, 10)
544
+ },
545
+ 'S': {
546
+ regex: /\d{1,2}/,
547
+ extract: (match) => parseInt(match, 10)
548
+ },
549
+ 'f': {
550
+ regex: /\d{1,3}/,
551
+ extract: (match) => parseInt(match, 10)
552
+ }
553
+ };
554
+ const result = {
555
+ year: new Date().getFullYear(),
556
+ month: 1,
557
+ day: 1,
558
+ hour: 0,
559
+ minute: 0,
560
+ second: 0,
561
+ millisecond: 0
562
+ };
563
+ let valueIndex = 0;
564
+ let formatIndex = 0;
565
+ let inLiteral = false;
566
+ let currentLiteral = '';
567
+ while (formatIndex < format.length && valueIndex < valueStr.length) {
568
+ const formatChar = format[formatIndex];
569
+ if (formatChar === '[') {
570
+ inLiteral = true;
571
+ currentLiteral = '';
572
+ formatIndex++;
573
+ }
574
+ else if (formatChar === ']' && inLiteral) {
575
+ if (valueStr.substring(valueIndex, valueIndex + currentLiteral.length) === currentLiteral) {
576
+ valueIndex += currentLiteral.length;
577
+ }
578
+ else {
579
+ return undefined;
580
+ }
581
+ inLiteral = false;
582
+ currentLiteral = '';
583
+ formatIndex++;
584
+ }
585
+ else if (inLiteral) {
586
+ currentLiteral += formatChar;
587
+ formatIndex++;
588
+ }
589
+ else if (formatChar === '%' && formatIndex + 1 < format.length) {
590
+ const token = format[formatIndex + 1];
591
+ const handler = tokenHandlers[token];
592
+ if (handler) {
593
+ const remainingValue = valueStr.substring(valueIndex);
594
+ const match = remainingValue.match(handler.regex);
595
+ if (match && match.index === 0) {
596
+ const matchedValue = match[0];
597
+ const numericValue = handler.extract(matchedValue);
598
+ switch (token) {
599
+ case 'Y':
600
+ case 'y':
601
+ result.year = numericValue;
602
+ break;
603
+ case 'm':
604
+ result.month = numericValue;
605
+ break;
606
+ case 'd':
607
+ result.day = numericValue;
608
+ break;
609
+ case 'H':
610
+ result.hour = numericValue;
611
+ break;
612
+ case 'M':
613
+ result.minute = numericValue;
614
+ break;
615
+ case 'S':
616
+ result.second = numericValue;
617
+ break;
618
+ case 'f':
619
+ result.millisecond = numericValue;
620
+ break;
621
+ }
622
+ valueIndex += matchedValue.length;
623
+ }
624
+ else {
625
+ return undefined;
626
+ }
627
+ }
628
+ else {
629
+ valueIndex++;
630
+ }
631
+ formatIndex += 2;
632
+ }
633
+ else {
634
+ if (formatChar === valueStr[valueIndex]) {
635
+ valueIndex++;
636
+ formatIndex++;
637
+ }
638
+ else {
639
+ return undefined;
640
+ }
641
+ }
642
+ }
643
+ if (result.month < 1 || result.month > 12)
644
+ return undefined;
645
+ if (result.day < 1 || result.day > 31)
646
+ return undefined;
647
+ if (result.hour < 0 || result.hour > 23)
648
+ return undefined;
649
+ if (result.minute < 0 || result.minute > 59)
650
+ return undefined;
651
+ if (result.second < 0 || result.second > 59)
652
+ return undefined;
653
+ if (result.millisecond < 0 || result.millisecond > 999)
654
+ return undefined;
655
+ try {
656
+ const date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, result.second, result.millisecond);
657
+ if (isNaN(date.getTime())) {
658
+ return undefined;
659
+ }
660
+ return new Timez(date);
661
+ }
662
+ catch (error) {
663
+ return undefined;
664
+ }
665
+ }
666
+ static getTokenLength(token) {
667
+ const tokenLengths = {
668
+ 'Y': 4,
669
+ 'y': 2,
670
+ 'm': 2,
671
+ 'd': 2,
672
+ 'H': 2,
673
+ 'M': 2,
674
+ 'S': 2,
675
+ 'f': 3,
676
+ 'z': 5
677
+ };
678
+ return tokenLengths[token] || 1;
679
+ }
680
+ parseTimezoneOffset(timezone) {
681
+ const offsets = {
682
+ 'UTC': 0,
683
+ 'EST': -300,
684
+ 'EDT': -240,
685
+ 'CST': -360,
686
+ 'CDT': -300,
687
+ 'PST': -480,
688
+ 'PDT': -420,
689
+ };
690
+ if (offsets[timezone.toUpperCase()] !== undefined) {
691
+ return offsets[timezone.toUpperCase()];
692
+ }
693
+ const match = timezone.match(/^([+-])(\d{1,2}):?(\d{2})?$/);
694
+ if (match) {
695
+ const sign = match[1] === '+' ? 1 : -1;
696
+ const hours = parseInt(match[2], 10);
697
+ const minutes = match[3] ? parseInt(match[3], 10) : 0;
698
+ return sign * (hours * 60 + minutes);
699
+ }
700
+ return this._date ? -this._date.getTimezoneOffset() : 0;
701
+ }
702
+ static get FORMATS() {
703
+ return { ...Timez.PREDEFINED_FORMATS };
704
+ }
705
+ static exposeToGlobal() {
706
+ if (typeof window !== 'undefined') {
707
+ window.Timez = Timez;
708
+ }
709
+ }
710
+ }
711
+ if (typeof window !== 'undefined') {
712
+ window.Timez = Timez;
713
+ }
714
+ const globalFunctModule = {
715
+ default: Timez,
716
+ Timez: Timez,
717
+ };
718
+ const __bundledModules = globalFunctModule;
719
+ if (typeof global !== 'undefined') {
720
+ global.default = Timez;
721
+ global.Timez = Timez;
722
+ global.__bundledModules = __bundledModules;
723
+ }
724
+ if (typeof window !== "undefined") {
725
+ window.default = Timez;
726
+ window.Timez = Timez;
727
+ window.__bundledModules = __bundledModules;
728
+ }
729
+ if (typeof exports !== 'undefined') {
730
+ exports.default = Timez;
731
+ exports.Timez = Timez;
732
+ }
733
+ return globalFunctModule;
734
+ })(typeof global !== 'undefined' ? global :
735
+ typeof window !== 'undefined' ? window :
736
+ typeof self !== 'undefined' ? self :
737
+ typeof globalThis !== 'undefined' ? globalThis :
738
+ {});
739
+ const TimezElementGF = globalFunct.Timez;
740
+ const defaultElementGF = globalFunct.default;