@bereasoftware/time-guard 2.6.1 → 2.7.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.
Files changed (98) hide show
  1. package/README.en.md +232 -0
  2. package/README.md +259 -4
  3. package/dist/angular/index.cjs +148 -0
  4. package/dist/angular/index.d.ts +2 -0
  5. package/dist/angular/index.es.js +143 -0
  6. package/dist/angular.d.ts +59 -0
  7. package/dist/calendars/index.cjs +357 -2
  8. package/dist/calendars/index.es.js +99 -68
  9. package/dist/chunk-BbtWAPZS.cjs +36 -0
  10. package/dist/core-BFdo248T.cjs +1892 -0
  11. package/dist/core-CyBR5PPd.js +1809 -0
  12. package/dist/core.d.ts +224 -0
  13. package/dist/index.d.ts +9 -0
  14. package/dist/locales/african.locale.d.ts +7 -0
  15. package/dist/locales/index.cjs +7 -1
  16. package/dist/{types/locales → locales}/index.d.ts +2 -2
  17. package/dist/locales/index.es.js +3 -3
  18. package/dist/locales/south-american.locale.d.ts +7 -0
  19. package/dist/locales-B1mDDyn_.cjs +3537 -0
  20. package/dist/{locales-DSBvgSaw.js → locales-By7IK3Ep.js} +749 -33
  21. package/dist/native/index.cjs +48 -0
  22. package/dist/native/index.d.ts +2 -0
  23. package/dist/native/index.es.js +18 -0
  24. package/dist/native.d.ts +9 -0
  25. package/dist/plugins/advanced-format.cjs +105 -2
  26. package/dist/plugins/advanced-format.es.js +63 -45
  27. package/dist/plugins/duration.cjs +258 -2
  28. package/dist/plugins/duration.es.js +165 -61
  29. package/dist/plugins/relative-time.cjs +166 -2
  30. package/dist/plugins/relative-time.es.js +74 -37
  31. package/dist/qwik/index.cjs +104 -0
  32. package/dist/qwik/index.d.ts +2 -0
  33. package/dist/qwik/index.es.js +100 -0
  34. package/dist/qwik.d.ts +32 -0
  35. package/dist/react/index.cjs +112 -0
  36. package/dist/react/index.d.ts +2 -0
  37. package/dist/react/index.es.js +103 -0
  38. package/dist/react.d.ts +46 -0
  39. package/dist/solid/index.cjs +127 -0
  40. package/dist/solid/index.d.ts +2 -0
  41. package/dist/solid/index.es.js +122 -0
  42. package/dist/solid.d.ts +53 -0
  43. package/dist/svelte/index.cjs +398 -0
  44. package/dist/svelte/index.d.ts +2 -0
  45. package/dist/svelte/index.es.js +393 -0
  46. package/dist/svelte.d.ts +88 -0
  47. package/dist/time-guard.cjs +7359 -4
  48. package/dist/time-guard.es.js +3625 -8085
  49. package/dist/time-guard.iife.js +13549 -4
  50. package/dist/time-guard.umd.js +13550 -4
  51. package/dist/types/index.d.ts +651 -127
  52. package/dist/vue/index.cjs +143 -0
  53. package/dist/vue/index.d.ts +2 -0
  54. package/dist/vue/index.es.js +137 -0
  55. package/dist/vue.d.ts +35 -0
  56. package/package.json +107 -27
  57. package/dist/calendars/index.cjs.map +0 -1
  58. package/dist/calendars/index.es.js.map +0 -1
  59. package/dist/locales-DSBvgSaw.js.map +0 -1
  60. package/dist/locales-ybx7jS8G.cjs +0 -2
  61. package/dist/locales-ybx7jS8G.cjs.map +0 -1
  62. package/dist/plugins/advanced-format.cjs.map +0 -1
  63. package/dist/plugins/advanced-format.es.js.map +0 -1
  64. package/dist/plugins/duration.cjs.map +0 -1
  65. package/dist/plugins/duration.es.js.map +0 -1
  66. package/dist/plugins/relative-time.cjs.map +0 -1
  67. package/dist/plugins/relative-time.es.js.map +0 -1
  68. package/dist/time-guard.cjs.map +0 -1
  69. package/dist/time-guard.es.js.map +0 -1
  70. package/dist/time-guard.iife.js.map +0 -1
  71. package/dist/time-guard.umd.js.map +0 -1
  72. package/dist/types/types/index.d.ts +0 -641
  73. /package/dist/{types/adapters → adapters}/temporal.adapter.d.ts +0 -0
  74. /package/dist/{types/calendars → calendars}/calendar.manager.d.ts +0 -0
  75. /package/dist/{types/calendars → calendars}/index.d.ts +0 -0
  76. /package/dist/{types/formatters → formatters}/date.formatter.d.ts +0 -0
  77. /package/dist/{types/locales → locales}/additional.locale.d.ts +0 -0
  78. /package/dist/{types/locales → locales}/asian.locale.d.ts +0 -0
  79. /package/dist/{types/locales → locales}/english.locale.d.ts +0 -0
  80. /package/dist/{types/locales → locales}/european.locale.d.ts +0 -0
  81. /package/dist/{types/locales → locales}/locale.manager.d.ts +0 -0
  82. /package/dist/{types/locales → locales}/middle-eastern.locale.d.ts +0 -0
  83. /package/dist/{types/locales → locales}/nordic.locale.d.ts +0 -0
  84. /package/dist/{types/locales → locales}/romance.locale.d.ts +0 -0
  85. /package/dist/{types/locales → locales}/slavic.locale.d.ts +0 -0
  86. /package/dist/{types/locales → locales}/spanish.locale.d.ts +0 -0
  87. /package/dist/{types/plugins → plugins}/advanced-format/index.d.ts +0 -0
  88. /package/dist/{types/plugins → plugins}/advanced-format.d.ts +0 -0
  89. /package/dist/{types/plugins → plugins}/duration/index.d.ts +0 -0
  90. /package/dist/{types/plugins → plugins}/duration/types.d.ts +0 -0
  91. /package/dist/{types/plugins → plugins}/duration.d.ts +0 -0
  92. /package/dist/{types/plugins → plugins}/index.d.ts +0 -0
  93. /package/dist/{types/plugins → plugins}/manager.d.ts +0 -0
  94. /package/dist/{types/plugins → plugins}/relative-time/index.d.ts +0 -0
  95. /package/dist/{types/plugins → plugins}/relative-time/types.d.ts +0 -0
  96. /package/dist/{types/plugins → plugins}/relative-time.d.ts +0 -0
  97. /package/dist/{types/time-guard.d.ts → time-guard.d.ts} +0 -0
  98. /package/dist/{types/utils → utils}/duration-locale.d.ts +0 -0
