@bereasoftware/time-guard 1.0.1

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