@bereasoftware/time-guard 2.0.4 → 2.0.6

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.
Files changed (41) hide show
  1. package/README.en.md +0 -4
  2. package/README.md +0 -4
  3. package/dist/calendars/index.es.js +1 -1
  4. package/dist/locales/index.es.js +1 -1
  5. package/dist/plugins/advanced-format.es.js +1 -1
  6. package/dist/plugins/duration.es.js +1 -1
  7. package/dist/plugins/relative-time.es.js +1 -1
  8. package/dist/time-guard.cjs +1 -1
  9. package/dist/time-guard.es.js +3627 -144
  10. package/dist/time-guard.iife.js +1 -1
  11. package/dist/time-guard.umd.js +1 -1
  12. package/dist/types/adapters/temporal.adapter.d.ts +60 -0
  13. package/dist/types/calendars/calendar.manager.d.ts +52 -0
  14. package/dist/types/calendars/index.d.ts +81 -0
  15. package/dist/types/formatters/date.formatter.d.ts +21 -0
  16. package/dist/types/index.d.ts +19 -0
  17. package/dist/types/locales/additional.locale.d.ts +5 -0
  18. package/dist/types/locales/asian.locale.d.ts +9 -0
  19. package/dist/types/locales/english.locale.d.ts +6 -0
  20. package/dist/types/locales/european.locale.d.ts +9 -0
  21. package/dist/types/locales/index.d.ts +17 -0
  22. package/dist/types/locales/locale.manager.d.ts +42 -0
  23. package/dist/types/locales/locales-data.d.ts +17 -0
  24. package/dist/types/locales/middle-eastern.locale.d.ts +5 -0
  25. package/dist/types/locales/nordic.locale.d.ts +6 -0
  26. package/dist/types/locales/romance.locale.d.ts +7 -0
  27. package/dist/types/locales/slavic.locale.d.ts +6 -0
  28. package/dist/types/locales/spanish.locale.d.ts +5 -0
  29. package/dist/types/plugins/advanced-format/index.d.ts +47 -0
  30. package/dist/types/plugins/duration/index.d.ts +107 -0
  31. package/dist/types/plugins/duration/types.d.ts +85 -0
  32. package/dist/types/plugins/index.d.ts +10 -0
  33. package/dist/types/plugins/manager.d.ts +58 -0
  34. package/dist/types/plugins/relative-time/index.d.ts +39 -0
  35. package/dist/types/plugins/relative-time/types.d.ts +27 -0
  36. package/dist/types/polyfill-loader.d.ts +5 -0
  37. package/dist/types/time-guard.d.ts +151 -1130
  38. package/dist/types/types/index.d.ts +301 -0
  39. package/package.json +20 -29
  40. package/dist/full.cjs +0 -1
  41. package/dist/full.es.js +0 -4341
