@bereasoftware/time-guard 2.0.5 → 2.0.7
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 +0 -4
- package/README.md +0 -4
- package/dist/calendars/index.es.js +1 -1
- package/dist/locales/index.es.js +1 -1
- package/dist/plugins/advanced-format.es.js +1 -1
- package/dist/plugins/duration.es.js +1 -1
- package/dist/plugins/relative-time.es.js +1 -1
- package/dist/time-guard.cjs +1 -1
- package/dist/time-guard.es.js +3627 -144
- package/dist/time-guard.iife.js +1 -1
- package/dist/time-guard.umd.js +1 -1
- package/dist/types/adapters/temporal.adapter.d.ts +60 -0
- package/dist/types/calendars/calendar.manager.d.ts +52 -0
- package/dist/types/calendars/index.d.ts +81 -0
- package/dist/types/formatters/date.formatter.d.ts +21 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/locales/additional.locale.d.ts +5 -0
- package/dist/types/locales/asian.locale.d.ts +9 -0
- package/dist/types/locales/english.locale.d.ts +6 -0
- package/dist/types/locales/european.locale.d.ts +9 -0
- package/dist/types/locales/index.d.ts +17 -0
- package/dist/types/locales/locale.manager.d.ts +42 -0
- package/dist/types/locales/locales-data.d.ts +17 -0
- package/dist/types/locales/middle-eastern.locale.d.ts +5 -0
- package/dist/types/locales/nordic.locale.d.ts +6 -0
- package/dist/types/locales/romance.locale.d.ts +7 -0
- package/dist/types/locales/slavic.locale.d.ts +6 -0
- package/dist/types/locales/spanish.locale.d.ts +5 -0
- package/dist/types/plugins/advanced-format/index.d.ts +47 -0
- package/dist/types/plugins/duration/index.d.ts +107 -0
- package/dist/types/plugins/duration/types.d.ts +85 -0
- package/dist/types/plugins/index.d.ts +10 -0
- package/dist/types/plugins/manager.d.ts +58 -0
- package/dist/types/plugins/relative-time/index.d.ts +39 -0
- package/dist/types/plugins/relative-time/types.d.ts +27 -0
- package/dist/types/polyfill-loader.d.ts +5 -0
- package/dist/types/time-guard.d.ts +151 -1
- package/dist/types/types/index.d.ts +301 -0
- package/package.json +22 -31
- package/dist/full.cjs +0 -1
- package/dist/full.es.js +0 -4341
- package/dist/types/calendars.d.ts +0 -1
- package/dist/types/full.d.ts +0 -1
- package/dist/types/locales.d.ts +0 -1
- package/dist/types/plugins/advanced-format.d.ts +0 -2
- package/dist/types/plugins/duration.d.ts +0 -3
- package/dist/types/plugins/relative-time.d.ts +0 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ILocale } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Aggregated locale data from all modules
|
|
4
|
+
*/
|
|
5
|
+
export declare const ALL_LOCALES: Record<string, ILocale>;
|
|
6
|
+
/**
|
|
7
|
+
* Register all locales into a locale map
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerAllLocales(localeMap: Map<string, ILocale> | Record<string, ILocale>): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get all available locales
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAvailableLocales(): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Total locales count (minimum 40 required)
|
|
16
|
+
*/
|
|
17
|
+
export declare const LOCALES_COUNT = 40;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ILocale, ILocaleManager } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* English locale data
|
|
4
|
+
*/
|
|
5
|
+
export declare const EN_LOCALE: ILocale;
|
|
6
|
+
/**
|
|
7
|
+
* Spanish locale data (sample for i18n support)
|
|
8
|
+
*/
|
|
9
|
+
export declare const ES_LOCALE: ILocale;
|
|
10
|
+
/**
|
|
11
|
+
* Locale Manager - implements ILocaleManager
|
|
12
|
+
*/
|
|
13
|
+
export declare class LocaleManager implements ILocaleManager {
|
|
14
|
+
private static instance;
|
|
15
|
+
private locales;
|
|
16
|
+
private currentLocale;
|
|
17
|
+
/**
|
|
18
|
+
* Singleton pattern
|
|
19
|
+
*/
|
|
20
|
+
static getInstance(): LocaleManager;
|
|
21
|
+
private constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Set or register a locale
|
|
24
|
+
*/
|
|
25
|
+
setLocale(locale: string, data?: ILocale): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get locale information
|
|
28
|
+
*/
|
|
29
|
+
getLocale(locale?: string): ILocale;
|
|
30
|
+
/**
|
|
31
|
+
* List all registered locales
|
|
32
|
+
*/
|
|
33
|
+
listLocales(): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Get current locale
|
|
36
|
+
*/
|
|
37
|
+
getCurrentLocale(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Load multiple locales
|
|
40
|
+
*/
|
|
41
|
+
loadLocales(locales: Record<string, ILocale>): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ILocale } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Locale data record for all supported languages
|
|
4
|
+
*/
|
|
5
|
+
export declare const LOCALES_DATA: Record<string, ILocale>;
|
|
6
|
+
/**
|
|
7
|
+
* Dynamically register all locales
|
|
8
|
+
*/
|
|
9
|
+
export declare function registerAllLocales(localeMap: Map<string, ILocale> | Record<string, ILocale>): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get all available locales
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAvailableLocales(): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Total locales count
|
|
16
|
+
*/
|
|
17
|
+
export declare const LOCALES_COUNT: number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ILocale } from '../types';
|
|
2
|
+
export declare const SV_LOCALE_DATA: ILocale;
|
|
3
|
+
export declare const NB_LOCALE_DATA: ILocale;
|
|
4
|
+
export declare const DA_LOCALE_DATA: ILocale;
|
|
5
|
+
export declare const FI_LOCALE_DATA: ILocale;
|
|
6
|
+
export declare const NORDIC_LOCALES: Record<string, ILocale>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ILocale } from '../types';
|
|
2
|
+
export declare const FR_LOCALE_DATA: ILocale;
|
|
3
|
+
export declare const IT_LOCALE_DATA: ILocale;
|
|
4
|
+
export declare const PT_LOCALE_DATA: ILocale;
|
|
5
|
+
export declare const PT_BR_LOCALE_DATA: ILocale;
|
|
6
|
+
export declare const RO_LOCALE_DATA: ILocale;
|
|
7
|
+
export declare const ROMANCE_LOCALES: Record<string, ILocale>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ILocale } from '../types';
|
|
2
|
+
export declare const RU_LOCALE_DATA: ILocale;
|
|
3
|
+
export declare const PL_LOCALE_DATA: ILocale;
|
|
4
|
+
export declare const CS_LOCALE_DATA: ILocale;
|
|
5
|
+
export declare const SK_LOCALE_DATA: ILocale;
|
|
6
|
+
export declare const SLAVIC_LOCALES: Record<string, ILocale>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ITimeGuardPlugin } from '../../types';
|
|
2
|
+
import { TimeGuard } from '../../time-guard';
|
|
3
|
+
export declare class AdvancedFormatPlugin implements ITimeGuardPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
/**
|
|
7
|
+
* Install plugin into TimeGuard
|
|
8
|
+
*/
|
|
9
|
+
install(TimeGuardClass: typeof TimeGuard): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get ordinal suffix (1st, 2nd, 3rd, etc.)
|
|
12
|
+
*/
|
|
13
|
+
private getOrdinal;
|
|
14
|
+
/**
|
|
15
|
+
* Pad number with leading zeros
|
|
16
|
+
*/
|
|
17
|
+
private padNumber;
|
|
18
|
+
/**
|
|
19
|
+
* Get ISO week number
|
|
20
|
+
*/
|
|
21
|
+
private getISOWeek;
|
|
22
|
+
/**
|
|
23
|
+
* Get week of year (locale-based)
|
|
24
|
+
*/
|
|
25
|
+
private getWeekOfYear;
|
|
26
|
+
/**
|
|
27
|
+
* Get ISO week year
|
|
28
|
+
*/
|
|
29
|
+
private getISOWeekYear;
|
|
30
|
+
/**
|
|
31
|
+
* Get week year
|
|
32
|
+
*/
|
|
33
|
+
private getWeekYear;
|
|
34
|
+
/**
|
|
35
|
+
* Get timezone offset short form
|
|
36
|
+
*/
|
|
37
|
+
private getTimezoneOffset;
|
|
38
|
+
/**
|
|
39
|
+
* Get timezone offset long form
|
|
40
|
+
*/
|
|
41
|
+
private getTimezoneOffsetLong;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create and export default instance
|
|
45
|
+
*/
|
|
46
|
+
declare const _default: AdvancedFormatPlugin;
|
|
47
|
+
export default _default;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ITimeGuardPlugin } from '../../types';
|
|
2
|
+
import { TimeGuard } from '../../time-guard';
|
|
3
|
+
import { DurationInput, DurationObject, DurationUnit, IDuration } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Duration class - represents time span following ISO 8601 standard
|
|
6
|
+
*/
|
|
7
|
+
export declare class Duration implements IDuration {
|
|
8
|
+
private years;
|
|
9
|
+
private months;
|
|
10
|
+
private weeks;
|
|
11
|
+
private days;
|
|
12
|
+
private hours;
|
|
13
|
+
private minutes;
|
|
14
|
+
private seconds;
|
|
15
|
+
private milliseconds;
|
|
16
|
+
constructor(input: DurationInput);
|
|
17
|
+
/**
|
|
18
|
+
* Create Duration from ISO 8601 string
|
|
19
|
+
* @example Duration.fromISO("P3Y6M4DT12H30M5S")
|
|
20
|
+
*/
|
|
21
|
+
static fromISO(iso: string): Duration;
|
|
22
|
+
/**
|
|
23
|
+
* Create a Duration between this date and another
|
|
24
|
+
*/
|
|
25
|
+
static between(from: TimeGuard, to: TimeGuard): Duration;
|
|
26
|
+
/**
|
|
27
|
+
* Create Duration from milliseconds
|
|
28
|
+
*/
|
|
29
|
+
static fromMilliseconds(ms: number): Duration;
|
|
30
|
+
/**
|
|
31
|
+
* Get duration in specific unit
|
|
32
|
+
*/
|
|
33
|
+
as(unit: DurationUnit): number;
|
|
34
|
+
/**
|
|
35
|
+
* Get duration as milliseconds
|
|
36
|
+
*/
|
|
37
|
+
asMilliseconds(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get duration as seconds
|
|
40
|
+
*/
|
|
41
|
+
asSeconds(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Get duration as minutes
|
|
44
|
+
*/
|
|
45
|
+
asMinutes(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Get duration as hours
|
|
48
|
+
*/
|
|
49
|
+
asHours(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Get duration as days
|
|
52
|
+
*/
|
|
53
|
+
asDays(): number;
|
|
54
|
+
/**
|
|
55
|
+
* Get duration as weeks
|
|
56
|
+
*/
|
|
57
|
+
asWeeks(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Get duration as months
|
|
60
|
+
*/
|
|
61
|
+
asMonths(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Get duration as years
|
|
64
|
+
*/
|
|
65
|
+
asYears(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Get all components
|
|
68
|
+
*/
|
|
69
|
+
toObject(): DurationObject;
|
|
70
|
+
/**
|
|
71
|
+
* Get ISO 8601 string representation
|
|
72
|
+
* @example "P3Y6M4DT12H30M5S"
|
|
73
|
+
*/
|
|
74
|
+
toISO(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Get human-readable string
|
|
77
|
+
*/
|
|
78
|
+
humanize(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Check if duration is negative
|
|
81
|
+
*/
|
|
82
|
+
isNegative(): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Get absolute duration
|
|
85
|
+
*/
|
|
86
|
+
abs(): Duration;
|
|
87
|
+
/**
|
|
88
|
+
* String representation
|
|
89
|
+
*/
|
|
90
|
+
toString(): string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Duration Plugin
|
|
94
|
+
*/
|
|
95
|
+
export declare class DurationPlugin implements ITimeGuardPlugin {
|
|
96
|
+
name: string;
|
|
97
|
+
version: string;
|
|
98
|
+
/**
|
|
99
|
+
* Install plugin into TimeGuard
|
|
100
|
+
*/
|
|
101
|
+
install(TimeGuardClass: typeof TimeGuard): void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create and export default instance
|
|
105
|
+
*/
|
|
106
|
+
export declare const durationPlugin: DurationPlugin;
|
|
107
|
+
export default durationPlugin;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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';
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
import { ITimeGuard, ITimeGuardConfig, Unit, FormatPreset, IRoundOptions } from './types';
|
|
2
|
+
type DurationParts = {
|
|
3
|
+
years: number;
|
|
4
|
+
months: number;
|
|
5
|
+
days: number;
|
|
6
|
+
hours: number;
|
|
7
|
+
minutes: number;
|
|
8
|
+
seconds: number;
|
|
9
|
+
milliseconds: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* TimeGuard implementation - Main facade class
|
|
13
|
+
*/
|
|
14
|
+
export declare class TimeGuard implements ITimeGuard {
|
|
15
|
+
private temporal;
|
|
16
|
+
private config;
|
|
17
|
+
private formatterInstance;
|
|
18
|
+
private static readonly ZERO_DURATION;
|
|
19
|
+
private static isLeapYearValue;
|
|
20
|
+
private static toDurationParts;
|
|
21
|
+
constructor(input?: unknown, config?: ITimeGuardConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Static factory methods
|
|
24
|
+
*/
|
|
25
|
+
static now(config?: ITimeGuardConfig): TimeGuard;
|
|
26
|
+
static from(input: unknown, config?: ITimeGuardConfig): TimeGuard;
|
|
27
|
+
static fromTemporal(temporal: any, // Temporal.PlainDateTime | Temporal.ZonedDateTime
|
|
28
|
+
config?: ITimeGuardConfig): TimeGuard;
|
|
29
|
+
toTemporal(): any;
|
|
30
|
+
toDate(): Date;
|
|
31
|
+
toISOString(): string;
|
|
32
|
+
valueOf(): number;
|
|
33
|
+
unix(): number;
|
|
34
|
+
toJSON(): string;
|
|
35
|
+
toString(): string;
|
|
36
|
+
locale(): string;
|
|
37
|
+
locale(locale: string): TimeGuard;
|
|
38
|
+
timezone(): string | null;
|
|
39
|
+
timezone(timezone: string): TimeGuard;
|
|
40
|
+
format(pattern: string | FormatPreset): string;
|
|
41
|
+
get(component: Unit): number;
|
|
42
|
+
add(units: Partial<Record<Unit, number>>): TimeGuard;
|
|
43
|
+
subtract(units: Partial<Record<Unit, number>>): TimeGuard;
|
|
44
|
+
diff(other: TimeGuard, unit?: Unit): number;
|
|
45
|
+
isBefore(other: TimeGuard): boolean;
|
|
46
|
+
isAfter(other: TimeGuard): boolean;
|
|
47
|
+
isSame(other: TimeGuard, unit?: Unit): boolean;
|
|
48
|
+
isBetween(start: TimeGuard, end: TimeGuard, unit?: Unit, inclusivity?: '[)' | '()' | '[]' | '(]'): boolean;
|
|
49
|
+
clone(): TimeGuard;
|
|
50
|
+
startOf(unit: Unit): TimeGuard;
|
|
51
|
+
endOf(unit: Unit): TimeGuard;
|
|
52
|
+
set(values: Partial<Record<Unit, number>>): TimeGuard;
|
|
53
|
+
year(): number;
|
|
54
|
+
month(): number;
|
|
55
|
+
day(): number;
|
|
56
|
+
hour(): number;
|
|
57
|
+
minute(): number;
|
|
58
|
+
second(): number;
|
|
59
|
+
millisecond(): number;
|
|
60
|
+
dayOfWeek(): number;
|
|
61
|
+
dayOfYear(): number;
|
|
62
|
+
weekOfYear(): number;
|
|
63
|
+
daysInMonth(): number;
|
|
64
|
+
daysInYear(): number;
|
|
65
|
+
inLeapYear(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Calculate duration until another TimeGuard
|
|
68
|
+
*/
|
|
69
|
+
until(other: TimeGuard): DurationParts;
|
|
70
|
+
/**
|
|
71
|
+
* Round to a specific unit with optional rounding mode
|
|
72
|
+
*/
|
|
73
|
+
round(options?: IRoundOptions): TimeGuard;
|
|
74
|
+
/**
|
|
75
|
+
* Convert to PlainDate (removes time information)
|
|
76
|
+
*/
|
|
77
|
+
toPlainDate(): {
|
|
78
|
+
year: number;
|
|
79
|
+
month: number;
|
|
80
|
+
day: number;
|
|
81
|
+
dayOfWeek: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Convert to PlainTime (removes date information)
|
|
85
|
+
*/
|
|
86
|
+
toPlainTime(): {
|
|
87
|
+
hour: number;
|
|
88
|
+
minute: number;
|
|
89
|
+
second: number;
|
|
90
|
+
millisecond: number;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Create new TimeGuard with only date, keeping time from parameter
|
|
94
|
+
*/
|
|
95
|
+
withDate(year: number, month: number, day: number): TimeGuard;
|
|
96
|
+
/**
|
|
97
|
+
* Create new TimeGuard with only time, keeping date
|
|
98
|
+
*/
|
|
99
|
+
withTime(hour: number, minute?: number, second?: number, millisecond?: number): TimeGuard;
|
|
100
|
+
/**
|
|
101
|
+
* Get timezone offset in format ±HH:mm
|
|
102
|
+
*/
|
|
103
|
+
getOffset(): string;
|
|
104
|
+
/**
|
|
105
|
+
* Get timezone offset in nanoseconds
|
|
106
|
+
*/
|
|
107
|
+
getOffsetNanoseconds(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Get timezone ID
|
|
110
|
+
*/
|
|
111
|
+
getTimeZoneId(): string | null;
|
|
112
|
+
/**
|
|
113
|
+
* Start of the day in current timezone
|
|
114
|
+
*/
|
|
115
|
+
startOfDay(): TimeGuard;
|
|
116
|
+
/**
|
|
117
|
+
* End of the day in current timezone
|
|
118
|
+
*/
|
|
119
|
+
endOfDay(): TimeGuard;
|
|
120
|
+
/**
|
|
121
|
+
* Calculate duration from another TimeGuard (inverse of until)
|
|
122
|
+
* Returns negative values if other is before this
|
|
123
|
+
*/
|
|
124
|
+
since(other: TimeGuard): DurationParts;
|
|
125
|
+
/**
|
|
126
|
+
* Get ISO 8601 duration string
|
|
127
|
+
* Example: P1Y2M3DT4H5M6S
|
|
128
|
+
*/
|
|
129
|
+
toDurationString(other?: TimeGuard): string;
|
|
130
|
+
/**
|
|
131
|
+
* Check if this date is in the past
|
|
132
|
+
*/
|
|
133
|
+
isPast(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Check if this date is in the future
|
|
136
|
+
*/
|
|
137
|
+
isFuture(): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Check if this date is today
|
|
140
|
+
*/
|
|
141
|
+
isToday(): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if this date is tomorrow
|
|
144
|
+
*/
|
|
145
|
+
isTomorrow(): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Check if this date is yesterday
|
|
148
|
+
*/
|
|
149
|
+
isYesterday(): boolean;
|
|
150
|
+
}
|
|
151
|
+
export {};
|