@bereasoftware/time-guard 2.5.1 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +7 -4
- package/README.md +7 -4
- package/dist/calendars/index.es.js +1 -1
- package/dist/plugins/advanced-format.cjs +1 -1
- package/dist/plugins/advanced-format.cjs.map +1 -1
- package/dist/plugins/advanced-format.es.js +1 -53
- package/dist/plugins/advanced-format.es.js.map +1 -1
- package/dist/plugins/duration.cjs.map +1 -1
- package/dist/plugins/duration.es.js +1 -1
- package/dist/plugins/duration.es.js.map +1 -1
- package/dist/plugins/relative-time.cjs.map +1 -1
- package/dist/plugins/relative-time.es.js +1 -1
- package/dist/plugins/relative-time.es.js.map +1 -1
- package/dist/time-guard.cjs +3 -1
- package/dist/time-guard.cjs.map +1 -1
- package/dist/time-guard.es.js +11014 -3948
- package/dist/time-guard.es.js.map +1 -1
- package/dist/time-guard.iife.js +3 -1
- package/dist/time-guard.iife.js.map +1 -1
- package/dist/time-guard.umd.js +3 -1
- package/dist/time-guard.umd.js.map +1 -1
- package/dist/types/calendars/index.d.ts +1 -81
- package/dist/types/index.d.ts +1 -20
- package/dist/types/locales/index.d.ts +1 -17
- package/dist/types/plugins/advanced-format.d.ts +1 -0
- package/dist/types/plugins/duration.d.ts +1 -0
- package/dist/types/plugins/relative-time.d.ts +1 -0
- package/package.json +6 -7
- package/dist/types/adapters/temporal.adapter.d.ts +0 -66
- package/dist/types/calendars/calendar.manager.d.ts +0 -52
- package/dist/types/formatters/date.formatter.d.ts +0 -21
- package/dist/types/locales/additional.locale.d.ts +0 -5
- package/dist/types/locales/asian.locale.d.ts +0 -9
- package/dist/types/locales/english.locale.d.ts +0 -6
- package/dist/types/locales/european.locale.d.ts +0 -9
- package/dist/types/locales/locale.manager.d.ts +0 -42
- package/dist/types/locales/locales-data.d.ts +0 -17
- package/dist/types/locales/middle-eastern.locale.d.ts +0 -5
- package/dist/types/locales/nordic.locale.d.ts +0 -6
- package/dist/types/locales/romance.locale.d.ts +0 -7
- package/dist/types/locales/slavic.locale.d.ts +0 -6
- package/dist/types/locales/spanish.locale.d.ts +0 -5
- package/dist/types/plugins/advanced-format/index.d.ts +0 -47
- package/dist/types/plugins/duration/index.d.ts +0 -107
- package/dist/types/plugins/duration/types.d.ts +0 -85
- package/dist/types/plugins/index.d.ts +0 -10
- package/dist/types/plugins/manager.d.ts +0 -58
- package/dist/types/plugins/relative-time/index.d.ts +0 -39
- package/dist/types/plugins/relative-time/types.d.ts +0 -27
- package/dist/types/polyfill-loader.d.ts +0 -6
- package/dist/types/time-guard.d.ts +0 -426
- package/dist/types/types/index.d.ts +0 -578
- package/dist/types/utils/duration-locale.d.ts +0 -33
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Duration Plugin Types
|
|
3
|
-
*/
|
|
4
|
-
export type DurationUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
|
|
5
|
-
export interface DurationInput {
|
|
6
|
-
years?: number;
|
|
7
|
-
months?: number;
|
|
8
|
-
weeks?: number;
|
|
9
|
-
days?: number;
|
|
10
|
-
hours?: number;
|
|
11
|
-
minutes?: number;
|
|
12
|
-
seconds?: number;
|
|
13
|
-
milliseconds?: number;
|
|
14
|
-
}
|
|
15
|
-
export interface DurationObject {
|
|
16
|
-
years: number;
|
|
17
|
-
months: number;
|
|
18
|
-
weeks: number;
|
|
19
|
-
days: number;
|
|
20
|
-
hours: number;
|
|
21
|
-
minutes: number;
|
|
22
|
-
seconds: number;
|
|
23
|
-
milliseconds: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Duration class for ISO 8601 durations
|
|
27
|
-
*/
|
|
28
|
-
export interface IDuration {
|
|
29
|
-
/**
|
|
30
|
-
* Get duration in specific unit
|
|
31
|
-
*/
|
|
32
|
-
as(unit: DurationUnit): number;
|
|
33
|
-
/**
|
|
34
|
-
* Get duration as milliseconds
|
|
35
|
-
*/
|
|
36
|
-
asMilliseconds(): number;
|
|
37
|
-
/**
|
|
38
|
-
* Get duration as seconds
|
|
39
|
-
*/
|
|
40
|
-
asSeconds(): number;
|
|
41
|
-
/**
|
|
42
|
-
* Get duration as minutes
|
|
43
|
-
*/
|
|
44
|
-
asMinutes(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Get duration as hours
|
|
47
|
-
*/
|
|
48
|
-
asHours(): number;
|
|
49
|
-
/**
|
|
50
|
-
* Get duration as days
|
|
51
|
-
*/
|
|
52
|
-
asDays(): number;
|
|
53
|
-
/**
|
|
54
|
-
* Get duration as weeks
|
|
55
|
-
*/
|
|
56
|
-
asWeeks(): number;
|
|
57
|
-
/**
|
|
58
|
-
* Get duration as months
|
|
59
|
-
*/
|
|
60
|
-
asMonths(): number;
|
|
61
|
-
/**
|
|
62
|
-
* Get duration as years
|
|
63
|
-
*/
|
|
64
|
-
asYears(): number;
|
|
65
|
-
/**
|
|
66
|
-
* Get all components
|
|
67
|
-
*/
|
|
68
|
-
toObject(): DurationObject;
|
|
69
|
-
/**
|
|
70
|
-
* Get ISO 8601 string representation
|
|
71
|
-
*/
|
|
72
|
-
toISO(): string;
|
|
73
|
-
/**
|
|
74
|
-
* Get human-readable string
|
|
75
|
-
*/
|
|
76
|
-
humanize(): string;
|
|
77
|
-
/**
|
|
78
|
-
* Check if duration is negative
|
|
79
|
-
*/
|
|
80
|
-
isNegative(): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Get absolute duration
|
|
83
|
-
*/
|
|
84
|
-
abs(): IDuration;
|
|
85
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TimeGuard Plugins
|
|
3
|
-
* Central export point for all plugins
|
|
4
|
-
*/
|
|
5
|
-
export { PluginManager } from './manager';
|
|
6
|
-
export { RelativeTimePlugin, default as relativeTimePlugin } from './relative-time';
|
|
7
|
-
export { DurationPlugin, Duration, default as durationPlugin } from './duration';
|
|
8
|
-
export { AdvancedFormatPlugin, default as advancedFormatPlugin } from './advanced-format';
|
|
9
|
-
export type { RelativeTimeConfig, RelativeTimeFormats, RelativeTimeThreshold } from './relative-time/types';
|
|
10
|
-
export type { IDuration, DurationInput, DurationObject, DurationUnit } from './duration/types';
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ITimeGuardPlugin } from '../types';
|
|
2
|
-
import { TimeGuard } from '../time-guard';
|
|
3
|
-
/**
|
|
4
|
-
* Plugin Manager - handles plugin registration and initialization
|
|
5
|
-
* Uses Singleton pattern to ensure single instance across application
|
|
6
|
-
*/
|
|
7
|
-
export declare class PluginManager {
|
|
8
|
-
private static instance;
|
|
9
|
-
private plugins;
|
|
10
|
-
/**
|
|
11
|
-
* Get singleton instance
|
|
12
|
-
*/
|
|
13
|
-
static getInstance(): PluginManager;
|
|
14
|
-
/**
|
|
15
|
-
* Register a plugin
|
|
16
|
-
* @param plugin - The plugin to register
|
|
17
|
-
* @param timeGuardClass - Reference to TimeGuard class
|
|
18
|
-
* @param config - Optional plugin configuration
|
|
19
|
-
*/
|
|
20
|
-
static use(plugin: ITimeGuardPlugin, timeGuardClass: typeof TimeGuard, config?: unknown): void;
|
|
21
|
-
/**
|
|
22
|
-
* Register multiple plugins at once
|
|
23
|
-
* @param plugins - Array of plugins to register
|
|
24
|
-
* @param timeGuardClass - Reference to TimeGuard class
|
|
25
|
-
* @param config - Optional plugin configuration
|
|
26
|
-
*/
|
|
27
|
-
static useMultiple(plugins: ITimeGuardPlugin[], timeGuardClass: typeof TimeGuard, config?: unknown): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get registered plugin by name
|
|
30
|
-
* @param name - Plugin name
|
|
31
|
-
* @returns Plugin instance or undefined
|
|
32
|
-
*/
|
|
33
|
-
static getPlugin(name: string): ITimeGuardPlugin | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Check if plugin is registered
|
|
36
|
-
* @param name - Plugin name
|
|
37
|
-
* @returns True if plugin is registered
|
|
38
|
-
*/
|
|
39
|
-
static hasPlugin(name: string): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Get all registered plugins
|
|
42
|
-
* @returns Array of registered plugin names
|
|
43
|
-
*/
|
|
44
|
-
static listPlugins(): string[];
|
|
45
|
-
/**
|
|
46
|
-
* Unregister a plugin
|
|
47
|
-
* @param name - Plugin name
|
|
48
|
-
*/
|
|
49
|
-
static unuse(name: string): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Clear all plugins
|
|
52
|
-
*/
|
|
53
|
-
static clear(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Internal register method
|
|
56
|
-
*/
|
|
57
|
-
private register;
|
|
58
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ITimeGuardPlugin } from '../../types';
|
|
2
|
-
import { TimeGuard } from '../../time-guard';
|
|
3
|
-
import { RelativeTimeConfig, RelativeTimeFormats } from './types';
|
|
4
|
-
export declare class RelativeTimePlugin implements ITimeGuardPlugin {
|
|
5
|
-
name: string;
|
|
6
|
-
version: string;
|
|
7
|
-
private config;
|
|
8
|
-
private formats;
|
|
9
|
-
constructor(config?: RelativeTimeConfig);
|
|
10
|
-
/**
|
|
11
|
-
* Install plugin into TimeGuard
|
|
12
|
-
*/
|
|
13
|
-
install(TimeGuardClass: typeof TimeGuard): void;
|
|
14
|
-
/**
|
|
15
|
-
* Format relative time
|
|
16
|
-
*/
|
|
17
|
-
private formatRelativeTime;
|
|
18
|
-
/**
|
|
19
|
-
* Get relative time string based on milliseconds
|
|
20
|
-
*/
|
|
21
|
-
private getRelativeTimeString;
|
|
22
|
-
/**
|
|
23
|
-
* Get milliseconds per unit
|
|
24
|
-
*/
|
|
25
|
-
private getUnitMilliseconds;
|
|
26
|
-
/**
|
|
27
|
-
* Set format strings
|
|
28
|
-
*/
|
|
29
|
-
setFormats(formats: Partial<RelativeTimeFormats>): void;
|
|
30
|
-
/**
|
|
31
|
-
* Get current formats
|
|
32
|
-
*/
|
|
33
|
-
getFormats(): RelativeTimeFormats;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Create and export default instance
|
|
37
|
-
*/
|
|
38
|
-
declare const _default: RelativeTimePlugin;
|
|
39
|
-
export default _default;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RelativeTime Plugin Types
|
|
3
|
-
*/
|
|
4
|
-
export interface RelativeTimeConfig {
|
|
5
|
-
thresholds?: RelativeTimeThreshold[];
|
|
6
|
-
rounding?: (value: number) => number;
|
|
7
|
-
}
|
|
8
|
-
export interface RelativeTimeThreshold {
|
|
9
|
-
l: string;
|
|
10
|
-
r?: number;
|
|
11
|
-
d?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface RelativeTimeFormats {
|
|
14
|
-
future: string;
|
|
15
|
-
past: string;
|
|
16
|
-
s: string;
|
|
17
|
-
m: string;
|
|
18
|
-
mm: string;
|
|
19
|
-
h: string;
|
|
20
|
-
hh: string;
|
|
21
|
-
d: string;
|
|
22
|
-
dd: string;
|
|
23
|
-
M: string;
|
|
24
|
-
MM: string;
|
|
25
|
-
y: string;
|
|
26
|
-
yy: string;
|
|
27
|
-
}
|
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
import { ITimeGuard, ITimeGuardConfig, Unit, FormatPreset, IRoundOptions, IDurationOptions, IDiffResult, IDiffOptions, DurationParts, IDurationExplanation } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Diff result object that allows chaining with .as()
|
|
4
|
-
* Example: tg1.diff(tg2).as('month')
|
|
5
|
-
* Also acts as a number value for backward compatibility
|
|
6
|
-
*
|
|
7
|
-
* Supports two modes:
|
|
8
|
-
* - 'exact': Returns precise time differences (e.g., 65 days)
|
|
9
|
-
* - 'calendar': Returns calendar-aware breakdown (e.g., 2 months 5 days)
|
|
10
|
-
*/
|
|
11
|
-
declare class DiffResult implements IDiffResult {
|
|
12
|
-
private _value;
|
|
13
|
-
private _tg1;
|
|
14
|
-
private _tg2;
|
|
15
|
-
private _mode;
|
|
16
|
-
private _breakdownData;
|
|
17
|
-
private _locale;
|
|
18
|
-
constructor(value: number, tg1: TimeGuard, tg2: TimeGuard, mode?: 'calendar' | 'exact', breakdownData?: DurationParts, locale?: string);
|
|
19
|
-
/**
|
|
20
|
-
* Convert the diff to a different unit
|
|
21
|
-
* Example: diff.as('month') returns the difference in months
|
|
22
|
-
*/
|
|
23
|
-
as(unit: Unit): number;
|
|
24
|
-
/**
|
|
25
|
-
* Get breakdown in calendar mode (months, days, etc.)
|
|
26
|
-
* Returns null for 'exact' mode
|
|
27
|
-
*/
|
|
28
|
-
breakdown(): DurationParts | null;
|
|
29
|
-
/**
|
|
30
|
-
* Format as human-readable string
|
|
31
|
-
* Example: "2 months and 5 days"
|
|
32
|
-
*/
|
|
33
|
-
format(locale?: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Get the calculation mode used for this diff
|
|
36
|
-
*/
|
|
37
|
-
getMode(): 'calendar' | 'exact';
|
|
38
|
-
/**
|
|
39
|
-
* Allow implicit numeric conversion for backward compatibility
|
|
40
|
-
*/
|
|
41
|
-
valueOf(): number;
|
|
42
|
-
/**
|
|
43
|
-
* String representation
|
|
44
|
-
*/
|
|
45
|
-
toString(): string;
|
|
46
|
-
/**
|
|
47
|
-
* JSON representation
|
|
48
|
-
*/
|
|
49
|
-
toJSON(): number;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* DurationResult class - Represents a duration breakdown with humanize support
|
|
53
|
-
* Example: start.until(end).humanize() → "2 months and 5 days"
|
|
54
|
-
*
|
|
55
|
-
* Public class available for type checking and extending
|
|
56
|
-
* Returned by until(), since(), and between() methods
|
|
57
|
-
*/
|
|
58
|
-
export declare class DurationResult implements DurationParts {
|
|
59
|
-
years: number;
|
|
60
|
-
months: number;
|
|
61
|
-
weeks: number;
|
|
62
|
-
days: number;
|
|
63
|
-
hours: number;
|
|
64
|
-
minutes: number;
|
|
65
|
-
seconds: number;
|
|
66
|
-
milliseconds: number;
|
|
67
|
-
private _locale;
|
|
68
|
-
private _startDate?;
|
|
69
|
-
private _endDate?;
|
|
70
|
-
private _steps;
|
|
71
|
-
private _mode;
|
|
72
|
-
private _leapYearFlags;
|
|
73
|
-
private _calculationTimeMs;
|
|
74
|
-
constructor(parts: DurationParts, locale?: string, metadata?: {
|
|
75
|
-
startDate?: string;
|
|
76
|
-
endDate?: string;
|
|
77
|
-
steps?: string[];
|
|
78
|
-
mode?: 'exact' | 'estimated';
|
|
79
|
-
leapYearFlags?: Array<{
|
|
80
|
-
year: number;
|
|
81
|
-
isLeap: boolean;
|
|
82
|
-
daysInFebruary: number;
|
|
83
|
-
}>;
|
|
84
|
-
calculationTimeMs?: number;
|
|
85
|
-
});
|
|
86
|
-
/**
|
|
87
|
-
* Convert duration to human-readable string
|
|
88
|
-
* Supports multiple humanization styles using Intl API
|
|
89
|
-
* @example
|
|
90
|
-
* duration.humanize() // "2 months" (Intl.RelativeTimeFormat style)
|
|
91
|
-
* duration.humanize({ fullBreakdown: true, locale: 'es' }) // "2 meses y 5 días"
|
|
92
|
-
*/
|
|
93
|
-
humanize(options?: {
|
|
94
|
-
locale?: string;
|
|
95
|
-
fullBreakdown?: boolean;
|
|
96
|
-
numeric?: 'always' | 'auto';
|
|
97
|
-
}): string;
|
|
98
|
-
/**
|
|
99
|
-
* Get total duration in specified unit (date-fns style)
|
|
100
|
-
* Useful for business logic: payments, metrics, analytics
|
|
101
|
-
*
|
|
102
|
-
* Conversion factors:
|
|
103
|
-
* - 1 year = 365.25 days (accounting for leap years)
|
|
104
|
-
* - 1 month = 365.25/12 days = 30.4375 days
|
|
105
|
-
* - 1 week = 7 days
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* duration.total('days') // 65
|
|
109
|
-
* duration.total('months') // 2.166... (65 / 30.4375)
|
|
110
|
-
* duration.total('hours') // 1560 (65 * 24)
|
|
111
|
-
* duration.total('seconds') // 5616000 (65 * 24 * 60 * 60)
|
|
112
|
-
*/
|
|
113
|
-
total(unit: Unit): number;
|
|
114
|
-
/**
|
|
115
|
-
* String representation
|
|
116
|
-
* Returns humanized format by default, or numeric if in exact mode
|
|
117
|
-
*/
|
|
118
|
-
toString(): string;
|
|
119
|
-
/**
|
|
120
|
-
* JSON representation
|
|
121
|
-
* Returns the breakdown as object for serialization
|
|
122
|
-
*/
|
|
123
|
-
toJSON(): Record<string, number>;
|
|
124
|
-
/**
|
|
125
|
-
* Explain the calculation - killer feature for debugging and education
|
|
126
|
-
* Returns detailed breakdown of how the duration was calculated
|
|
127
|
-
*
|
|
128
|
-
* Perfect for:
|
|
129
|
-
* - Debugging complex date calculations
|
|
130
|
-
* - Educational purposes (showing date math)
|
|
131
|
-
* - Auditing time-based business logic
|
|
132
|
-
* - Verification of calculation methodology
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* start.until(end).explain()
|
|
136
|
-
* // {
|
|
137
|
-
* // input: ['2024-01-15', '2024-03-20'],
|
|
138
|
-
* // steps: [
|
|
139
|
-
* // 'Parsed dates: 2024-01-15 to 2024-03-20',
|
|
140
|
-
* // '2024 is a leap year (366 days)',
|
|
141
|
-
* // 'February 2024 has 29 days',
|
|
142
|
-
* // 'Total calculated: 65 days'
|
|
143
|
-
* // ],
|
|
144
|
-
* // breakdown: { years: 0, months: 2, weeks: 0, days: 5, ... },
|
|
145
|
-
* // mode: 'exact',
|
|
146
|
-
* // explanation: 'Calculated 2024-01-15 to 2024-03-20...'
|
|
147
|
-
* // }
|
|
148
|
-
*/
|
|
149
|
-
explain(): IDurationExplanation;
|
|
150
|
-
/**
|
|
151
|
-
* Generate explanation steps for the calculation
|
|
152
|
-
* Used when steps weren't provided during construction
|
|
153
|
-
*/
|
|
154
|
-
private generateExplanationSteps;
|
|
155
|
-
/**
|
|
156
|
-
* Pluralize a unit name (deprecated - use utility function)
|
|
157
|
-
*/
|
|
158
|
-
private pluralizeUnit;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* TimeGuard implementation - Main facade class
|
|
162
|
-
*/
|
|
163
|
-
/**
|
|
164
|
-
* TimeRange - Fluent API for date range operations
|
|
165
|
-
* Semantic naming that eliminates confusion about date order
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* TimeGuard.range('2024-01-15', '2024-03-20')
|
|
169
|
-
* .toDuration() // Returns DurationResult
|
|
170
|
-
* .humanize() // "2 months and 5 days"
|
|
171
|
-
*
|
|
172
|
-
* TimeGuard.range('2024-01-15', '2024-03-20')
|
|
173
|
-
* .inMonths() // 2.1355 (precise decimal)
|
|
174
|
-
*
|
|
175
|
-
* These methods work regardless of date order
|
|
176
|
-
*/
|
|
177
|
-
export declare class TimeRange {
|
|
178
|
-
private _start;
|
|
179
|
-
private _end;
|
|
180
|
-
constructor(start: TimeGuard, end: TimeGuard);
|
|
181
|
-
/**
|
|
182
|
-
* Get the duration between the two dates
|
|
183
|
-
* @returns DurationResult with all duration properties and methods
|
|
184
|
-
* @example
|
|
185
|
-
* const duration = TimeGuard.range(start, end).toDuration();
|
|
186
|
-
* duration.humanize(); // "2 months and 5 days"
|
|
187
|
-
* duration.total('day'); // 65.875
|
|
188
|
-
*/
|
|
189
|
-
toDuration(): DurationResult;
|
|
190
|
-
/**
|
|
191
|
-
* Get the range expressed in months (as decimal)
|
|
192
|
-
* Accounts for leap years and average month lengths
|
|
193
|
-
* @returns Number of months (can be decimal like 2.1355)
|
|
194
|
-
* @example
|
|
195
|
-
* TimeGuard.range('2024-01-15', '2024-03-20').inMonths(); // ~2.1355
|
|
196
|
-
*/
|
|
197
|
-
inMonths(): number;
|
|
198
|
-
/**
|
|
199
|
-
* Get human-readable representation of the range
|
|
200
|
-
* Semantic naming that emphasizes what the range represents
|
|
201
|
-
* @returns String like "2 months and 5 days"
|
|
202
|
-
* @example
|
|
203
|
-
* TimeGuard.range(start, end).humanize(); // "2 months and 5 days"
|
|
204
|
-
* TimeGuard.range(start, end).humanize({ locale: 'es' }); // "2 meses y 5 días"
|
|
205
|
-
*/
|
|
206
|
-
humanize(options?: {
|
|
207
|
-
locale?: string;
|
|
208
|
-
fullBreakdown?: boolean;
|
|
209
|
-
numeric?: 'always' | 'auto';
|
|
210
|
-
}): string;
|
|
211
|
-
/**
|
|
212
|
-
* Get duration in specific unit
|
|
213
|
-
* Chainable with other TimeRange methods
|
|
214
|
-
* @example
|
|
215
|
-
* TimeGuard.range(start, end).in('day'); // 65.875
|
|
216
|
-
*/
|
|
217
|
-
in(unit: Unit): number;
|
|
218
|
-
}
|
|
219
|
-
export declare class TimeGuard implements ITimeGuard {
|
|
220
|
-
private temporal;
|
|
221
|
-
private config;
|
|
222
|
-
private formatterInstance;
|
|
223
|
-
private static readonly ZERO_DURATION;
|
|
224
|
-
private static isLeapYearValue;
|
|
225
|
-
private static toDurationParts;
|
|
226
|
-
constructor(input?: unknown, config?: ITimeGuardConfig);
|
|
227
|
-
/**
|
|
228
|
-
* Static factory methods
|
|
229
|
-
*/
|
|
230
|
-
static now(config?: ITimeGuardConfig): TimeGuard;
|
|
231
|
-
static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
|
|
232
|
-
static fromTemporal(temporal: any, // Temporal.PlainDateTime | Temporal.ZonedDateTime
|
|
233
|
-
config?: ITimeGuardConfig): TimeGuard;
|
|
234
|
-
/**
|
|
235
|
-
* Calculate duration between two dates - semantic API eliminating until/since confusion
|
|
236
|
-
*
|
|
237
|
-
* Always returns positive duration regardless of date order.
|
|
238
|
-
* Use .humanize() for user-friendly output.
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* const start = TimeGuard.from("2024-01-15");
|
|
242
|
-
* const end = TimeGuard.from("2024-03-20");
|
|
243
|
-
*
|
|
244
|
-
* TimeGuard.between(start, end).humanize();
|
|
245
|
-
* // "2 months and 5 days"
|
|
246
|
-
*
|
|
247
|
-
* // Order doesn't matter - semantic clarity!
|
|
248
|
-
* TimeGuard.between(end, start).humanize();
|
|
249
|
-
* // "2 months and 5 days" (still positive)
|
|
250
|
-
*
|
|
251
|
-
* // Has all DurationParts properties
|
|
252
|
-
* TimeGuard.between(start, end).months; // 2
|
|
253
|
-
* TimeGuard.between(start, end).days; // 5
|
|
254
|
-
*/
|
|
255
|
-
static between(date1: TimeGuard, date2: TimeGuard): DurationResult;
|
|
256
|
-
/**
|
|
257
|
-
* Create a TimeRange for fluent duration calculations
|
|
258
|
-
* Marketing-friendly naming that emphasizes range semantics
|
|
259
|
-
*
|
|
260
|
-
* @example
|
|
261
|
-
* TimeGuard.range("2024-01-15", "2024-03-20")
|
|
262
|
-
* .humanize() // "2 months and 5 days"
|
|
263
|
-
*
|
|
264
|
-
* TimeGuard.range("2024-01-15", "2024-03-20")
|
|
265
|
-
* .inMonths() // 2.1355
|
|
266
|
-
*
|
|
267
|
-
* TimeGuard.range("2024-01-15", "2024-03-20")
|
|
268
|
-
* .toDuration() // DurationResult object
|
|
269
|
-
*/
|
|
270
|
-
static range(start: unknown, end: unknown): TimeRange;
|
|
271
|
-
toTemporal(): any;
|
|
272
|
-
toDate(): Date;
|
|
273
|
-
toISOString(): string;
|
|
274
|
-
valueOf(): number;
|
|
275
|
-
unix(): number;
|
|
276
|
-
toJSON(): string;
|
|
277
|
-
toString(): string;
|
|
278
|
-
locale(): string;
|
|
279
|
-
locale(locale: string): TimeGuard;
|
|
280
|
-
timezone(): string | null;
|
|
281
|
-
timezone(timezone: string): TimeGuard;
|
|
282
|
-
format(pattern: string | FormatPreset): string;
|
|
283
|
-
get(component: Unit): number;
|
|
284
|
-
add(units: Partial<Record<Unit, number>>): TimeGuard;
|
|
285
|
-
subtract(units: Partial<Record<Unit, number>>): TimeGuard;
|
|
286
|
-
/**
|
|
287
|
-
* Calculate difference between two TimeGuard instances
|
|
288
|
-
*
|
|
289
|
-
* Supports multiple modes:
|
|
290
|
-
* 1. diff(other) - Returns DiffResult with fluent API (default: exact mode)
|
|
291
|
-
* 2. diff(other, unit) - Returns number (backward compatible)
|
|
292
|
-
* 3. diff(other, options) - Returns DiffResult with calendar or exact mode
|
|
293
|
-
*
|
|
294
|
-
* @example
|
|
295
|
-
* // Exact mode (default)
|
|
296
|
-
* tg1.diff(tg2).as('day') // Get as number: 65
|
|
297
|
-
*
|
|
298
|
-
* // Calendar mode - shows normalized breakdown
|
|
299
|
-
* tg1.diff(tg2, { mode: 'calendar' }).format('en')
|
|
300
|
-
* // Output: "2 months and 5 days"
|
|
301
|
-
*
|
|
302
|
-
* // With custom unit
|
|
303
|
-
* tg1.diff(tg2, { unit: 'hour' }).as('hour') // 1560
|
|
304
|
-
*/
|
|
305
|
-
diff(other: TimeGuard): DiffResult;
|
|
306
|
-
diff(other: TimeGuard, unit: Unit): number;
|
|
307
|
-
diff(other: TimeGuard, options: IDiffOptions): DiffResult;
|
|
308
|
-
isBefore(other: TimeGuard): boolean;
|
|
309
|
-
isAfter(other: TimeGuard): boolean;
|
|
310
|
-
isSame(other: TimeGuard, unit?: Unit): boolean;
|
|
311
|
-
isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
|
|
312
|
-
clone(): TimeGuard;
|
|
313
|
-
startOf(unit: Unit): TimeGuard;
|
|
314
|
-
endOf(unit: Unit): TimeGuard;
|
|
315
|
-
set(values: Partial<Record<Unit, number>>): TimeGuard;
|
|
316
|
-
year(): number;
|
|
317
|
-
month(): number;
|
|
318
|
-
day(): number;
|
|
319
|
-
hour(): number;
|
|
320
|
-
minute(): number;
|
|
321
|
-
second(): number;
|
|
322
|
-
millisecond(): number;
|
|
323
|
-
dayOfWeek(): number;
|
|
324
|
-
dayOfYear(): number;
|
|
325
|
-
weekOfYear(): number;
|
|
326
|
-
daysInMonth(): number;
|
|
327
|
-
daysInYear(): number;
|
|
328
|
-
inLeapYear(): boolean;
|
|
329
|
-
/**
|
|
330
|
-
* Calculate duration until another TimeGuard
|
|
331
|
-
* @returns Duration object with .humanize() and other methods
|
|
332
|
-
* @example
|
|
333
|
-
* start.until(end).humanize() // "2 months and 5 days"
|
|
334
|
-
* start.until(end).humanize({ fullBreakdown: true, locale: 'es' }) // "2 meses y 5 días"
|
|
335
|
-
*/
|
|
336
|
-
until(other: TimeGuard, options?: IDurationOptions): DurationResult;
|
|
337
|
-
/**
|
|
338
|
-
* Generate explanation steps for until() calculation
|
|
339
|
-
*/
|
|
340
|
-
private generateUntilSteps;
|
|
341
|
-
/**
|
|
342
|
-
* Round to a specific unit with optional rounding mode
|
|
343
|
-
*/
|
|
344
|
-
round(options?: IRoundOptions): TimeGuard;
|
|
345
|
-
/**
|
|
346
|
-
* Convert to PlainDate (removes time information)
|
|
347
|
-
*/
|
|
348
|
-
toPlainDate(): {
|
|
349
|
-
year: number;
|
|
350
|
-
month: number;
|
|
351
|
-
day: number;
|
|
352
|
-
dayOfWeek: number;
|
|
353
|
-
};
|
|
354
|
-
/**
|
|
355
|
-
* Convert to PlainTime (removes date information)
|
|
356
|
-
*/
|
|
357
|
-
toPlainTime(): {
|
|
358
|
-
hour: number;
|
|
359
|
-
minute: number;
|
|
360
|
-
second: number;
|
|
361
|
-
millisecond: number;
|
|
362
|
-
};
|
|
363
|
-
/**
|
|
364
|
-
* Create new TimeGuard with only date, keeping time from parameter
|
|
365
|
-
*/
|
|
366
|
-
withDate(year: number, month: number, day: number): TimeGuard;
|
|
367
|
-
/**
|
|
368
|
-
* Create new TimeGuard with only time, keeping date
|
|
369
|
-
*/
|
|
370
|
-
withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
|
|
371
|
-
/**
|
|
372
|
-
* Get timezone offset in format ±HH:mm
|
|
373
|
-
*/
|
|
374
|
-
getOffset(): string;
|
|
375
|
-
/**
|
|
376
|
-
* Get timezone offset in nanoseconds
|
|
377
|
-
*/
|
|
378
|
-
getOffsetNanoseconds(): number;
|
|
379
|
-
/**
|
|
380
|
-
* Get timezone ID
|
|
381
|
-
*/
|
|
382
|
-
getTimeZoneId(): string | null;
|
|
383
|
-
/**
|
|
384
|
-
* Start of the day in current timezone
|
|
385
|
-
*/
|
|
386
|
-
startOfDay(): TimeGuard;
|
|
387
|
-
/**
|
|
388
|
-
* End of the day in current timezone
|
|
389
|
-
*/
|
|
390
|
-
endOfDay(): TimeGuard;
|
|
391
|
-
/**
|
|
392
|
-
* Calculate duration from another TimeGuard (inverse of until)
|
|
393
|
-
* Returns negative values if other is before this
|
|
394
|
-
* @returns Duration object with .humanize() and other methods
|
|
395
|
-
* @example
|
|
396
|
-
* end.since(start).humanize() // "2 months and 5 days"
|
|
397
|
-
* end.since(start).humanize({ locale: 'es' }) // "2 meses y 5 días"
|
|
398
|
-
*/
|
|
399
|
-
since(other: TimeGuard, options?: IDurationOptions): DurationResult;
|
|
400
|
-
/**
|
|
401
|
-
* Get ISO 8601 duration string
|
|
402
|
-
* Example: P1Y2M3DT4H5M6S
|
|
403
|
-
*/
|
|
404
|
-
toDurationString(other?: TimeGuard): string;
|
|
405
|
-
/**
|
|
406
|
-
* Check if this date is in the past
|
|
407
|
-
*/
|
|
408
|
-
isPast(): boolean;
|
|
409
|
-
/**
|
|
410
|
-
* Check if this date is in the future
|
|
411
|
-
*/
|
|
412
|
-
isFuture(): boolean;
|
|
413
|
-
/**
|
|
414
|
-
* Check if this date is today
|
|
415
|
-
*/
|
|
416
|
-
isToday(): boolean;
|
|
417
|
-
/**
|
|
418
|
-
* Check if this date is tomorrow
|
|
419
|
-
*/
|
|
420
|
-
isTomorrow(): boolean;
|
|
421
|
-
/**
|
|
422
|
-
* Check if this date is yesterday
|
|
423
|
-
*/
|
|
424
|
-
isYesterday(): boolean;
|
|
425
|
-
}
|
|
426
|
-
export { PluginManager } from './plugins/manager';
|