@@ -1,1130 +1,151 @@
1
- import { Temporal } from '@js-temporal/polyfill';
2
-
3
- export declare class AdvancedFormatPlugin implements ITimeGuardPlugin {
4
- name: string;
5
- version: string;
6
- /**
7
- * Install plugin into TimeGuard
8
- */
9
- install(TimeGuardClass: typeof TimeGuard): void;
10
- /**
11
- * Get ordinal suffix (1st, 2nd, 3rd, etc.)
12
- */
13
- private getOrdinal;
14
- /**
15
- * Pad number with leading zeros
16
- */
17
- private padNumber;
18
- /**
19
- * Get ISO week number
20
- */
21
- private getISOWeek;
22
- /**
23
- * Get week of year (locale-based)
24
- */
25
- private getWeekOfYear;
26
- /**
27
- * Get ISO week year
28
- */
29
- private getISOWeekYear;
30
- /**
31
- * Get week year
32
- */
33
- private getWeekYear;
34
- /**
35
- * Get timezone offset short form
36
- */
37
- private getTimezoneOffset;
38
- /**
39
- * Get timezone offset long form
40
- */
41
- private getTimezoneOffsetLong;
42
- }
43
-
44
- /**
45
- * Create and export default instance
46
- */
47
- export declare const advancedFormatPlugin: AdvancedFormatPlugin;
48
-
49
- /**
50
- * Aggregated locale data from all modules
51
- */
52
- export declare const ALL_LOCALES: Record<string, ILocale>;
53
-
54
- /**
55
- * Buddhist Calendar
56
- * @experimental Uses Gregorian rules with BE year offset (CE + 543).
57
- */
58
- export declare class BuddhistCalendar implements ICalendarSystem {
59
- readonly id = "buddhist";
60
- readonly name = "Buddhist Calendar";
61
- readonly locale = "th";
62
- private monthNames;
63
- getMonthName(month: number): string;
64
- getWeekdayName(day: number): string;
65
- isLeapYear(year: number): boolean;
66
- daysInMonth(year: number, month: number): number;
67
- daysInYear(year: number): number;
68
- }
69
-
70
- /**
71
- * Calendar Manager - Singleton for managing calendar systems
72
- */
73
- export declare class CalendarManager implements ICalendarManager {
74
- private static instance;
75
- private calendars;
76
- private defaultCalendar;
77
- private constructor();
78
- /**
79
- * Get singleton instance
80
- */
81
- static getInstance(): CalendarManager;
82
- /**
83
- * Register a new calendar system
84
- */
85
- register(calendar: ICalendarSystem): void;
86
- /**
87
- * Get calendar by ID
88
- */
89
- get(id: string): ICalendarSystem | undefined;
90
- /**
91
- * List all available calendars
92
- */
93
- list(): string[];
94
- /**
95
- * Set default calendar
96
- */
97
- setDefault(id: string): void;
98
- /**
99
- * Get default calendar
100
- */
101
- getDefault(): ICalendarSystem;
102
- }
103
-
104
- export declare const calendarManager: CalendarManager;
105
-
106
- /**
107
- * Chinese Calendar
108
- * @experimental Uses simplified calculations. May not be accurate for all dates.
109
- */
110
- export declare class ChineseCalendar implements ICalendarSystem {
111
- readonly id = "chinese";
112
- readonly name = "Chinese Calendar";
113
- readonly locale = "zh";
114
- private monthNames;
115
- private terrestrialBranches;
116
- getMonthName(month: number): string;
117
- getWeekdayName(day: number, short?: boolean): string;
118
- isLeapYear(year: number): boolean;
119
- daysInMonth(_year: number, month: number): number;
120
- daysInYear(year: number): number;
121
- /**
122
- * Get zodiac sign for year
123
- */
124
- getZodiacSign(year: number): string;
125
- }
126
-
127
- /**
128
- * Date Formatter implementation
129
- */
130
- export declare class DateFormatter implements IDateFormatter {
131
- private localeManager;
132
- constructor();
133
- /**
134
- * Format date with pattern and locale
135
- */
136
- format(date: Temporal.PlainDateTime, pattern: string, locale?: string): string;
137
- /**
138
- * Get format pattern for preset
139
- */
140
- getPreset(preset: FormatPreset): string;
141
- /**
142
- * Format with preset
143
- */
144
- formatPreset(date: Temporal.PlainDateTime, preset: FormatPreset, locale?: string): string;
145
- }
146
-
147
- /**
148
- * Duration class - represents time span following ISO 8601 standard
149
- */
150
- export declare class Duration implements IDuration {
151
- private years;
152
- private months;
153
- private weeks;
154
- private days;
155
- private hours;
156
- private minutes;
157
- private seconds;
158
- private milliseconds;
159
- constructor(input: DurationInput);
160
- /**
161
- * Create Duration from ISO 8601 string
162
- * @example Duration.fromISO("P3Y6M4DT12H30M5S")
163
- */
164
- static fromISO(iso: string): Duration;
165
- /**
166
- * Create a Duration between this date and another
167
- */
168
- static between(from: TimeGuard, to: TimeGuard): Duration;
169
- /**
170
- * Create Duration from milliseconds
171
- */
172
- static fromMilliseconds(ms: number): Duration;
173
- /**
174
- * Get duration in specific unit
175
- */
176
- as(unit: DurationUnit): number;
177
- /**
178
- * Get duration as milliseconds
179
- */
180
- asMilliseconds(): number;
181
- /**
182
- * Get duration as seconds
183
- */
184
- asSeconds(): number;
185
- /**
186
- * Get duration as minutes
187
- */
188
- asMinutes(): number;
189
- /**
190
- * Get duration as hours
191
- */
192
- asHours(): number;
193
- /**
194
- * Get duration as days
195
- */
196
- asDays(): number;
197
- /**
198
- * Get duration as weeks
199
- */
200
- asWeeks(): number;
201
- /**
202
- * Get duration as months
203
- */
204
- asMonths(): number;
205
- /**
206
- * Get duration as years
207
- */
208
- asYears(): number;
209
- /**
210
- * Get all components
211
- */
212
- toObject(): DurationObject;
213
- /**
214
- * Get ISO 8601 string representation
215
- * @example "P3Y6M4DT12H30M5S"
216
- */
217
- toISO(): string;
218
- /**
219
- * Get human-readable string
220
- */
221
- humanize(): string;
222
- /**
223
- * Check if duration is negative
224
- */
225
- isNegative(): boolean;
226
- /**
227
- * Get absolute duration
228
- */
229
- abs(): Duration;
230
- /**
231
- * String representation
232
- */
233
- toString(): string;
234
- }
235
-
236
- export declare interface DurationInput {
237
- years?: number;
238
- months?: number;
239
- weeks?: number;
240
- days?: number;
241
- hours?: number;
242
- minutes?: number;
243
- seconds?: number;
244
- milliseconds?: number;
245
- }
246
-
247
- export declare interface DurationObject {
248
- years: number;
249
- months: number;
250
- weeks: number;
251
- days: number;
252
- hours: number;
253
- minutes: number;
254
- seconds: number;
255
- milliseconds: number;
256
- }
257
-
258
- /**
259
- * Duration Plugin
260
- */
261
- export declare class DurationPlugin implements ITimeGuardPlugin {
262
- name: string;
263
- version: string;
264
- /**
265
- * Install plugin into TimeGuard
266
- */
267
- install(TimeGuardClass: typeof TimeGuard): void;
268
- }
269
-
270
- /**
271
- * Create and export default instance
272
- */
273
- export declare const durationPlugin: DurationPlugin;
274
-
275
- /**
276
- * Duration Plugin Types
277
- */
278
- export declare type DurationUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
279
-
280
- /**
281
- * English locale data
282
- */
283
- export declare const EN_LOCALE: ILocale;
284
-
285
- /**
286
- * Spanish locale data (sample for i18n support)
287
- */
288
- export declare const ES_LOCALE: ILocale;
289
-
290
- /**
291
- * Format preset strings for common patterns
292
- */
293
- export declare type FormatPreset = 'iso' | 'date' | 'time' | 'datetime' | 'rfc2822' | 'rfc3339' | 'utc';
294
-
295
- /**
296
- * Get all available locales
297
- */
298
- export declare function getAvailableLocales(): string[];
299
-
300
- /**
301
- * Gregorian Calendar System (ISO 8601 default)
302
- */
303
- export declare class GregorianCalendar implements ICalendarSystem {
304
- readonly id = "gregory";
305
- readonly name = "Gregorian Calendar";
306
- readonly locale = "en";
307
- private monthNames;
308
- private monthNamesShort;
309
- private weekdayNames;
310
- private weekdayNamesShort;
311
- getMonthName(month: number, short?: boolean): string;
312
- getWeekdayName(day: number, short?: boolean): string;
313
- isLeapYear(year: number): boolean;
314
- daysInMonth(year: number, month: number): number;
315
- daysInYear(year: number): number;
316
- }
317
-
318
- /**
319
- * Hebrew Calendar
320
- * @experimental Uses simplified calculations. May not be accurate for all dates.
321
- */
322
- export declare class HebrewCalendar implements ICalendarSystem {
323
- readonly id = "hebrew";
324
- readonly name = "Hebrew Calendar";
325
- readonly locale = "he";
326
- private monthNames;
327
- getMonthName(month: number): string;
328
- getWeekdayName(day: number, short?: boolean): string;
329
- isLeapYear(year: number): boolean;
330
- daysInMonth(_year: number, month: number): number;
331
- daysInYear(year: number): number;
332
- }
333
-
334
- /**
335
- * Calendar manager interface
336
- */
337
- export declare interface ICalendarManager {
338
- register(calendar: ICalendarSystem): void;
339
- get(id: string): ICalendarSystem | undefined;
340
- list(): string[];
341
- setDefault(id: string): void;
342
- getDefault(): ICalendarSystem;
343
- }
344
-
345
- /**
346
- * Calendar system interface
347
- */
348
- export declare interface ICalendarSystem {
349
- id: string;
350
- name: string;
351
- locale?: string;
352
- getMonthName(month: number, short?: boolean): string;
353
- getWeekdayName(day: number, short?: boolean): string;
354
- isLeapYear(year: number): boolean;
355
- daysInMonth(year: number, month: number): number;
356
- daysInYear(year: number): number;
357
- }
358
-
359
- /**
360
- * Interface for arithmetic operations
361
- */
362
- export declare interface IDateArithmetic {
363
- add(units: Partial<Record<Unit, number>> | IDuration_2): TimeGuard_2;
364
- subtract(units: Partial<Record<Unit, number>> | IDuration_2): TimeGuard_2;
365
- diff(other: TimeGuard_2, unit?: Unit): number;
366
- until(other: TimeGuard_2, options?: IRoundOptions): IDuration_2;
367
- round(options: IRoundOptions): TimeGuard_2;
368
- }
369
-
370
- /**
371
- * Interface for date/time formatting (Strategy Pattern)
372
- */
373
- export declare interface IDateFormatter {
374
- format(date: any, pattern: string): string;
375
- getPreset(preset: FormatPreset): string;
376
- }
377
-
378
- /**
379
- * Interface for manipulation operations
380
- */
381
- export declare interface IDateManipulation {
382
- clone(): TimeGuard_2;
383
- startOf(unit: Unit): TimeGuard_2;
384
- endOf(unit: Unit): TimeGuard_2;
385
- set(values: Partial<Record<Unit, number>>): TimeGuard_2;
386
- year(): number;
387
- month(): number;
388
- day(): number;
389
- hour(): number;
390
- minute(): number;
391
- second(): number;
392
- millisecond(): number;
393
- dayOfWeek(): number;
394
- dayOfYear(): number;
395
- weekOfYear(): number;
396
- daysInMonth(): number;
397
- daysInYear(): number;
398
- inLeapYear(): boolean;
399
- }
400
-
401
- /**
402
- * Interface for date/time parsing strategy (Strategy Pattern)
403
- */
404
- export declare interface IDateParser {
405
- parse(input: unknown): any | null;
406
- canHandle(input: unknown): boolean;
407
- }
408
-
409
- /**
410
- * Interface for query operations
411
- */
412
- export declare interface IDateQuery {
413
- isBefore(other: TimeGuard_2): boolean;
414
- isAfter(other: TimeGuard_2): boolean;
415
- isSame(other: TimeGuard_2, unit?: Unit): boolean;
416
- isBetween(start: TimeGuard_2, end: TimeGuard_2, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
417
- }
418
-
419
- /**
420
- * Duration class for ISO 8601 durations
421
- */
422
- export declare interface IDuration {
423
- /**
424
- * Get duration in specific unit
425
- */
426
- as(unit: DurationUnit): number;
427
- /**
428
- * Get duration as milliseconds
429
- */
430
- asMilliseconds(): number;
431
- /**
432
- * Get duration as seconds
433
- */
434
- asSeconds(): number;
435
- /**
436
- * Get duration as minutes
437
- */
438
- asMinutes(): number;
439
- /**
440
- * Get duration as hours
441
- */
442
- asHours(): number;
443
- /**
444
- * Get duration as days
445
- */
446
- asDays(): number;
447
- /**
448
- * Get duration as weeks
449
- */
450
- asWeeks(): number;
451
- /**
452
- * Get duration as months
453
- */
454
- asMonths(): number;
455
- /**
456
- * Get duration as years
457
- */
458
- asYears(): number;
459
- /**
460
- * Get all components
461
- */
462
- toObject(): DurationObject;
463
- /**
464
- * Get ISO 8601 string representation
465
- */
466
- toISO(): string;
467
- /**
468
- * Get human-readable string
469
- */
470
- humanize(): string;
471
- /**
472
- * Check if duration is negative
473
- */
474
- isNegative(): boolean;
475
- /**
476
- * Get absolute duration
477
- */
478
- abs(): IDuration;
479
- }
480
-
481
- /**
482
- * Duration-like object for arithmetic operations
483
- */
484
- declare interface IDuration_2 {
485
- years?: number;
486
- months?: number;
487
- weeks?: number;
488
- days?: number;
489
- hours?: number;
490
- minutes?: number;
491
- seconds?: number;
492
- milliseconds?: number;
493
- microseconds?: number;
494
- nanoseconds?: number;
495
- }
496
-
497
- /**
498
- * Locale configuration interface
499
- */
500
- export declare interface ILocale {
501
- name: string;
502
- months: string[];
503
- monthsShort: string[];
504
- weekdays: string[];
505
- weekdaysShort: string[];
506
- weekdaysMin: string[];
507
- meridiem?: {
508
- am: string;
509
- pm: string;
510
- };
511
- formats?: Record<string, string>;
512
- }
513
-
514
- /**
515
- * Interface for locale management (Single Responsibility)
516
- */
517
- export declare interface ILocaleManager {
518
- setLocale(locale: string, data?: ILocale): void;
519
- getLocale(locale?: string): ILocale;
520
- listLocales(): string[];
521
- }
522
-
523
- /**
524
- * Round options for precision control
525
- */
526
- export declare interface IRoundOptions {
527
- smallestUnit?: Unit;
528
- roundingMode?: 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfExpand' | 'halfFloor' | 'halfCeil' | 'halfTrunc';
529
- roundingIncrement?: number;
530
- }
531
-
532
- /**
533
- * Islamic Calendar (Hijri)
534
- * @experimental Uses simplified calculations. May not be accurate for all dates.
535
- */
536
- export declare class IslamicCalendar implements ICalendarSystem {
537
- readonly id = "islamic";
538
- readonly name = "Islamic Calendar (Hijri)";
539
- readonly locale = "ar";
540
- private monthNames;
541
- getMonthName(month: number): string;
542
- getWeekdayName(day: number, short?: boolean): string;
543
- isLeapYear(year: number): boolean;
544
- daysInMonth(year: number, month: number): number;
545
- daysInYear(year: number): number;
546
- }
547
-
548
- /**
549
- * Main TimeGuard interface (Facade Pattern)
550
- */
551
- export declare interface ITimeGuard extends IDateArithmetic, IDateQuery, IDateManipulation {
552
- /**
553
- * Get the underlying Temporal date object
554
- */
555
- toTemporal(): any;
556
- /**
557
- * Get as JavaScript Date (compatibility)
558
- */
559
- toDate(): Date;
560
- /**
561
- * Get as ISO string
562
- */
563
- toISOString(): string;
564
- /**
565
- * Get as Unix timestamp (milliseconds)
566
- */
567
- valueOf(): number;
568
- /**
569
- * Format the date with pattern or preset
570
- */
571
- format(pattern: string | FormatPreset): string;
572
- /**
573
- * Get accessor for components
574
- */
575
- get(component: Unit): number;
576
- /**
577
- * Locale of this instance
578
- */
579
- locale(): string;
580
- /**
581
- * Clone with new locale
582
- */
583
- locale(locale: string): TimeGuard_2;
584
- /**
585
- * Timezone info
586
- */
587
- timezone(): string | null;
588
- /**
589
- * Convert to another timezone
590
- */
591
- timezone(timezone: string): TimeGuard_2;
592
- /**
593
- * Get Unix timestamp in seconds
594
- */
595
- unix(): number;
596
- /**
597
- * Convert to JSON
598
- */
599
- toJSON(): string;
600
- /**
601
- * String representation
602
- */
603
- toString(): string;
604
- /**
605
- * Convert to PlainDate object
606
- */
607
- toPlainDate(): {
608
- year: number;
609
- month: number;
610
- day: number;
611
- dayOfWeek: number;
612
- };
613
- /**
614
- * Convert to PlainTime object
615
- */
616
- toPlainTime(): {
617
- hour: number;
618
- minute: number;
619
- second: number;
620
- millisecond: number;
621
- };
622
- /**
623
- * Get timezone offset (±HH:mm format or Z)
624
- */
625
- getOffset(): string;
626
- /**
627
- * Get timezone offset in nanoseconds
628
- */
629
- getOffsetNanoseconds(): number;
630
- /**
631
- * Get timezone ID
632
- */
633
- getTimeZoneId(): string | null;
634
- /**
635
- * Start of day
636
- */
637
- startOfDay(): TimeGuard_2;
638
- /**
639
- * End of day
640
- */
641
- endOfDay(): TimeGuard_2;
642
- /**
643
- * Duration from another date (inverse of until)
644
- */
645
- since(other: TimeGuard_2): IDuration_2;
646
- /**
647
- * ISO 8601 duration string (P1Y2M3DT4H5M6S)
648
- */
649
- toDurationString(other?: TimeGuard_2): string;
650
- /**
651
- * Check if in past
652
- */
653
- isPast(): boolean;
654
- /**
655
- * Check if in future
656
- */
657
- isFuture(): boolean;
658
- /**
659
- * Check if today
660
- */
661
- isToday(): boolean;
662
- /**
663
- * Check if tomorrow
664
- */
665
- isTomorrow(): boolean;
666
- /**
667
- * Check if yesterday
668
- */
669
- isYesterday(): boolean;
670
- }
671
-
672
- /**
673
- * Configuration options for TimeGuard instance
674
- */
675
- export declare interface ITimeGuardConfig {
676
- locale?: string;
677
- timezone?: string;
678
- strict?: boolean;
679
- }
680
-
681
- /**
682
- * Factory interface
683
- */
684
- export declare interface ITimeGuardFactory {
685
- create(input?: unknown, config?: ITimeGuardConfig): ITimeGuard;
686
- now(config?: ITimeGuardConfig): ITimeGuard;
687
- fromTemporal(date: any, config?: ITimeGuardConfig): ITimeGuard;
688
- }
689
-
690
- /**
691
- * Plugin interface for extending functionality
692
- */
693
- export declare interface ITimeGuardPlugin {
694
- name: string;
695
- version: string;
696
- install(timeGuard: typeof TimeGuard_2, config?: unknown): void;
697
- }
698
-
699
- /**
700
- * Interface for timezone operations
701
- */
702
- export declare interface ITimezoneAdapter {
703
- toTimezone(date: any, timezone: string): any;
704
- fromTimezone(date: any, targetTimezone: string): any;
705
- getOffset(timezone: string): number;
706
- }
707
-
708
- /**
709
- * Japanese Calendar
710
- * @experimental Uses Gregorian rules post-1873. Historical dates may not be accurate.
711
- */
712
- export declare class JapaneseCalendar implements ICalendarSystem {
713
- readonly id = "japanese";
714
- readonly name = "Japanese Calendar";
715
- readonly locale = "ja";
716
- private monthNames;
717
- getMonthName(month: number): string;
718
- getWeekdayName(day: number, short?: boolean): string;
719
- isLeapYear(year: number): boolean;
720
- daysInMonth(year: number, month: number): number;
721
- daysInYear(year: number): number;
722
- }
723
-
724
- /**
725
- * Locale Manager - implements ILocaleManager
726
- */
727
- export declare class LocaleManager implements ILocaleManager {
728
- private static instance;
729
- private locales;
730
- private currentLocale;
731
- /**
732
- * Singleton pattern
733
- */
734
- static getInstance(): LocaleManager;
735
- private constructor();
736
- /**
737
- * Set or register a locale
738
- */
739
- setLocale(locale: string, data?: ILocale): void;
740
- /**
741
- * Get locale information
742
- */
743
- getLocale(locale?: string): ILocale;
744
- /**
745
- * List all registered locales
746
- */
747
- listLocales(): string[];
748
- /**
749
- * Get current locale
750
- */
751
- getCurrentLocale(): string;
752
- /**
753
- * Load multiple locales
754
- */
755
- loadLocales(locales: Record<string, ILocale>): void;
756
- }
757
-
758
- /**
759
- * Total locales count (minimum 40 required)
760
- */
761
- export declare const LOCALES_COUNT = 40;
762
-
763
- /**
764
- * Plugin Manager - handles plugin registration and initialization
765
- * Uses Singleton pattern to ensure single instance across application
766
- */
767
- export declare class PluginManager {
768
- private static instance;
769
- private plugins;
770
- /**
771
- * Get singleton instance
772
- */
773
- static getInstance(): PluginManager;
774
- /**
775
- * Register a plugin
776
- * @param plugin - The plugin to register
777
- * @param timeGuardClass - Reference to TimeGuard class
778
- * @param config - Optional plugin configuration
779
- */
780
- static use(plugin: ITimeGuardPlugin, timeGuardClass: typeof TimeGuard, config?: unknown): void;
781
- /**
782
- * Register multiple plugins at once
783
- * @param plugins - Array of plugins to register
784
- * @param timeGuardClass - Reference to TimeGuard class
785
- * @param config - Optional plugin configuration
786
- */
787
- static useMultiple(plugins: ITimeGuardPlugin[], timeGuardClass: typeof TimeGuard, config?: unknown): void;
788
- /**
789
- * Get registered plugin by name
790
- * @param name - Plugin name
791
- * @returns Plugin instance or undefined
792
- */
793
- static getPlugin(name: string): ITimeGuardPlugin | undefined;
794
- /**
795
- * Check if plugin is registered
796
- * @param name - Plugin name
797
- * @returns True if plugin is registered
798
- */
799
- static hasPlugin(name: string): boolean;
800
- /**
801
- * Get all registered plugins
802
- * @returns Array of registered plugin names
803
- */
804
- static listPlugins(): string[];
805
- /**
806
- * Unregister a plugin
807
- * @param name - Plugin name
808
- */
809
- static unuse(name: string): boolean;
810
- /**
811
- * Clear all plugins
812
- */
813
- static clear(): void;
814
- /**
815
- * Internal register method
816
- */
817
- private register;
818
- }
819
-
820
- /**
821
- * Register all locales into a locale map
822
- */
823
- export declare function registerAllLocales(localeMap: Map<string, ILocale> | Record<string, ILocale>): void;
824
-
825
- /**
826
- * RelativeTime Plugin Types
827
- */
828
- export declare interface RelativeTimeConfig {
829
- thresholds?: RelativeTimeThreshold[];
830
- rounding?: (value: number) => number;
831
- }
832
-
833
- export declare interface RelativeTimeFormats {
834
- future: string;
835
- past: string;
836
- s: string;
837
- m: string;
838
- mm: string;
839
- h: string;
840
- hh: string;
841
- d: string;
842
- dd: string;
843
- M: string;
844
- MM: string;
845
- y: string;
846
- yy: string;
847
- }
848
-
849
- export declare class RelativeTimePlugin implements ITimeGuardPlugin {
850
- name: string;
851
- version: string;
852
- private config;
853
- private formats;
854
- constructor(config?: RelativeTimeConfig);
855
- /**
856
- * Install plugin into TimeGuard
857
- */
858
- install(TimeGuardClass: typeof TimeGuard): void;
859
- /**
860
- * Format relative time
861
- */
862
- private formatRelativeTime;
863
- /**
864
- * Get relative time string based on milliseconds
865
- */
866
- private getRelativeTimeString;
867
- /**
868
- * Get milliseconds per unit
869
- */
870
- private getUnitMilliseconds;
871
- /**
872
- * Set format strings
873
- */
874
- setFormats(formats: Partial<RelativeTimeFormats>): void;
875
- /**
876
- * Get current formats
877
- */
878
- getFormats(): RelativeTimeFormats;
879
- }
880
-
881
- /**
882
- * Create and export default instance
883
- */
884
- export declare const relativeTimePlugin: RelativeTimePlugin;
885
-
886
- export declare interface RelativeTimeThreshold {
887
- l: string;
888
- r?: number;
889
- d?: string;
890
- }
891
-
892
- /**
893
- * Adapter for Temporal date/time operations
894
- */
895
- export declare class TemporalAdapter {
896
- /**
897
- * Parse various input formats to Temporal.PlainDateTime
898
- */
899
- static parseToPlainDateTime(input: unknown): TemporalPlainDateTime;
900
- /**
901
- * Convert JavaScript Date to Temporal.PlainDateTime
902
- */
903
- static fromDate(date: Date): TemporalPlainDateTime;
904
- /**
905
- * Convert Unix timestamp (milliseconds) to Temporal.PlainDateTime
906
- */
907
- static fromUnix(timestamp: number): TemporalPlainDateTime;
908
- /**
909
- * Parse ISO string to Temporal.PlainDateTime
910
- */
911
- static parseISOString(iso: string): TemporalPlainDateTime;
912
- /**
913
- * Create from object with date components
914
- */
915
- static fromObject(obj: Record<string, any>): TemporalPlainDateTime;
916
- /**
917
- * Convert Temporal.PlainDateTime to JavaScript Date
918
- */
919
- static toDate(temporal: TemporalPlainDateTime | TemporalZonedDateTime): Date;
920
- /**
921
- * Convert to Unix timestamp (milliseconds)
922
- */
923
- static toUnix(temporal: TemporalPlainDateTime | TemporalZonedDateTime): number;
924
- /**
925
- * Convert to ISO string
926
- */
927
- static toISOString(temporal: TemporalPlainDateTime | TemporalZonedDateTime): string;
928
- /**
929
- * Ensure we have a PlainDateTime
930
- */
931
- static toPlainDateTime(temporal: TemporalPlainDateTime | TemporalZonedDateTime): TemporalPlainDateTime;
932
- /**
933
- * Type guards
934
- */
935
- static isPlainDateTime(obj: unknown): obj is TemporalPlainDateTime;
936
- static isZonedDateTime(obj: unknown): obj is TemporalZonedDateTime;
937
- static isPlainDate(obj: unknown): obj is any;
938
- static isPlainTime(obj: unknown): obj is any;
939
- /**
940
- * Get current time as PlainDateTime
941
- */
942
- static now(): TemporalPlainDateTime;
943
- /**
944
- * Get current time as ZonedDateTime with timezone
945
- */
946
- static nowInTimezone(timezone: string): TemporalZonedDateTime;
947
- }
948
-
949
- declare type TemporalPlainDateTime = Temporal.PlainDateTime;
950
-
951
- declare type TemporalZonedDateTime = Temporal.ZonedDateTime;
952
-
953
- /**
954
- * TimeGuard implementation - Main facade class
955
- */
956
- export declare class TimeGuard implements ITimeGuard {
957
- private temporal;
958
- private config;
959
- private formatterInstance;
960
- constructor(input?: unknown, config?: ITimeGuardConfig);
961
- /**
962
- * Static factory methods
963
- */
964
- static now(config?: ITimeGuardConfig): TimeGuard;
965
- static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
966
- static fromTemporal(temporal: any, // Temporal.PlainDateTime | Temporal.ZonedDateTime
967
- config?: ITimeGuardConfig): TimeGuard;
968
- toTemporal(): any;
969
- toDate(): Date;
970
- toISOString(): string;
971
- valueOf(): number;
972
- unix(): number;
973
- toJSON(): string;
974
- toString(): string;
975
- locale(): string;
976
- locale(locale: string): TimeGuard;
977
- timezone(): string | null;
978
- timezone(timezone: string): TimeGuard;
979
- format(pattern: string | FormatPreset): string;
980
- get(component: Unit): number;
981
- add(units: Partial<Record<Unit, number>>): TimeGuard;
982
- subtract(units: Partial<Record<Unit, number>>): TimeGuard;
983
- diff(other: TimeGuard, unit?: Unit): number;
984
- isBefore(other: TimeGuard): boolean;
985
- isAfter(other: TimeGuard): boolean;
986
- isSame(other: TimeGuard, unit?: Unit): boolean;
987
- isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
988
- clone(): TimeGuard;
989
- startOf(unit: Unit): TimeGuard;
990
- endOf(unit: Unit): TimeGuard;
991
- set(values: Partial<Record<Unit, number>>): TimeGuard;
992
- year(): number;
993
- month(): number;
994
- day(): number;
995
- hour(): number;
996
- minute(): number;
997
- second(): number;
998
- millisecond(): number;
999
- dayOfWeek(): number;
1000
- dayOfYear(): number;
1001
- weekOfYear(): number;
1002
- daysInMonth(): number;
1003
- daysInYear(): number;
1004
- inLeapYear(): boolean;
1005
- /**
1006
- * Calculate duration until another TimeGuard
1007
- */
1008
- until(other: TimeGuard): {
1009
- years: number;
1010
- months: number;
1011
- days: number;
1012
- hours: number;
1013
- minutes: number;
1014
- seconds: number;
1015
- milliseconds: number;
1016
- };
1017
- /**
1018
- * Round to a specific unit with optional rounding mode
1019
- */
1020
- round(options?: IRoundOptions): TimeGuard;
1021
- /**
1022
- * Convert to PlainDate (removes time information)
1023
- */
1024
- toPlainDate(): {
1025
- year: number;
1026
- month: number;
1027
- day: number;
1028
- dayOfWeek: number;
1029
- };
1030
- /**
1031
- * Convert to PlainTime (removes date information)
1032
- */
1033
- toPlainTime(): {
1034
- hour: number;
1035
- minute: number;
1036
- second: number;
1037
- millisecond: number;
1038
- };
1039
- /**
1040
- * Create new TimeGuard with only date, keeping time from parameter
1041
- */
1042
- withDate(year: number, month: number, day: number): TimeGuard;
1043
- /**
1044
- * Create new TimeGuard with only time, keeping date
1045
- */
1046
- withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
1047
- /**
1048
- * Get timezone offset in format ±HH:mm
1049
- */
1050
- getOffset(): string;
1051
- /**
1052
- * Get timezone offset in nanoseconds
1053
- */
1054
- getOffsetNanoseconds(): number;
1055
- /**
1056
- * Get timezone ID
1057
- */
1058
- getTimeZoneId(): string | null;
1059
- /**
1060
- * Start of the day in current timezone
1061
- */
1062
- startOfDay(): TimeGuard;
1063
- /**
1064
- * End of the day in current timezone
1065
- */
1066
- endOfDay(): TimeGuard;
1067
- /**
1068
- * Calculate duration from another TimeGuard (inverse of until)
1069
- * Returns negative values if other is before this
1070
- */
1071
- since(other: TimeGuard): {
1072
- years: number;
1073
- months: number;
1074
- days: number;
1075
- hours: number;
1076
- minutes: number;
1077
- seconds: number;
1078
- milliseconds: number;
1079
- };
1080
- /**
1081
- * Get ISO 8601 duration string
1082
- * Example: P1Y2M3DT4H5M6S
1083
- */
1084
- toDurationString(other?: TimeGuard): string;
1085
- /**
1086
- * Check if this date is in the past
1087
- */
1088
- isPast(): boolean;
1089
- /**
1090
- * Check if this date is in the future
1091
- */
1092
- isFuture(): boolean;
1093
- /**
1094
- * Check if this date is today
1095
- */
1096
- isToday(): boolean;
1097
- /**
1098
- * Check if this date is tomorrow
1099
- */
1100
- isTomorrow(): boolean;
1101
- /**
1102
- * Check if this date is yesterday
1103
- */
1104
- isYesterday(): boolean;
1105
- }
1106
-
1107
- export declare function timeGuard(input?: unknown, config?: ITimeGuardConfig): TimeGuard;
1108
-
1109
- /**
1110
- * Forward declaration for TimeGuard class
1111
- * Implementation is in ./time-guard.ts, exported via ./index.ts
1112
- */
1113
- declare class TimeGuard_2 {
1114
- constructor(input?: unknown, config?: ITimeGuardConfig);
1115
- }
1116
-
1117
- /**
1118
- * TimeGuard - Core Types and Interfaces
1119
- * Following SOLID principles and TypeScript best practices
1120
- *
1121
- * Temporal types are provided natively by TypeScript (lib.esnext.temporal).
1122
- */
1123
- /**
1124
- * Unit type for date/time operations
1125
- */
1126
- export declare type Unit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond' | 'microsecond' | 'nanosecond';
1127
-
1128
- export declare const version: string;
1129
-
1130
- export { }
1
+ import { ITimeGuard, ITimeGuardConfig, Unit, FormatPreset, IRoundOptions } from './types';
2
+ type DurationParts = {
3
+ years: number;
4
+ months: number;
5
+ days: number;
6
+ hours: number;
7
+ minutes: number;
8
+ seconds: number;
9
+ milliseconds: number;
10
+ };
11
+ /**
12
+ * TimeGuard implementation - Main facade class
13
+ */
14
+ export declare class TimeGuard implements ITimeGuard {
15
+ private temporal;
16
+ private config;
17
+ private formatterInstance;
18
+ private static readonly ZERO_DURATION;
19
+ private static isLeapYearValue;
20
+ private static toDurationParts;
21
+ constructor(input?: unknown, config?: ITimeGuardConfig);
22
+ /**
23
+ * Static factory methods
24
+ */
25
+ static now(config?: ITimeGuardConfig): TimeGuard;
26
+ static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
27
+ static fromTemporal(temporal: any, // Temporal.PlainDateTime | Temporal.ZonedDateTime
28
+ config?: ITimeGuardConfig): TimeGuard;
29
+ toTemporal(): any;
30
+ toDate(): Date;
31
+ toISOString(): string;
32
+ valueOf(): number;
33
+ unix(): number;
34
+ toJSON(): string;
35
+ toString(): string;
36
+ locale(): string;
37
+ locale(locale: string): TimeGuard;
38
+ timezone(): string | null;
39
+ timezone(timezone: string): TimeGuard;
40
+ format(pattern: string | FormatPreset): string;
41
+ get(component: Unit): number;
42
+ add(units: Partial<Record<Unit, number>>): TimeGuard;
43
+ subtract(units: Partial<Record<Unit, number>>): TimeGuard;
44
+ diff(other: TimeGuard, unit?: Unit): number;
45
+ isBefore(other: TimeGuard): boolean;
46
+ isAfter(other: TimeGuard): boolean;
47
+ isSame(other: TimeGuard, unit?: Unit): boolean;
48
+ isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
49
+ clone(): TimeGuard;
50
+ startOf(unit: Unit): TimeGuard;
51
+ endOf(unit: Unit): TimeGuard;
52
+ set(values: Partial<Record<Unit, number>>): TimeGuard;
53
+ year(): number;
54
+ month(): number;
55
+ day(): number;
56
+ hour(): number;
57
+ minute(): number;
58
+ second(): number;
59
+ millisecond(): number;
60
+ dayOfWeek(): number;
61
+ dayOfYear(): number;
62
+ weekOfYear(): number;
63
+ daysInMonth(): number;
64
+ daysInYear(): number;
65
+ inLeapYear(): boolean;
66
+ /**
67
+ * Calculate duration until another TimeGuard
68
+ */
69
+ until(other: TimeGuard): DurationParts;
70
+ /**
71
+ * Round to a specific unit with optional rounding mode
72
+ */
73
+ round(options?: IRoundOptions): TimeGuard;
74
+ /**
75
+ * Convert to PlainDate (removes time information)
76
+ */
77
+ toPlainDate(): {
78
+ year: number;
79
+ month: number;
80
+ day: number;
81
+ dayOfWeek: number;
82
+ };
83
+ /**
84
+ * Convert to PlainTime (removes date information)
85
+ */
86
+ toPlainTime(): {
87
+ hour: number;
88
+ minute: number;
89
+ second: number;
90
+ millisecond: number;
91
+ };
92
+ /**
93
+ * Create new TimeGuard with only date, keeping time from parameter
94
+ */
95
+ withDate(year: number, month: number, day: number): TimeGuard;
96
+ /**
97
+ * Create new TimeGuard with only time, keeping date
98
+ */
99
+ withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
100
+ /**
101
+ * Get timezone offset in format ±HH:mm
102
+ */
103
+ getOffset(): string;
104
+ /**
105
+ * Get timezone offset in nanoseconds
106
+ */
107
+ getOffsetNanoseconds(): number;
108
+ /**
109
+ * Get timezone ID
110
+ */
111
+ getTimeZoneId(): string | null;
112
+ /**
113
+ * Start of the day in current timezone
114
+ */
115
+ startOfDay(): TimeGuard;
116
+ /**
117
+ * End of the day in current timezone
118
+ */
119
+ endOfDay(): TimeGuard;
120
+ /**
121
+ * Calculate duration from another TimeGuard (inverse of until)
122
+ * Returns negative values if other is before this
123
+ */
124
+ since(other: TimeGuard): DurationParts;
125
+ /**
126
+ * Get ISO 8601 duration string
127
+ * Example: P1Y2M3DT4H5M6S
128
+ */
129
+ toDurationString(other?: TimeGuard): string;
130
+ /**
131
+ * Check if this date is in the past
132
+ */
133
+ isPast(): boolean;
134
+ /**
135
+ * Check if this date is in the future
136
+ */
137
+ isFuture(): boolean;
138
+ /**
139
+ * Check if this date is today
140
+ */
141
+ isToday(): boolean;
142
+ /**
143
+ * Check if this date is tomorrow
144
+ */
145
+ isTomorrow(): boolean;
146
+ /**
147
+ * Check if this date is yesterday
148
+ */
149
+ isYesterday(): boolean;
150
+ }
151
+ export {};