@bereasoftware/time-guard 2.0.3 → 2.0.4
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 +10 -2
- package/README.md +17 -7
- package/dist/{calendars.es.js → calendars/index.es.js} +1 -1
- package/dist/full.cjs +1 -1
- package/dist/full.es.js +2 -2
- package/dist/{locales.es.js → locales/index.es.js} +1 -1
- package/dist/{plugin-advanced-format.es.js → plugins/advanced-format.es.js} +1 -1
- package/dist/{plugin-duration.es.js → plugins/duration.es.js} +1 -1
- package/dist/{plugin-relative-time.es.js → plugins/relative-time.es.js} +1 -1
- package/dist/time-guard.cjs +1 -1
- package/dist/time-guard.es.js +2 -2
- package/dist/time-guard.iife.js +1 -1
- package/dist/time-guard.umd.js +1 -1
- package/dist/types/time-guard.d.ts +1130 -1
- package/package.json +22 -21
- package/dist/types/calendars.d.ts +0 -1
- package/dist/types/locales.d.ts +0 -1
- package/dist/types/plugin-advanced-format.d.ts +0 -1
- package/dist/types/plugin-duration.d.ts +0 -1
- package/dist/types/plugin-relative-time.d.ts +0 -1
- package/dist/types/src/adapters/temporal.adapter.d.ts +0 -60
- package/dist/types/src/calendars/calendar.manager.d.ts +0 -52
- package/dist/types/src/calendars/index.d.ts +0 -81
- package/dist/types/src/formatters/date.formatter.d.ts +0 -21
- package/dist/types/src/full.d.ts +0 -8
- package/dist/types/src/index.d.ts +0 -23
- package/dist/types/src/locales/additional.locale.d.ts +0 -5
- package/dist/types/src/locales/asian.locale.d.ts +0 -9
- package/dist/types/src/locales/english.locale.d.ts +0 -6
- package/dist/types/src/locales/european.locale.d.ts +0 -9
- package/dist/types/src/locales/index.d.ts +0 -17
- package/dist/types/src/locales/locale.manager.d.ts +0 -42
- package/dist/types/src/locales/locales-data.d.ts +0 -17
- package/dist/types/src/locales/middle-eastern.locale.d.ts +0 -5
- package/dist/types/src/locales/nordic.locale.d.ts +0 -6
- package/dist/types/src/locales/romance.locale.d.ts +0 -7
- package/dist/types/src/locales/slavic.locale.d.ts +0 -6
- package/dist/types/src/locales/spanish.locale.d.ts +0 -5
- package/dist/types/src/plugins/advanced-format/index.d.ts +0 -47
- package/dist/types/src/plugins/duration/index.d.ts +0 -107
- package/dist/types/src/plugins/duration/types.d.ts +0 -85
- package/dist/types/src/plugins/index.d.ts +0 -10
- package/dist/types/src/plugins/manager.d.ts +0 -58
- package/dist/types/src/plugins/relative-time/index.d.ts +0 -39
- package/dist/types/src/plugins/relative-time/types.d.ts +0 -27
- package/dist/types/src/polyfill-loader.d.ts +0 -5
- package/dist/types/src/time-guard.d.ts +0 -154
- package/dist/types/src/types/index.d.ts +0 -301
- /package/dist/{calendars.cjs → calendars/index.cjs} +0 -0
- /package/dist/{locales.cjs → locales/index.cjs} +0 -0
- /package/dist/{plugin-advanced-format.cjs → plugins/advanced-format.cjs} +0 -0
- /package/dist/{plugin-duration.cjs → plugins/duration.cjs} +0 -0
- /package/dist/{plugin-relative-time.cjs → plugins/relative-time.cjs} +0 -0
|
@@ -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,154 +0,0 @@
|
|
|
1
|
-
import { ITimeGuard, ITimeGuardConfig, Unit, FormatPreset, IRoundOptions } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* TimeGuard implementation - Main facade class
|
|
4
|
-
*/
|
|
5
|
-
export declare class TimeGuard implements ITimeGuard {
|
|
6
|
-
private temporal;
|
|
7
|
-
private config;
|
|
8
|
-
private formatterInstance;
|
|
9
|
-
constructor(input?: unknown, config?: ITimeGuardConfig);
|
|
10
|
-
/**
|
|
11
|
-
* Static factory methods
|
|
12
|
-
*/
|
|
13
|
-
static now(config?: ITimeGuardConfig): TimeGuard;
|
|
14
|
-
static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
|
|
15
|
-
static fromTemporal(temporal: any, // Temporal.PlainDateTime | Temporal.ZonedDateTime
|
|
16
|
-
config?: ITimeGuardConfig): TimeGuard;
|
|
17
|
-
toTemporal(): any;
|
|
18
|
-
toDate(): Date;
|
|
19
|
-
toISOString(): string;
|
|
20
|
-
valueOf(): number;
|
|
21
|
-
unix(): number;
|
|
22
|
-
toJSON(): string;
|
|
23
|
-
toString(): string;
|
|
24
|
-
locale(): string;
|
|
25
|
-
locale(locale: string): TimeGuard;
|
|
26
|
-
timezone(): string | null;
|
|
27
|
-
timezone(timezone: string): TimeGuard;
|
|
28
|
-
format(pattern: string | FormatPreset): string;
|
|
29
|
-
get(component: Unit): number;
|
|
30
|
-
add(units: Partial<Record<Unit, number>>): TimeGuard;
|
|
31
|
-
subtract(units: Partial<Record<Unit, number>>): TimeGuard;
|
|
32
|
-
diff(other: TimeGuard, unit?: Unit): number;
|
|
33
|
-
isBefore(other: TimeGuard): boolean;
|
|
34
|
-
isAfter(other: TimeGuard): boolean;
|
|
35
|
-
isSame(other: TimeGuard, unit?: Unit): boolean;
|
|
36
|
-
isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
|
|
37
|
-
clone(): TimeGuard;
|
|
38
|
-
startOf(unit: Unit): TimeGuard;
|
|
39
|
-
endOf(unit: Unit): TimeGuard;
|
|
40
|
-
set(values: Partial<Record<Unit, number>>): TimeGuard;
|
|
41
|
-
year(): number;
|
|
42
|
-
month(): number;
|
|
43
|
-
day(): number;
|
|
44
|
-
hour(): number;
|
|
45
|
-
minute(): number;
|
|
46
|
-
second(): number;
|
|
47
|
-
millisecond(): number;
|
|
48
|
-
dayOfWeek(): number;
|
|
49
|
-
dayOfYear(): number;
|
|
50
|
-
weekOfYear(): number;
|
|
51
|
-
daysInMonth(): number;
|
|
52
|
-
daysInYear(): number;
|
|
53
|
-
inLeapYear(): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Calculate duration until another TimeGuard
|
|
56
|
-
*/
|
|
57
|
-
until(other: TimeGuard): {
|
|
58
|
-
years: number;
|
|
59
|
-
months: number;
|
|
60
|
-
days: number;
|
|
61
|
-
hours: number;
|
|
62
|
-
minutes: number;
|
|
63
|
-
seconds: number;
|
|
64
|
-
milliseconds: number;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Round to a specific unit with optional rounding mode
|
|
68
|
-
*/
|
|
69
|
-
round(options?: IRoundOptions): TimeGuard;
|
|
70
|
-
/**
|
|
71
|
-
* Convert to PlainDate (removes time information)
|
|
72
|
-
*/
|
|
73
|
-
toPlainDate(): {
|
|
74
|
-
year: number;
|
|
75
|
-
month: number;
|
|
76
|
-
day: number;
|
|
77
|
-
dayOfWeek: number;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Convert to PlainTime (removes date information)
|
|
81
|
-
*/
|
|
82
|
-
toPlainTime(): {
|
|
83
|
-
hour: number;
|
|
84
|
-
minute: number;
|
|
85
|
-
second: number;
|
|
86
|
-
millisecond: number;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Create new TimeGuard with only date, keeping time from parameter
|
|
90
|
-
*/
|
|
91
|
-
withDate(year: number, month: number, day: number): TimeGuard;
|
|
92
|
-
/**
|
|
93
|
-
* Create new TimeGuard with only time, keeping date
|
|
94
|
-
*/
|
|
95
|
-
withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
|
|
96
|
-
/**
|
|
97
|
-
* Get timezone offset in format ±HH:mm
|
|
98
|
-
*/
|
|
99
|
-
getOffset(): string;
|
|
100
|
-
/**
|
|
101
|
-
* Get timezone offset in nanoseconds
|
|
102
|
-
*/
|
|
103
|
-
getOffsetNanoseconds(): number;
|
|
104
|
-
/**
|
|
105
|
-
* Get timezone ID
|
|
106
|
-
*/
|
|
107
|
-
getTimeZoneId(): string | null;
|
|
108
|
-
/**
|
|
109
|
-
* Start of the day in current timezone
|
|
110
|
-
*/
|
|
111
|
-
startOfDay(): TimeGuard;
|
|
112
|
-
/**
|
|
113
|
-
* End of the day in current timezone
|
|
114
|
-
*/
|
|
115
|
-
endOfDay(): TimeGuard;
|
|
116
|
-
/**
|
|
117
|
-
* Calculate duration from another TimeGuard (inverse of until)
|
|
118
|
-
* Returns negative values if other is before this
|
|
119
|
-
*/
|
|
120
|
-
since(other: TimeGuard): {
|
|
121
|
-
years: number;
|
|
122
|
-
months: number;
|
|
123
|
-
days: number;
|
|
124
|
-
hours: number;
|
|
125
|
-
minutes: number;
|
|
126
|
-
seconds: number;
|
|
127
|
-
milliseconds: number;
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Get ISO 8601 duration string
|
|
131
|
-
* Example: P1Y2M3DT4H5M6S
|
|
132
|
-
*/
|
|
133
|
-
toDurationString(other?: TimeGuard): string;
|
|
134
|
-
/**
|
|
135
|
-
* Check if this date is in the past
|
|
136
|
-
*/
|
|
137
|
-
isPast(): boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Check if this date is in the future
|
|
140
|
-
*/
|
|
141
|
-
isFuture(): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Check if this date is today
|
|
144
|
-
*/
|
|
145
|
-
isToday(): boolean;
|
|
146
|
-
/**
|
|
147
|
-
* Check if this date is tomorrow
|
|
148
|
-
*/
|
|
149
|
-
isTomorrow(): boolean;
|
|
150
|
-
/**
|
|
151
|
-
* Check if this date is yesterday
|
|
152
|
-
*/
|
|
153
|
-
isYesterday(): boolean;
|
|
154
|
-
}
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TimeGuard - Core Types and Interfaces
|
|
3
|
-
* Following SOLID principles and TypeScript best practices
|
|
4
|
-
*
|
|
5
|
-
* Temporal types are provided natively by TypeScript (lib.esnext.temporal).
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Unit type for date/time operations
|
|
9
|
-
*/
|
|
10
|
-
export type Unit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond' | 'microsecond' | 'nanosecond';
|
|
11
|
-
/**
|
|
12
|
-
* Format preset strings for common patterns
|
|
13
|
-
*/
|
|
14
|
-
export type FormatPreset = 'iso' | 'date' | 'time' | 'datetime' | 'rfc2822' | 'rfc3339' | 'utc';
|
|
15
|
-
/**
|
|
16
|
-
* Duration-like object for arithmetic operations
|
|
17
|
-
*/
|
|
18
|
-
export interface IDuration {
|
|
19
|
-
years?: number;
|
|
20
|
-
months?: number;
|
|
21
|
-
weeks?: number;
|
|
22
|
-
days?: number;
|
|
23
|
-
hours?: number;
|
|
24
|
-
minutes?: number;
|
|
25
|
-
seconds?: number;
|
|
26
|
-
milliseconds?: number;
|
|
27
|
-
microseconds?: number;
|
|
28
|
-
nanoseconds?: number;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Round options for precision control
|
|
32
|
-
*/
|
|
33
|
-
export interface IRoundOptions {
|
|
34
|
-
smallestUnit?: Unit;
|
|
35
|
-
roundingMode?: 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfExpand' | 'halfFloor' | 'halfCeil' | 'halfTrunc';
|
|
36
|
-
roundingIncrement?: number;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Calendar system interface
|
|
40
|
-
*/
|
|
41
|
-
export interface ICalendarSystem {
|
|
42
|
-
id: string;
|
|
43
|
-
name: string;
|
|
44
|
-
locale?: string;
|
|
45
|
-
getMonthName(month: number, short?: boolean): string;
|
|
46
|
-
getWeekdayName(day: number, short?: boolean): string;
|
|
47
|
-
isLeapYear(year: number): boolean;
|
|
48
|
-
daysInMonth(year: number, month: number): number;
|
|
49
|
-
daysInYear(year: number): number;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Calendar manager interface
|
|
53
|
-
*/
|
|
54
|
-
export interface ICalendarManager {
|
|
55
|
-
register(calendar: ICalendarSystem): void;
|
|
56
|
-
get(id: string): ICalendarSystem | undefined;
|
|
57
|
-
list(): string[];
|
|
58
|
-
setDefault(id: string): void;
|
|
59
|
-
getDefault(): ICalendarSystem;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Locale configuration interface
|
|
63
|
-
*/
|
|
64
|
-
export interface ILocale {
|
|
65
|
-
name: string;
|
|
66
|
-
months: string[];
|
|
67
|
-
monthsShort: string[];
|
|
68
|
-
weekdays: string[];
|
|
69
|
-
weekdaysShort: string[];
|
|
70
|
-
weekdaysMin: string[];
|
|
71
|
-
meridiem?: {
|
|
72
|
-
am: string;
|
|
73
|
-
pm: string;
|
|
74
|
-
};
|
|
75
|
-
formats?: Record<string, string>;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Configuration options for TimeGuard instance
|
|
79
|
-
*/
|
|
80
|
-
export interface ITimeGuardConfig {
|
|
81
|
-
locale?: string;
|
|
82
|
-
timezone?: string;
|
|
83
|
-
strict?: boolean;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Interface for date/time parsing strategy (Strategy Pattern)
|
|
87
|
-
*/
|
|
88
|
-
export interface IDateParser {
|
|
89
|
-
parse(input: unknown): any | null;
|
|
90
|
-
canHandle(input: unknown): boolean;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Interface for date/time formatting (Strategy Pattern)
|
|
94
|
-
*/
|
|
95
|
-
export interface IDateFormatter {
|
|
96
|
-
format(date: any, pattern: string): string;
|
|
97
|
-
getPreset(preset: FormatPreset): string;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Interface for locale management (Single Responsibility)
|
|
101
|
-
*/
|
|
102
|
-
export interface ILocaleManager {
|
|
103
|
-
setLocale(locale: string, data?: ILocale): void;
|
|
104
|
-
getLocale(locale?: string): ILocale;
|
|
105
|
-
listLocales(): string[];
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Interface for arithmetic operations
|
|
109
|
-
*/
|
|
110
|
-
export interface IDateArithmetic {
|
|
111
|
-
add(units: Partial<Record<Unit, number>> | IDuration): TimeGuard;
|
|
112
|
-
subtract(units: Partial<Record<Unit, number>> | IDuration): TimeGuard;
|
|
113
|
-
diff(other: TimeGuard, unit?: Unit): number;
|
|
114
|
-
until(other: TimeGuard, options?: IRoundOptions): IDuration;
|
|
115
|
-
round(options: IRoundOptions): TimeGuard;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Interface for query operations
|
|
119
|
-
*/
|
|
120
|
-
export interface IDateQuery {
|
|
121
|
-
isBefore(other: TimeGuard): boolean;
|
|
122
|
-
isAfter(other: TimeGuard): boolean;
|
|
123
|
-
isSame(other: TimeGuard, unit?: Unit): boolean;
|
|
124
|
-
isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Interface for manipulation operations
|
|
128
|
-
*/
|
|
129
|
-
export interface IDateManipulation {
|
|
130
|
-
clone(): TimeGuard;
|
|
131
|
-
startOf(unit: Unit): TimeGuard;
|
|
132
|
-
endOf(unit: Unit): TimeGuard;
|
|
133
|
-
set(values: Partial<Record<Unit, number>>): TimeGuard;
|
|
134
|
-
year(): number;
|
|
135
|
-
month(): number;
|
|
136
|
-
day(): number;
|
|
137
|
-
hour(): number;
|
|
138
|
-
minute(): number;
|
|
139
|
-
second(): number;
|
|
140
|
-
millisecond(): number;
|
|
141
|
-
dayOfWeek(): number;
|
|
142
|
-
dayOfYear(): number;
|
|
143
|
-
weekOfYear(): number;
|
|
144
|
-
daysInMonth(): number;
|
|
145
|
-
daysInYear(): number;
|
|
146
|
-
inLeapYear(): boolean;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Interface for timezone operations
|
|
150
|
-
*/
|
|
151
|
-
export interface ITimezoneAdapter {
|
|
152
|
-
toTimezone(date: any, timezone: string): any;
|
|
153
|
-
fromTimezone(date: any, targetTimezone: string): any;
|
|
154
|
-
getOffset(timezone: string): number;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Main TimeGuard interface (Facade Pattern)
|
|
158
|
-
*/
|
|
159
|
-
export interface ITimeGuard extends IDateArithmetic, IDateQuery, IDateManipulation {
|
|
160
|
-
/**
|
|
161
|
-
* Get the underlying Temporal date object
|
|
162
|
-
*/
|
|
163
|
-
toTemporal(): any;
|
|
164
|
-
/**
|
|
165
|
-
* Get as JavaScript Date (compatibility)
|
|
166
|
-
*/
|
|
167
|
-
toDate(): Date;
|
|
168
|
-
/**
|
|
169
|
-
* Get as ISO string
|
|
170
|
-
*/
|
|
171
|
-
toISOString(): string;
|
|
172
|
-
/**
|
|
173
|
-
* Get as Unix timestamp (milliseconds)
|
|
174
|
-
*/
|
|
175
|
-
valueOf(): number;
|
|
176
|
-
/**
|
|
177
|
-
* Format the date with pattern or preset
|
|
178
|
-
*/
|
|
179
|
-
format(pattern: string | FormatPreset): string;
|
|
180
|
-
/**
|
|
181
|
-
* Get accessor for components
|
|
182
|
-
*/
|
|
183
|
-
get(component: Unit): number;
|
|
184
|
-
/**
|
|
185
|
-
* Locale of this instance
|
|
186
|
-
*/
|
|
187
|
-
locale(): string;
|
|
188
|
-
/**
|
|
189
|
-
* Clone with new locale
|
|
190
|
-
*/
|
|
191
|
-
locale(locale: string): TimeGuard;
|
|
192
|
-
/**
|
|
193
|
-
* Timezone info
|
|
194
|
-
*/
|
|
195
|
-
timezone(): string | null;
|
|
196
|
-
/**
|
|
197
|
-
* Convert to another timezone
|
|
198
|
-
*/
|
|
199
|
-
timezone(timezone: string): TimeGuard;
|
|
200
|
-
/**
|
|
201
|
-
* Get Unix timestamp in seconds
|
|
202
|
-
*/
|
|
203
|
-
unix(): number;
|
|
204
|
-
/**
|
|
205
|
-
* Convert to JSON
|
|
206
|
-
*/
|
|
207
|
-
toJSON(): string;
|
|
208
|
-
/**
|
|
209
|
-
* String representation
|
|
210
|
-
*/
|
|
211
|
-
toString(): string;
|
|
212
|
-
/**
|
|
213
|
-
* Convert to PlainDate object
|
|
214
|
-
*/
|
|
215
|
-
toPlainDate(): {
|
|
216
|
-
year: number;
|
|
217
|
-
month: number;
|
|
218
|
-
day: number;
|
|
219
|
-
dayOfWeek: number;
|
|
220
|
-
};
|
|
221
|
-
/**
|
|
222
|
-
* Convert to PlainTime object
|
|
223
|
-
*/
|
|
224
|
-
toPlainTime(): {
|
|
225
|
-
hour: number;
|
|
226
|
-
minute: number;
|
|
227
|
-
second: number;
|
|
228
|
-
millisecond: number;
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Get timezone offset (±HH:mm format or Z)
|
|
232
|
-
*/
|
|
233
|
-
getOffset(): string;
|
|
234
|
-
/**
|
|
235
|
-
* Get timezone offset in nanoseconds
|
|
236
|
-
*/
|
|
237
|
-
getOffsetNanoseconds(): number;
|
|
238
|
-
/**
|
|
239
|
-
* Get timezone ID
|
|
240
|
-
*/
|
|
241
|
-
getTimeZoneId(): string | null;
|
|
242
|
-
/**
|
|
243
|
-
* Start of day
|
|
244
|
-
*/
|
|
245
|
-
startOfDay(): TimeGuard;
|
|
246
|
-
/**
|
|
247
|
-
* End of day
|
|
248
|
-
*/
|
|
249
|
-
endOfDay(): TimeGuard;
|
|
250
|
-
/**
|
|
251
|
-
* Duration from another date (inverse of until)
|
|
252
|
-
*/
|
|
253
|
-
since(other: TimeGuard): IDuration;
|
|
254
|
-
/**
|
|
255
|
-
* ISO 8601 duration string (P1Y2M3DT4H5M6S)
|
|
256
|
-
*/
|
|
257
|
-
toDurationString(other?: TimeGuard): string;
|
|
258
|
-
/**
|
|
259
|
-
* Check if in past
|
|
260
|
-
*/
|
|
261
|
-
isPast(): boolean;
|
|
262
|
-
/**
|
|
263
|
-
* Check if in future
|
|
264
|
-
*/
|
|
265
|
-
isFuture(): boolean;
|
|
266
|
-
/**
|
|
267
|
-
* Check if today
|
|
268
|
-
*/
|
|
269
|
-
isToday(): boolean;
|
|
270
|
-
/**
|
|
271
|
-
* Check if tomorrow
|
|
272
|
-
*/
|
|
273
|
-
isTomorrow(): boolean;
|
|
274
|
-
/**
|
|
275
|
-
* Check if yesterday
|
|
276
|
-
*/
|
|
277
|
-
isYesterday(): boolean;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Plugin interface for extending functionality
|
|
281
|
-
*/
|
|
282
|
-
export interface ITimeGuardPlugin {
|
|
283
|
-
name: string;
|
|
284
|
-
version: string;
|
|
285
|
-
install(timeGuard: typeof TimeGuard, config?: unknown): void;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Factory interface
|
|
289
|
-
*/
|
|
290
|
-
export interface ITimeGuardFactory {
|
|
291
|
-
create(input?: unknown, config?: ITimeGuardConfig): ITimeGuard;
|
|
292
|
-
now(config?: ITimeGuardConfig): ITimeGuard;
|
|
293
|
-
fromTemporal(date: any, config?: ITimeGuardConfig): ITimeGuard;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Forward declaration for TimeGuard class
|
|
297
|
-
* Implementation is in ./time-guard.ts, exported via ./index.ts
|
|
298
|
-
*/
|
|
299
|
-
export declare class TimeGuard {
|
|
300
|
-
constructor(input?: unknown, config?: ITimeGuardConfig);
|
|
301
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|