@@ -1,33 +1,152 @@
1
- import { ITimeGuard, ITimeGuardConfig, Unit, FormatPreset, IRoundOptions, IDurationOptions, DurationParts, IDiffResult, IDiffOptions, IDurationExplanation, IFormattableDuration, TemporalPlainDateTime, TemporalZonedDateTime } from './types';
2
- import { LocaleManager, EN_LOCALE, ES_LOCALE } from './locales/locale.manager';
1
+ import { Temporal } from '@js-temporal/polyfill';
2
+ export type TemporalPlainDateTime = Temporal.PlainDateTime;
3
+ export type TemporalZonedDateTime = Temporal.ZonedDateTime;
4
+ export type TemporalPlainDate = Temporal.PlainDate;
5
+ export type TemporalPlainTime = Temporal.PlainTime;
6
+ export type TemporalDuration = Temporal.Duration;
7
+ export interface TemporalPlainDateTimeExtended extends TemporalPlainDateTime {
8
+ dayOfWeek: number;
9
+ dayOfYear: number;
10
+ weekOfYear: number;
11
+ yearOfWeek: number;
12
+ microsecond: number;
13
+ nanosecond: number;
14
+ add<T extends TemporalPlainDateTime>(duration: TemporalDuration | Record<string, unknown>): T;
15
+ subtract<T extends TemporalPlainDateTime>(duration: TemporalDuration | Record<string, unknown>): T;
16
+ with<T extends TemporalPlainDateTime>(fields: Record<string, unknown>): T;
17
+ }
18
+ export interface TemporalZonedDateTimeExtended extends TemporalZonedDateTime {
19
+ offset: string;
20
+ offsetNanoseconds: number;
21
+ timeZoneId: string;
22
+ }
23
+ export interface TemporalDurationExtended extends TemporalDuration {
24
+ abs<T extends TemporalDuration>(this: T): T;
25
+ }
26
+ export interface TemporalDurationLike {
27
+ years?: number;
28
+ months?: number;
29
+ weeks?: number;
30
+ days?: number;
31
+ hours?: number;
32
+ minutes?: number;
33
+ seconds?: number;
34
+ milliseconds?: number;
35
+ microseconds?: number;
36
+ nanoseconds?: number;
37
+ }
38
+ export type DurationLike = TemporalDuration | TemporalDurationLike | Record<string, unknown>;
39
+ export interface TemporalPlainDateTimePolyfill extends TemporalPlainDateTime {
40
+ toZonedDateTime(timeZone: string): TemporalZonedDateTime;
41
+ dayOfWeek: number;
42
+ dayOfYear: number;
43
+ weekOfYear: number;
44
+ yearOfWeek: number;
45
+ add(duration: DurationLike): TemporalPlainDateTimePolyfill;
46
+ subtract(duration: DurationLike): TemporalPlainDateTimePolyfill;
47
+ with(fields: Record<string, unknown>): TemporalPlainDateTimePolyfill;
48
+ since(other: TemporalPlainDateTime, options?: Record<string, unknown>): TemporalDuration;
49
+ }
50
+ export interface TemporalZonedDateTimePolyfill extends TemporalZonedDateTime {
51
+ offset: string;
52
+ offsetNanoseconds: number;
53
+ timeZoneId: string;
54
+ toPlainDateTime(): TemporalPlainDateTime;
55
+ }
56
+ export interface TemporalLike {
57
+ toPlainDateTime(): TemporalPlainDateTime;
58
+ toPlainDate?(): TemporalPlainDate;
59
+ toPlainTime?(): TemporalPlainTime;
60
+ }
61
+ export type DateInput = TemporalPlainDateTime | TemporalZonedDateTime | TemporalPlainDate | TemporalPlainTime | Date | string | number | Record<string, unknown>;
62
+ /**
63
+ * Unit type for date/time operations
64
+ */
65
+ export type Unit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond' | 'microsecond' | 'nanosecond';
66
+ /**
67
+ * Format preset strings for common patterns
68
+ */
69
+ export type FormatPreset = 'iso' | 'date' | 'time' | 'datetime' | 'rfc2822' | 'rfc3339' | 'utc';
70
+ /**
71
+ * Duration-like object for arithmetic operations
72
+ */
73
+ export interface IDuration {
74
+ years?: number;
75
+ months?: number;
76
+ weeks?: number;
77
+ days?: number;
78
+ hours?: number;
79
+ minutes?: number;
80
+ seconds?: number;
81
+ milliseconds?: number;
82
+ microseconds?: number;
83
+ nanoseconds?: number;
84
+ }
85
+ /**
86
+ * Round options for precision control
87
+ */
88
+ export interface IRoundOptions {
89
+ smallestUnit?: Unit;
90
+ roundingMode?: 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfExpand' | 'halfFloor' | 'halfCeil' | 'halfTrunc';
91
+ roundingIncrement?: number;
92
+ }
93
+ /**
94
+ * Duration options for normalizing time differences
95
+ */
96
+ export interface IDurationOptions {
97
+ largestUnit?: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
98
+ smallestUnit?: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
99
+ }
3
100
  /**
4
101
  * Diff result object that allows chaining with .as()
5
- *
6
- * Supports two modes:
7
- * - 'exact': Returns precise time differences
8
- * - 'calendar': Returns calendar-aware breakdown
9
- */
10
- declare class DiffResult implements IDiffResult, IFormattableDuration {
11
- private _value;
12
- private _tg1;
13
- private _tg2;
14
- private _mode;
15
- private _breakdownData;
16
- private _locale;
17
- constructor(value: number, tg1: TimeGuard, tg2: TimeGuard, mode?: 'calendar' | 'exact', breakdownData?: DurationParts, locale?: string);
102
+ * Example: tg1.diff(tg2).as('month')
103
+ */
104
+ export interface IDiffResult {
18
105
  as(unit: Unit): number;
106
+ /**
107
+ * Get breakdown in calendar mode (e.g., "2 months 5 days")
108
+ * Only available when mode is 'calendar'
109
+ */
19
110
  breakdown(): DurationParts | null;
111
+ /**
112
+ * Format the difference as a human-readable string
113
+ * @param locale Locale code (e.g., 'en', 'es', 'fr')
114
+ * @example
115
+ * diff.format('en') // "2 months and 5 days"
116
+ * diff.format('es') // "2 meses y 5 días"
117
+ */
20
118
  format(locale?: string): string;
119
+ /**
120
+ * Get the mode used for this diff calculation
121
+ */
21
122
  getMode(): 'calendar' | 'exact';
22
- valueOf(): number;
23
- toString(): string;
24
- toJSON(): number;
25
123
  }
26
124
  /**
27
- * DurationResult class - Represents a duration breakdown with humanize support
28
- * Returned by until(), since(), and between() methods
125
+ * Options for diff() method
29
126
  */
30
- export declare class DurationResult implements DurationParts, IFormattableDuration {
127
+ export interface IDiffOptions {
128
+ /**
129
+ * Calculation mode:
130
+ * - 'calendar': Returns months/days breakdown (e.g., 65 days → 2 months 5 days)
131
+ * - 'exact': Returns exact time units (e.g., 65 days)
132
+ * @default 'exact'
133
+ */
134
+ mode?: 'calendar' | 'exact';
135
+ /**
136
+ * Unit for diff when using 'exact' mode
137
+ * @default 'millisecond'
138
+ */
139
+ unit?: Unit;
140
+ /**
141
+ * Locale for formatting output text
142
+ * @default from TimeGuard instance config
143
+ */
144
+ locale?: string;
145
+ }
146
+ /**
147
+ * Duration parts breakdown
148
+ */
149
+ export interface DurationParts {
31
150
  years: number;
32
151
  months: number;
33
152
  weeks: number;
@@ -36,110 +155,272 @@ export declare class DurationResult implements DurationParts, IFormattableDurati
36
155
  minutes: number;
37
156
  seconds: number;
38
157
  milliseconds: number;
39
- private _locale;
40
- private _startDate?;
41
- private _endDate?;
42
- private _steps;
43
- private _mode;
44
- private _leapYearFlags;
45
- private _calculationTimeMs;
46
- constructor(parts: DurationParts, locale?: string, metadata?: {
47
- startDate?: string;
48
- endDate?: string;
49
- steps?: string[];
50
- mode?: 'exact' | 'estimated';
51
- leapYearFlags?: Array<{
52
- year: number;
53
- isLeap: boolean;
54
- daysInFebruary: number;
55
- }>;
56
- calculationTimeMs?: number;
57
- });
58
- humanize(options?: {
59
- locale?: string;
60
- fullBreakdown?: boolean;
61
- numeric?: 'always' | 'auto';
62
- }): string;
63
- total(unit: Unit): number;
158
+ }
159
+ /**
160
+ * Base interface for formattable duration-like objects
161
+ * Common functionality shared by DiffResult and DurationResult
162
+ */
163
+ export interface IFormattableDuration {
64
164
  toString(): string;
65
- toJSON(): Record<string, number>;
66
- explain(): IDurationExplanation;
67
- private generateExplanationSteps;
68
- private pluralizeUnit;
165
+ toJSON(): Record<string, number> | number;
69
166
  }
70
167
  /**
71
- * TimeRange - Fluent API for date range operations
72
- *
73
- * @example
74
- * TimeGuard.range('2024-01-15', '2024-03-20')
75
- * .toDuration().humanize() // "2 months and 5 days"
76
- * .inMonths() // 2.1355 (precise decimal)
168
+ * Options for humanize() method
77
169
  */
78
- export declare class TimeRange {
79
- private _start;
80
- private _end;
81
- constructor(start: TimeGuard, end: TimeGuard);
82
- toDuration(): DurationResult;
83
- inMonths(): number;
84
- humanize(options?: {
85
- locale?: string;
86
- fullBreakdown?: boolean;
87
- numeric?: 'always' | 'auto';
88
- }): string;
89
- in(unit: Unit): number;
170
+ export interface IHumanizeOptions {
171
+ /**
172
+ * Locale code (e.g., 'en', 'es', 'fr')
173
+ * @default from TimeGuard instance config
174
+ */
175
+ locale?: string;
176
+ /**
177
+ * Show full breakdown (e.g., "2 months and 5 days")
178
+ * or just largest unit (e.g., "2 months")
179
+ * @default false (largest unit only with Intl.RelativeTimeFormat style)
180
+ */
181
+ fullBreakdown?: boolean;
182
+ /**
183
+ * Numeric format: 'always', 'auto'
184
+ * @default 'always'
185
+ */
186
+ numeric?: 'always' | 'auto';
90
187
  }
91
188
  /**
92
- * TimeGuard implementation - Main facade class
189
+ * Duration result with humanize and total methods
190
+ * Returned by until(), since(), and between()
191
+ * Rich object for business logic: payments, metrics, analytics
93
192
  */
94
- export declare class TimeGuard implements ITimeGuard {
95
- private temporal;
96
- private config;
97
- private formatterInstance;
98
- private static readonly ZERO_DURATION;
99
- private static isLeapYearValue;
100
- private static toDurationParts;
101
- constructor(input?: unknown, config?: ITimeGuardConfig);
102
- static now(config?: ITimeGuardConfig): TimeGuard;
103
- static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
104
- static fromTemporal(temporal: TemporalPlainDateTime | TemporalZonedDateTime, config?: ITimeGuardConfig): TimeGuard;
193
+ export interface IDurationResult extends DurationParts {
105
194
  /**
106
- * Calculate duration between two dates - always returns positive duration
107
- *
195
+ * Convert duration to human-readable string
108
196
  * @example
109
- * TimeGuard.between(start, end).humanize() // "2 months and 5 days"
110
- * TimeGuard.between(end, start).humanize() // "2 months and 5 days" (still positive)
197
+ * duration.humanize() // "2 months"
198
+ * duration.humanize({ fullBreakdown: true, locale: 'es' }) // "2 meses y 5 días"
111
199
  */
112
- static between(date1: TimeGuard, date2: TimeGuard): DurationResult;
200
+ humanize(options?: IHumanizeOptions): string;
113
201
  /**
114
- * Create a TimeRange for fluent duration calculations
202
+ * Get total duration in specified unit (date-fns style)
203
+ * Perfect for business metrics: payments, analytics, calculations
204
+ *
205
+ * Conversion factors account for:
206
+ * - Leap years (1 year = 365.25 days)
207
+ * - Average month length (1 month = 30.4375 days)
115
208
  *
116
209
  * @example
117
- * TimeGuard.range("2024-01-15", "2024-03-20").humanize() // "2 months and 5 days"
210
+ * duration.total('days') // 65
211
+ * duration.total('months') // 2.166... (65 / 30.4375)
212
+ * duration.total('hours') // 1560
213
+ * duration.total('seconds') // 5616000
214
+ *
215
+ * Use cases:
216
+ * - Billing calculations: `duration.total('days') * dailyRate`
217
+ * - Performance metrics: `duration.total('milliseconds')`
218
+ * - Report generation: `duration.total('months')`
219
+ */
220
+ total(unit: Unit): number;
221
+ /**
222
+ * String representation
223
+ * Returns humanized format for display
118
224
  */
119
- static range(start: unknown, end: unknown): TimeRange;
120
- toTemporal(): TemporalPlainDateTime | TemporalZonedDateTime;
121
- toDate(): Date;
122
- toISOString(): string;
123
- valueOf(): number;
124
- unix(): number;
125
- toJSON(): string;
126
- [Symbol.toPrimitive](hint: 'default' | 'string' | 'number'): string | number;
127
225
  toString(): string;
128
- locale(): string;
129
- locale(locale: string): TimeGuard;
130
- timezone(): string | null;
131
- timezone(timezone: string): TimeGuard;
132
- format(pattern: string | FormatPreset): string;
133
- get(component: Unit): number;
134
- add(units: Partial<Record<Unit, number>>): TimeGuard;
135
- subtract(units: Partial<Record<Unit, number>>): TimeGuard;
136
- diff(other: TimeGuard): DiffResult;
226
+ /**
227
+ * JSON representation
228
+ * Returns breakdown as object for API responses
229
+ */
230
+ toJSON(): Record<string, number>;
231
+ /**
232
+ * Explain the calculation - killer feature for debugging and education
233
+ * Returns detailed breakdown of how the duration was calculated
234
+ *
235
+ * Perfect for:
236
+ * - Debugging complex date calculations
237
+ * - Educational purposes (showing date math)
238
+ * - Auditing time-based business logic
239
+ *
240
+ * @example
241
+ * duration.explain()
242
+ * // {
243
+ * // input: ['2024-01-15', '2024-03-20'],
244
+ * // steps: ['...step 1...', '...step 2...'],
245
+ * // breakdown: { years: 0, months: 2, days: 5, ... },
246
+ * // mode: 'exact',
247
+ * // explanation: '...'
248
+ * // }
249
+ */
250
+ explain(): IDurationExplanation;
251
+ }
252
+ /**
253
+ * Duration explanation object for debugging and education
254
+ * Provides transparent insight into calculation methodology
255
+ * Perfect for: debugging, auditing, educational purposes
256
+ *
257
+ * @example
258
+ * duration.explain()
259
+ * // {
260
+ * // input: ['2024-01-15', '2024-03-20'],
261
+ * // steps: [
262
+ * // 'Parsed dates: 2024-01-15 (day 15 of 365) to 2024-03-20 (day 80 of 365)',
263
+ * // '2024 is a leap year (366 days)',
264
+ * // 'February 2024 has 29 days',
265
+ * // 'Month 1: 31 - 15 = 16 days remaining',
266
+ * // 'Month 2: 29 days (full leap month)',
267
+ * // 'Month 3: 1 - 20 = 20 days',
268
+ * // 'Total: 16 + 29 + 20 = 65 days'
269
+ * // ],
270
+ * // breakdown: { years: 0, months: 2, weeks: 0, days: 5, ... },
271
+ * // mode: 'exact',
272
+ * // explanation: 'Calculated 2024-01-15 to 2024-03-20 including leap year adjustment'
273
+ * // }
274
+ */
275
+ export interface IDurationExplanation {
276
+ /**
277
+ * Input dates as array of strings or formatted representations
278
+ */
279
+ input: string[];
280
+ /**
281
+ * Step-by-step calculation explanation
282
+ * Each step is human-readable and educational
283
+ * Useful for debugging complex date calculations
284
+ */
285
+ steps: string[];
286
+ /**
287
+ * Duration breakdown by component
288
+ * Same as the DurationResult properties
289
+ */
290
+ breakdown: DurationParts;
291
+ /**
292
+ * Calculation mode
293
+ * - 'exact': Uses Temporal API precise calculations
294
+ * - 'estimated': Fallback for edge cases
295
+ */
296
+ mode: 'exact' | 'estimated';
297
+ /**
298
+ * Human-readable explanation of the entire calculation
299
+ * Summarizes the approach and any special handling
300
+ */
301
+ explanation: string;
302
+ /**
303
+ * Locale used for explanation text
304
+ * Supports internationalization of step descriptions
305
+ */
306
+ locale: string;
307
+ /**
308
+ * Leap year flags if applicable
309
+ * Documents which years were leap years in the calculation
310
+ */
311
+ leapYearFlags?: {
312
+ year: number;
313
+ isLeap: boolean;
314
+ daysInFebruary: number;
315
+ }[];
316
+ /**
317
+ * Performance metadata
318
+ * For monitoring calculation complexity
319
+ */
320
+ metadata?: {
321
+ calculationTimeMs: number;
322
+ precision: 'nanosecond' | 'microsecond' | 'millisecond' | 'second' | 'day';
323
+ };
324
+ }
325
+ /**
326
+ * Calendar system interface
327
+ */
328
+ export interface ICalendarSystem {
329
+ id: string;
330
+ name: string;
331
+ locale?: string;
332
+ getMonthName(month: number, short?: boolean): string;
333
+ getWeekdayName(day: number, short?: boolean): string;
334
+ isLeapYear(year: number): boolean;
335
+ daysInMonth(year: number, month: number): number;
336
+ daysInYear(year: number): number;
337
+ }
338
+ /**
339
+ * Calendar manager interface
340
+ */
341
+ export interface ICalendarManager {
342
+ register(calendar: ICalendarSystem): void;
343
+ get(id: string): ICalendarSystem | undefined;
344
+ list(): string[];
345
+ setDefault(id: string): void;
346
+ getDefault(): ICalendarSystem;
347
+ }
348
+ /**
349
+ * Locale configuration interface
350
+ */
351
+ export interface ILocale {
352
+ name: string;
353
+ months: string[];
354
+ monthsShort: string[];
355
+ weekdays: string[];
356
+ weekdaysShort: string[];
357
+ weekdaysMin: string[];
358
+ meridiem?: {
359
+ am: string;
360
+ pm: string;
361
+ };
362
+ formats?: Record<string, string>;
363
+ }
364
+ /**
365
+ * Configuration options for TimeGuard instance
366
+ */
367
+ export interface ITimeGuardConfig {
368
+ locale?: string;
369
+ timezone?: string;
370
+ strict?: boolean;
371
+ }
372
+ /**
373
+ * Interface for date/time parsing strategy (Strategy Pattern)
374
+ */
375
+ export interface IDateParser {
376
+ parse(input: unknown): TemporalPlainDateTime | null;
377
+ canHandle(input: unknown): boolean;
378
+ }
379
+ /**
380
+ * Interface for date/time formatting (Strategy Pattern)
381
+ */
382
+ export interface IDateFormatter {
383
+ format(date: TemporalPlainDateTime | TemporalZonedDateTime, pattern: string): string;
384
+ getPreset(preset: FormatPreset): string;
385
+ }
386
+ /**
387
+ * Interface for locale management (Single Responsibility)
388
+ */
389
+ export interface ILocaleManager {
390
+ setLocale(locale: string, data?: ILocale): void;
391
+ getLocale(locale?: string): ILocale;
392
+ listLocales(): string[];
393
+ }
394
+ /**
395
+ * Interface for arithmetic operations
396
+ */
397
+ export interface IDateArithmetic {
398
+ add(units: Partial<Record<Unit, number>> | IDuration): TimeGuard;
399
+ subtract(units: Partial<Record<Unit, number>> | IDuration): TimeGuard;
400
+ diff(other: TimeGuard): IDiffResult;
137
401
  diff(other: TimeGuard, unit: Unit): number;
138
- diff(other: TimeGuard, options: IDiffOptions): DiffResult;
402
+ until(other: TimeGuard, options?: IDurationOptions): IDurationResult;
403
+ since(other: TimeGuard, options?: IDurationOptions): IDurationResult;
404
+ round(options: IRoundOptions): TimeGuard;
405
+ addBusinessDays(days: number): TimeGuard;
406
+ subtractBusinessDays(days: number): TimeGuard;
407
+ }
408
+ /**
409
+ * Interface for query operations
410
+ */
411
+ export interface IDateQuery {
139
412
  isBefore(other: TimeGuard): boolean;
140
413
  isAfter(other: TimeGuard): boolean;
141
414
  isSame(other: TimeGuard, unit?: Unit): boolean;
142
415
  isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
416
+ isWeekend(): boolean;
417
+ isHoliday(): boolean;
418
+ isBusinessDay(): boolean;
419
+ }
420
+ /**
421
+ * Interface for manipulation operations
422
+ */
423
+ export interface IDateManipulation {
143
424
  clone(): TimeGuard;
144
425
  startOf(unit: Unit): TimeGuard;
145
426
  endOf(unit: Unit): TimeGuard;
@@ -157,9 +438,181 @@ export declare class TimeGuard implements ITimeGuard {
157
438
  daysInMonth(): number;
158
439
  daysInYear(): number;
159
440
  inLeapYear(): boolean;
160
- until(other: TimeGuard, options?: IDurationOptions): DurationResult;
161
- private generateUntilSteps;
162
- round(options?: IRoundOptions): TimeGuard;
441
+ }
442
+ /**
443
+ * Interface for timezone operations
444
+ */
445
+ export interface ITimezoneAdapter {
446
+ toTimezone(date: TemporalPlainDateTime, timezone: string): TemporalZonedDateTime;
447
+ fromTimezone(date: TemporalZonedDateTime, targetTimezone: string): TemporalPlainDateTime;
448
+ getOffset(timezone: string): number;
449
+ }
450
+ /**
451
+ * Main TimeGuard interface (Facade Pattern)
452
+ */
453
+ export interface ITimeGuard extends IDateArithmetic, IDateQuery, IDateManipulation {
454
+ /**
455
+ * Get the underlying Temporal date object
456
+ */
457
+ toTemporal(): TemporalPlainDateTime | TemporalZonedDateTime;
458
+ /**
459
+ * Get as JavaScript Date (compatibility)
460
+ */
461
+ toDate(): Date;
462
+ /**
463
+ * Get as ISO string
464
+ */
465
+ toISOString(): string;
466
+ /**
467
+ * Get as Unix timestamp (milliseconds)
468
+ */
469
+ valueOf(): number;
470
+ /**
471
+ * Format the date with pattern or preset
472
+ */
473
+ format(pattern: string | FormatPreset): string;
474
+ /**
475
+ * Get accessor for components
476
+ */
477
+ get(component: Unit): number;
478
+ /**
479
+ * Locale of this instance
480
+ */
481
+ locale(): string;
482
+ /**
483
+ * Clone with new locale
484
+ */
485
+ locale(locale: string): TimeGuard;
486
+ /**
487
+ * Timezone info
488
+ */
489
+ timezone(): string | null;
490
+ /**
491
+ * Convert to another timezone
492
+ */
493
+ timezone(timezone: string): TimeGuard;
494
+ /**
495
+ * Get Unix timestamp in seconds
496
+ */
497
+ unix(): number;
498
+ /**
499
+ * Convert to JSON
500
+ */
501
+ toJSON(): string;
502
+ /**
503
+ * String representation
504
+ */
505
+ toString(): string;
506
+ /**
507
+ * Convert to PlainDate object
508
+ */
509
+ toPlainDate(): {
510
+ year: number;
511
+ month: number;
512
+ day: number;
513
+ dayOfWeek: number;
514
+ };
515
+ /**
516
+ * Convert to PlainTime object
517
+ */
518
+ toPlainTime(): {
519
+ hour: number;
520
+ minute: number;
521
+ second: number;
522
+ millisecond: number;
523
+ };
524
+ /**
525
+ * Get timezone offset (±HH:mm format or Z)
526
+ */
527
+ getOffset(): string;
528
+ /**
529
+ * Get timezone offset in nanoseconds
530
+ */
531
+ getOffsetNanoseconds(): number;
532
+ /**
533
+ * Get timezone ID
534
+ */
535
+ getTimeZoneId(): string | null;
536
+ /**
537
+ * Start of day
538
+ */
539
+ startOfDay(): TimeGuard;
540
+ /**
541
+ * End of day
542
+ */
543
+ endOfDay(): TimeGuard;
544
+ /**
545
+ * Duration from another date (inverse of until)
546
+ */
547
+ since(other: TimeGuard, options?: IDurationOptions): IDurationResult;
548
+ /**
549
+ * ISO 8601 duration string (P1Y2M3DT4H5M6S)
550
+ */
551
+ toDurationString(other?: TimeGuard): string;
552
+ /**
553
+ * Check if in past
554
+ */
555
+ isPast(): boolean;
556
+ /**
557
+ * Check if in future
558
+ */
559
+ isFuture(): boolean;
560
+ /**
561
+ * Check if today
562
+ */
563
+ isToday(): boolean;
564
+ /**
565
+ * Check if tomorrow
566
+ */
567
+ isTomorrow(): boolean;
568
+ /**
569
+ * Check if yesterday
570
+ */
571
+ isYesterday(): boolean;
572
+ }
573
+ /**
574
+ * Plugin interface for extending functionality
575
+ */
576
+ export interface ITimeGuardPlugin {
577
+ name: string;
578
+ version: string;
579
+ install(timeGuard: typeof TimeGuard, config?: unknown): void;
580
+ }
581
+ /**
582
+ * Factory interface
583
+ */
584
+ export interface ITimeGuardFactory {
585
+ create(input?: unknown, config?: ITimeGuardConfig): ITimeGuard;
586
+ now(config?: ITimeGuardConfig): ITimeGuard;
587
+ fromTemporal(date: TemporalPlainDateTime | TemporalZonedDateTime, config?: ITimeGuardConfig): ITimeGuard;
588
+ }
589
+ /**
590
+ * Forward declaration for TimeGuard class
591
+ * Implementation is in ./index.ts, exported via ./index.ts
592
+ */
593
+ export declare class TimeGuard implements ITimeGuard {
594
+ constructor(input?: unknown, config?: ITimeGuardConfig);
595
+ static now(config?: ITimeGuardConfig): TimeGuard;
596
+ static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
597
+ static fromTemporal(temporal: TemporalPlainDateTime | TemporalZonedDateTime, config?: ITimeGuardConfig): TimeGuard;
598
+ static between(date1: TimeGuard, date2: TimeGuard): DurationResult;
599
+ static range(start: unknown, end: unknown): TimeRange;
600
+ static registerHolidays(dates: string[]): void;
601
+ static clearHolidays(): void;
602
+ static getRegisteredHolidays(): string[];
603
+ toTemporal(): TemporalPlainDateTime | TemporalZonedDateTime;
604
+ toDate(): Date;
605
+ toISOString(): string;
606
+ valueOf(): number;
607
+ format(pattern: string | FormatPreset): string;
608
+ get(component: Unit): number;
609
+ locale(): string;
610
+ locale(locale: string): TimeGuard;
611
+ timezone(): string | null;
612
+ timezone(timezone: string): TimeGuard;
613
+ unix(): number;
614
+ toJSON(): string;
615
+ toString(): string;
163
616
  toPlainDate(): {
164
617
  year: number;
165
618
  month: number;
@@ -172,34 +625,105 @@ export declare class TimeGuard implements ITimeGuard {
172
625
  second: number;
173
626
  millisecond: number;
174
627
  };
175
- withDate(year: number, month: number, day: number): TimeGuard;
176
- withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
177
628
  getOffset(): string;
178
629
  getOffsetNanoseconds(): number;
179
630
  getTimeZoneId(): string | null;
180
631
  startOfDay(): TimeGuard;
181
632
  endOfDay(): TimeGuard;
182
- since(other: TimeGuard, options?: IDurationOptions): DurationResult;
633
+ since(other: TimeGuard, options?: IDurationOptions): IDurationResult;
183
634
  toDurationString(other?: TimeGuard): string;
184
635
  isPast(): boolean;
185
636
  isFuture(): boolean;
186
637
  isToday(): boolean;
187
638
  isTomorrow(): boolean;
188
639
  isYesterday(): boolean;
640
+ add(units: Partial<Record<Unit, number>> | IDuration): TimeGuard;
641
+ subtract(units: Partial<Record<Unit, number>> | IDuration): TimeGuard;
642
+ diff(other: TimeGuard): IDiffResult;
643
+ diff(other: TimeGuard, unit: Unit): number;
644
+ until(other: TimeGuard, options?: IDurationOptions): IDurationResult;
645
+ round(options: IRoundOptions): TimeGuard;
646
+ addBusinessDays(days: number): TimeGuard;
647
+ subtractBusinessDays(days: number): TimeGuard;
648
+ isBefore(other: TimeGuard): boolean;
649
+ isAfter(other: TimeGuard): boolean;
650
+ isSame(other: TimeGuard, unit?: Unit): boolean;
651
+ isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
652
+ isWeekend(): boolean;
653
+ isHoliday(): boolean;
654
+ isBusinessDay(): boolean;
655
+ clone(): TimeGuard;
656
+ startOf(unit: Unit): TimeGuard;
657
+ endOf(unit: Unit): TimeGuard;
658
+ set(values: Partial<Record<Unit, number>>): TimeGuard;
659
+ year(): number;
660
+ month(): number;
661
+ day(): number;
662
+ hour(): number;
663
+ minute(): number;
664
+ second(): number;
665
+ millisecond(): number;
666
+ dayOfWeek(): number;
667
+ dayOfYear(): number;
668
+ weekOfYear(): number;
669
+ daysInMonth(): number;
670
+ daysInYear(): number;
671
+ inLeapYear(): boolean;
672
+ }
673
+ /**
674
+ * Forward declaration for DurationResult class
675
+ * Implementation is in ./index.ts, exported via ./index.ts
676
+ */
677
+ export declare class DurationResult implements IDurationResult {
678
+ constructor(parts: DurationParts, locale?: string, metadata?: {
679
+ startDate?: string;
680
+ endDate?: string;
681
+ steps?: string[];
682
+ mode?: 'exact' | 'estimated';
683
+ leapYearFlags?: Array<{
684
+ year: number;
685
+ isLeap: boolean;
686
+ daysInFebruary: number;
687
+ }>;
688
+ calculationTimeMs?: number;
689
+ });
690
+ years: number;
691
+ months: number;
692
+ weeks: number;
693
+ days: number;
694
+ hours: number;
695
+ minutes: number;
696
+ seconds: number;
697
+ milliseconds: number;
698
+ humanize(options?: {
699
+ locale?: string;
700
+ fullBreakdown?: boolean;
701
+ numeric?: 'always' | 'auto';
702
+ }): string;
703
+ total(unit: Unit): number;
704
+ toString(): string;
705
+ toJSON(): Record<string, number>;
706
+ explain(): IDurationExplanation;
707
+ }
708
+ /**
709
+ * Forward declaration for TimeRange class
710
+ * Fluent API for date range operations with semantic naming
711
+ * Implementation is in ./index.ts, exported via ./index.ts
712
+ */
713
+ export declare class TimeRange {
714
+ constructor(start: TimeGuard, end: TimeGuard);
715
+ get start(): TimeGuard;
716
+ get end(): TimeGuard;
717
+ toDuration(): DurationResult;
718
+ inMonths(): number;
719
+ humanize(options?: {
720
+ locale?: string;
721
+ fullBreakdown?: boolean;
722
+ numeric?: 'always' | 'auto';
723
+ }): string;
724
+ in(unit: Unit): number;
725
+ contains(date: unknown): boolean;
726
+ overlaps(other: TimeRange): boolean;
727
+ intersect(other: TimeRange): TimeRange | null;
728
+ union(other: TimeRange): TimeRange;
189
729
  }
190
- export type { ITimeGuard, ITimeGuardConfig, ITimeGuardFactory, ITimeGuardPlugin, IDateParser, IDateFormatter, ILocaleManager, IDateArithmetic, IDateQuery, IDateManipulation, ITimezoneAdapter, ICalendarSystem, ICalendarManager, IRoundOptions, IDurationOptions, IDurationResult, IDurationExplanation, IHumanizeOptions, IDiffResult, IDiffOptions, DurationParts, Unit, FormatPreset, ILocale, } from './types';
191
- export { TemporalAdapter } from './adapters/temporal.adapter';
192
- export { LocaleManager, EN_LOCALE, ES_LOCALE };
193
- export { getAvailableLocales, LOCALES_COUNT, ALL_LOCALES, registerAllLocales, } from './locales/index';
194
- export { DateFormatter } from './formatters/date.formatter';
195
- export { CalendarManager, GregorianCalendar, calendarManager, } from './calendars/calendar.manager';
196
- export { IslamicCalendar, HebrewCalendar, ChineseCalendar, JapaneseCalendar, BuddhistCalendar, } from './calendars/index';
197
- export * from './plugins/index';
198
- export { PluginManager } from './plugins/manager';
199
- export { RelativeTimePlugin, default as relativeTimePlugin, } from './plugins/relative-time';
200
- export type { RelativeTimeConfig, RelativeTimeFormats, RelativeTimeThreshold, } from './plugins/relative-time/types';
201
- export { DurationPlugin, Duration, default as durationPlugin, } from './plugins/duration';
202
- export type { IDuration, DurationInput, DurationObject, DurationUnit, } from './plugins/duration/types';
203
- export { AdvancedFormatPlugin, default as advancedFormatPlugin, } from './plugins/advanced-format';
204
- export declare function timeGuard(input?: unknown, config?: ITimeGuardConfig): TimeGuard;
205
- export declare const version: string;