@zelgadis87/utils-core 4.0.0
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/dist/Lazy.d.ts +21 -0
- package/dist/LazyAsync.d.ts +23 -0
- package/dist/Logger.d.ts +21 -0
- package/dist/Optional.d.ts +70 -0
- package/dist/async/CancelableDeferred.d.ts +17 -0
- package/dist/async/Deferred.d.ts +27 -0
- package/dist/async/RateThrottler.d.ts +12 -0
- package/dist/async/Semaphore.d.ts +10 -0
- package/dist/async/index.d.ts +4 -0
- package/dist/index.d.ts +11 -0
- package/dist/random/index.d.ts +2 -0
- package/dist/random/randomInterval.d.ts +1 -0
- package/dist/random/randomPercentage.d.ts +1 -0
- package/dist/sorting/ComparisonChain.d.ts +57 -0
- package/dist/sorting/Sorter.d.ts +100 -0
- package/dist/sorting/index.d.ts +4 -0
- package/dist/sorting/types.d.ts +5 -0
- package/dist/time/RandomTimeDuration.d.ts +9 -0
- package/dist/time/TimeBase.d.ts +38 -0
- package/dist/time/TimeDuration.d.ts +81 -0
- package/dist/time/TimeFrequency.d.ts +10 -0
- package/dist/time/TimeInstant.d.ts +137 -0
- package/dist/time/TimeInstantBuilder.d.ts +77 -0
- package/dist/time/TimeUnit.d.ts +17 -0
- package/dist/time/index.d.ts +6 -0
- package/dist/time/types.d.ts +26 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/arrays.d.ts +33 -0
- package/dist/types/booleans.d.ts +2 -0
- package/dist/types/functions.d.ts +20 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/json.d.ts +6 -0
- package/dist/types/nulls.d.ts +8 -0
- package/dist/types/numbers.d.ts +31 -0
- package/dist/types/promises.d.ts +6 -0
- package/dist/types/records.d.ts +14 -0
- package/dist/types/strings.d.ts +40 -0
- package/dist/upgrade/DataUpgrader.d.ts +22 -0
- package/dist/upgrade/errors.d.ts +12 -0
- package/dist/upgrade/getTransitionsPath.d.ts +3 -0
- package/dist/upgrade/index.d.ts +2 -0
- package/dist/upgrade/types.d.ts +31 -0
- package/dist/utils/asError.d.ts +1 -0
- package/dist/utils/bindThis.d.ts +1 -0
- package/dist/utils/constant.d.ts +8 -0
- package/dist/utils/entries.d.ts +4 -0
- package/dist/utils/groupBy.d.ts +7 -0
- package/dist/utils/iff.d.ts +8 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/indexBy.d.ts +7 -0
- package/dist/utils/jsonCloneDeep.d.ts +2 -0
- package/dist/utils/math.d.ts +9 -0
- package/dist/utils/noop.d.ts +1 -0
- package/dist/utils/omit.d.ts +2 -0
- package/dist/utils/pad.d.ts +3 -0
- package/dist/utils/pluralize.d.ts +1 -0
- package/dist/utils/round.d.ts +8 -0
- package/dist/utils/sortBy.d.ts +7 -0
- package/dist/utils/throttle.d.ts +3 -0
- package/dist/utils/uniq.d.ts +1 -0
- package/dist/utils/uniqBy.d.ts +2 -0
- package/dist/utils/uniqByKey.d.ts +1 -0
- package/dist/utils/upsert.d.ts +0 -0
- package/dist/utils/withTryCatch.d.ts +2 -0
- package/dist/utils/withTryCatchAsync.d.ts +2 -0
- package/dist/utils/wrap.d.ts +1 -0
- package/esbuild/index.cjs +2670 -0
- package/esbuild/index.mjs +2518 -0
- package/package.json +159 -0
- package/src/Lazy.ts +77 -0
- package/src/LazyAsync.ts +100 -0
- package/src/Logger.ts +44 -0
- package/src/Optional.ts +172 -0
- package/src/async/CancelableDeferred.ts +36 -0
- package/src/async/Deferred.ts +84 -0
- package/src/async/RateThrottler.ts +46 -0
- package/src/async/Semaphore.ts +45 -0
- package/src/async/index.ts +6 -0
- package/src/index.ts +13 -0
- package/src/random/index.ts +3 -0
- package/src/random/randomInterval.ts +4 -0
- package/src/random/randomPercentage.ts +6 -0
- package/src/sorting/ComparisonChain.ts +209 -0
- package/src/sorting/Sorter.ts +357 -0
- package/src/sorting/index.ts +5 -0
- package/src/sorting/types.ts +7 -0
- package/src/time/RandomTimeDuration.ts +21 -0
- package/src/time/TimeBase.ts +113 -0
- package/src/time/TimeDuration.ts +296 -0
- package/src/time/TimeFrequency.ts +28 -0
- package/src/time/TimeInstant.ts +488 -0
- package/src/time/TimeInstantBuilder.ts +126 -0
- package/src/time/TimeUnit.ts +43 -0
- package/src/time/index.ts +8 -0
- package/src/time/types.ts +56 -0
- package/src/types/arrays.ts +89 -0
- package/src/types/booleans.ts +8 -0
- package/src/types/functions.ts +27 -0
- package/src/types/index.ts +18 -0
- package/src/types/json.ts +5 -0
- package/src/types/nulls.ts +33 -0
- package/src/types/numbers.ts +80 -0
- package/src/types/promises.ts +23 -0
- package/src/types/records.ts +21 -0
- package/src/types/strings.ts +143 -0
- package/src/upgrade/DataUpgrader.ts +100 -0
- package/src/upgrade/errors.ts +25 -0
- package/src/upgrade/getTransitionsPath.ts +89 -0
- package/src/upgrade/index.ts +4 -0
- package/src/upgrade/types.ts +36 -0
- package/src/utils/asError.ts +12 -0
- package/src/utils/bindThis.ts +4 -0
- package/src/utils/constant.ts +9 -0
- package/src/utils/entries.ts +13 -0
- package/src/utils/groupBy.ts +39 -0
- package/src/utils/iff.ts +26 -0
- package/src/utils/index.ts +24 -0
- package/src/utils/indexBy.ts +36 -0
- package/src/utils/jsonCloneDeep.ts +31 -0
- package/src/utils/math.ts +44 -0
- package/src/utils/noop.ts +2 -0
- package/src/utils/omit.ts +8 -0
- package/src/utils/pad.ts +20 -0
- package/src/utils/pluralize.ts +20 -0
- package/src/utils/round.ts +24 -0
- package/src/utils/sortBy.ts +27 -0
- package/src/utils/throttle.ts +10 -0
- package/src/utils/uniq.ts +6 -0
- package/src/utils/uniqBy.ts +15 -0
- package/src/utils/uniqByKey.ts +5 -0
- package/src/utils/upsert.ts +2 -0
- package/src/utils/withTryCatch.ts +10 -0
- package/src/utils/withTryCatchAsync.ts +6 -0
- package/src/utils/wrap.ts +4 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import Deferred, { ICancelablePromise } from "../async/Deferred.js";
|
|
2
|
+
import { TComparisonResult } from "../sorting/index.js";
|
|
3
|
+
import { TTimeoutHandle, TVoidFunction } from "../types";
|
|
4
|
+
import { pad } from "../utils";
|
|
5
|
+
import TimeBase from "./TimeBase";
|
|
6
|
+
import TimeDuration from "./TimeDuration";
|
|
7
|
+
import { TTimeInstantBuilder, TTimeInstantCreationParameters, createTimeInstantFromParameters, timeInstantBuilder } from "./TimeInstantBuilder.js";
|
|
8
|
+
import TimeUnit from "./TimeUnit";
|
|
9
|
+
import { TDayOfMonth, TDayOfWeek, TFourDigitsMillisecond, TFourDigitsYear, TIso8601DateString, TIso8601DateUtcString, TMonth, TThreeDigitsMillisecond, TTwoDigitsDate, TTwoDigitsHour, TTwoDigitsMinute, TTwoDigitsMonth, TTwoDigitsSecond, TWeekNumber } from "./types";
|
|
10
|
+
|
|
11
|
+
export class TimeInstant extends TimeBase<TimeInstant> {
|
|
12
|
+
|
|
13
|
+
protected constructor( number: number, unit: TimeUnit ) {
|
|
14
|
+
super( number, unit );
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected create( value: number, unit: TimeUnit ) {
|
|
18
|
+
return new TimeInstant( value, unit );
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public addDuration( duration: TimeDuration ): TimeInstant {
|
|
22
|
+
return TimeInstant.fromUnixTimestamp( this.ms + duration.ms );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public removeDuration( duration: TimeDuration ): TimeInstant {
|
|
26
|
+
return TimeInstant.fromUnixTimestamp( this.ms - duration.ms );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public distanceFrom( instant: TimeInstant ): TimeDuration {
|
|
30
|
+
return TimeDuration.fromMs( Math.abs( this.ms - instant.ms ) );
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public distanceFromNow(): TimeDuration {
|
|
34
|
+
return TimeDuration.fromMs( Math.abs( this.ms - Date.now() ) );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public distanceFromStartOfDay(): TimeDuration {
|
|
38
|
+
return this.distanceFrom( this.atStartOfDay() );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public atStartOfDay(): TimeInstant {
|
|
42
|
+
return this.atTime( { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 } );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public distanceFromEndOfDay(): TimeDuration {
|
|
46
|
+
return this.distanceFrom( this.atEndOfDay() );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public atEndOfDay(): TimeInstant {
|
|
50
|
+
return this.atTime( { hours: 23, minutes: 59, seconds: 59, milliseconds: 999 } );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @deprecated[2024-10-24]: Use #promise() instead. */
|
|
54
|
+
public timeout( cb: () => unknown ): TTimeoutHandle {
|
|
55
|
+
if ( !this.isInTheFuture ) {
|
|
56
|
+
throw new Error( 'Instant is in the past' );
|
|
57
|
+
} else {
|
|
58
|
+
return this.distanceFromNow().timeout( () => cb() );
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public promise(): ICancelablePromise<void> {
|
|
63
|
+
const deferred = new Deferred<void>;
|
|
64
|
+
if ( !this.isInTheFuture ) {
|
|
65
|
+
deferred.resolve();
|
|
66
|
+
} else {
|
|
67
|
+
this.distanceFromNow().timeout( () => deferred.resolve() );
|
|
68
|
+
}
|
|
69
|
+
return deferred.asCancelablePromise;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public delay( cb: () => unknown ): { cancel: TVoidFunction } {
|
|
73
|
+
const deferred = this.promise();
|
|
74
|
+
void deferred.then( () => {
|
|
75
|
+
cb();
|
|
76
|
+
}, _err => {
|
|
77
|
+
return; // Do nothing on cancelation ( err is always an instance of DeferredCanceledError )
|
|
78
|
+
} );
|
|
79
|
+
return { cancel: () => deferred.cancel() };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public isToday(): boolean {
|
|
83
|
+
return Math.floor( this.days ) === Math.floor( TimeInstant.now().days );
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public asTimeString(): string {
|
|
87
|
+
const date = this.asDate();
|
|
88
|
+
return `${this.doGetTwoDigitsHours( date )}:${this.doGetTwoDigitsMinutes( date )}:${this.doGetTwoDigitsSeconds( date )}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public asDateString(): string {
|
|
92
|
+
const date = this.asDate();
|
|
93
|
+
return `${this.doGetTwoDigitsDays( date )}/${this.doGetTwoDigitsMonths( date )}/${this.doGetFourDigitsYears( date )}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public asIso8601(): TIso8601DateString {
|
|
97
|
+
const dash = '-', colon = '.', doublecolon = ':', T = 'T', date = this.asDate();
|
|
98
|
+
return (
|
|
99
|
+
this.doGetFourDigitsYears( date )
|
|
100
|
+
+ dash
|
|
101
|
+
+ this.doGetTwoDigitsMonths( date )
|
|
102
|
+
+ dash
|
|
103
|
+
+ this.doGetTwoDigitsDays( date )
|
|
104
|
+
+ T
|
|
105
|
+
+ this.doGetTwoDigitsHours( date )
|
|
106
|
+
+ doublecolon
|
|
107
|
+
+ this.doGetTwoDigitsMinutes( date )
|
|
108
|
+
+ doublecolon
|
|
109
|
+
+ this.doGetTwoDigitsSeconds( date )
|
|
110
|
+
+ colon
|
|
111
|
+
+ this.doGetThreeDigitsMilliseconds( date )
|
|
112
|
+
+ this.doGetFourDigitsTimezoneOffset( date )
|
|
113
|
+
) as TIso8601DateString;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public asIso8601UTC(): TIso8601DateUtcString {
|
|
117
|
+
const dash = '-', colon = '.', doublecolon = ':', T = 'T', utcDate = this.asDateUTC();
|
|
118
|
+
return (
|
|
119
|
+
this.doGetFourDigitsYears( utcDate )
|
|
120
|
+
+ dash
|
|
121
|
+
+ this.doGetTwoDigitsMonths( utcDate )
|
|
122
|
+
+ dash
|
|
123
|
+
+ this.doGetTwoDigitsDays( utcDate )
|
|
124
|
+
+ T
|
|
125
|
+
+ this.doGetTwoDigitsHours( utcDate )
|
|
126
|
+
+ doublecolon
|
|
127
|
+
+ this.doGetTwoDigitsMinutes( utcDate )
|
|
128
|
+
+ doublecolon
|
|
129
|
+
+ this.doGetTwoDigitsSeconds( utcDate )
|
|
130
|
+
+ colon
|
|
131
|
+
+ this.doGetThreeDigitsMilliseconds( utcDate )
|
|
132
|
+
+ 'Z'
|
|
133
|
+
) as TIso8601DateUtcString;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public asHumanTimestamp(): string {
|
|
137
|
+
const dash = '-', colon = '.', doublecolon = ':', T = 'T', date = this.asDate();
|
|
138
|
+
return (
|
|
139
|
+
this.doGetFourDigitsYears( date )
|
|
140
|
+
+ dash
|
|
141
|
+
+ this.doGetTwoDigitsMonths( date )
|
|
142
|
+
+ dash
|
|
143
|
+
+ this.doGetTwoDigitsDays( date )
|
|
144
|
+
+ T
|
|
145
|
+
+ this.doGetTwoDigitsHours( date )
|
|
146
|
+
+ doublecolon
|
|
147
|
+
+ this.doGetTwoDigitsMinutes( date )
|
|
148
|
+
+ doublecolon
|
|
149
|
+
+ this.doGetTwoDigitsSeconds( date )
|
|
150
|
+
+ colon
|
|
151
|
+
+ this.doGetThreeDigitsMilliseconds( date )
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
156
|
+
public get twoDigitsDays(): TTwoDigitsDate {
|
|
157
|
+
return this.doGetTwoDigitsDays( this.asDate() );
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
161
|
+
public get twoDigitsMonths(): TTwoDigitsMonth {
|
|
162
|
+
return this.doGetTwoDigitsMonths( this.asDate() );
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
166
|
+
public get fourDigitsYears(): TFourDigitsYear {
|
|
167
|
+
return this.doGetFourDigitsYears( this.asDate() );
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
171
|
+
public get twoDigitsHours(): TTwoDigitsHour {
|
|
172
|
+
return this.doGetTwoDigitsHours( this.asDate() );
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
176
|
+
public get twoDigitsMinutes(): TTwoDigitsMinute {
|
|
177
|
+
return this.doGetTwoDigitsMinutes( this.asDate() );
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
181
|
+
public get twoDigitsSeconds(): TTwoDigitsMinute {
|
|
182
|
+
return this.doGetTwoDigitsSeconds( this.asDate() );
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
186
|
+
public get threeDigitsMilliseconds(): TThreeDigitsMillisecond {
|
|
187
|
+
return this.doGetThreeDigitsMilliseconds( this.asDate() );
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
191
|
+
public get twoDigitsDaysUTC(): TTwoDigitsDate {
|
|
192
|
+
return this.doGetTwoDigitsDays( this.asDateUTC() );
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
196
|
+
public get twoDigitsMonthsUTC(): TTwoDigitsMonth {
|
|
197
|
+
return this.doGetTwoDigitsMonths( this.asDateUTC() );
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
201
|
+
public get fourDigitsYearsUTC(): TFourDigitsYear {
|
|
202
|
+
return this.doGetFourDigitsYears( this.asDateUTC() );
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
206
|
+
public get twoDigitsHoursUTC(): TTwoDigitsHour {
|
|
207
|
+
return this.doGetTwoDigitsHours( this.asDateUTC() );
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
211
|
+
public get twoDigitsMinutesUTC(): TTwoDigitsMinute {
|
|
212
|
+
return this.doGetTwoDigitsMinutes( this.asDateUTC() );
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
216
|
+
public get twoDigitsSecondsUTC(): TTwoDigitsSecond {
|
|
217
|
+
return this.doGetTwoDigitsSeconds( this.asDateUTC() );
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
221
|
+
public get threeDigitsMillisecondsUTC(): TThreeDigitsMillisecond {
|
|
222
|
+
return this.doGetThreeDigitsMilliseconds( this.asDateUTC() );
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Please do not use this method internally, as it is not optimized for continued usage.
|
|
226
|
+
public get fourDigitsTimezoneOffset(): TFourDigitsMillisecond {
|
|
227
|
+
const offset = this.asDate().getTimezoneOffset();
|
|
228
|
+
return ( ( offset >= 0 ? '+' : '-' )
|
|
229
|
+
+ pad( Math.floor( Math.abs( offset ) / 60 ).toString(), 2, '0' )
|
|
230
|
+
+ pad( ( Math.abs( offset ) % 60 ).toString(), 2, '0' )
|
|
231
|
+
) as TFourDigitsMillisecond;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
protected doGetTwoDigitsDays( date: Date ): TTwoDigitsDate {
|
|
235
|
+
return pad( date.getDate().toString(), 2, '0' ) as TTwoDigitsDate;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
protected doGetTwoDigitsMonths( date: Date ): TTwoDigitsMonth {
|
|
239
|
+
return pad( ( date.getMonth() + 1 ).toString(), 2, '0' ) as TTwoDigitsMonth;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
protected doGetFourDigitsYears( date: Date ): TFourDigitsYear {
|
|
243
|
+
return pad( date.getFullYear().toString(), 4, '0' ) as TFourDigitsYear;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
protected doGetTwoDigitsHours( date: Date ): TTwoDigitsHour {
|
|
247
|
+
return pad( date.getHours().toString(), 2, '0' ) as TTwoDigitsHour;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
protected doGetTwoDigitsMinutes( date: Date ): TTwoDigitsMinute {
|
|
251
|
+
return pad( date.getMinutes().toString(), 2, '0' ) as TTwoDigitsMinute;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
protected doGetTwoDigitsSeconds( date: Date ): TTwoDigitsMinute {
|
|
255
|
+
return pad( date.getSeconds().toString(), 2, '0' ) as TTwoDigitsMinute;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
protected doGetThreeDigitsMilliseconds( date: Date ): TThreeDigitsMillisecond {
|
|
259
|
+
return pad( date.getMilliseconds().toString(), 3, '0' ) as TThreeDigitsMillisecond;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
protected doGetFourDigitsTimezoneOffset( date: Date ): TFourDigitsMillisecond {
|
|
263
|
+
const offset = date.getTimezoneOffset();
|
|
264
|
+
return ( ( offset >= 0 ? '+' : '-' )
|
|
265
|
+
+ pad( Math.floor( Math.abs( offset ) / 60 ).toString(), 2, '0' )
|
|
266
|
+
+ pad( ( Math.abs( offset ) % 60 ).toString(), 2, '0' )
|
|
267
|
+
) as TFourDigitsMillisecond;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
public asUnixTimestamp(): number {
|
|
271
|
+
// Syntatic sugar for this.ms;
|
|
272
|
+
return this.ms;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
public asDate(): Date {
|
|
276
|
+
return new Date( this.ms );
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
public asDateUTC(): Date {
|
|
280
|
+
return new Date( this.ms + new Date().getTimezoneOffset() * 60 * 1000 );
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
public get isInThePast(): boolean {
|
|
284
|
+
return this.ms < Date.now();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public get isInTheFuture(): boolean {
|
|
288
|
+
return this.ms > Date.now();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public isAfter( other: TimeInstant ): boolean {
|
|
292
|
+
return this.ms > other.ms;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public isBefore( other: TimeInstant ): boolean {
|
|
296
|
+
return this.ms < other.ms;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public compareTo( other: TimeInstant ): TComparisonResult {
|
|
300
|
+
if ( this.ms === other.ms ) {
|
|
301
|
+
return 0;
|
|
302
|
+
} else if ( this.isBefore( other ) ) {
|
|
303
|
+
return -1;
|
|
304
|
+
} else {
|
|
305
|
+
return 1;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* @deprecated[04/07/2023]: Use distanceFromNow instead
|
|
311
|
+
*/
|
|
312
|
+
public fromNow(): TimeDuration {
|
|
313
|
+
return TimeDuration.ms( this.ms - Date.now() );
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @deprecated[04/07/2023]: Use distanceFrom instead
|
|
318
|
+
*/
|
|
319
|
+
public from( instant: TimeInstant ): TimeDuration {
|
|
320
|
+
return TimeDuration.ms( this.ms - instant.ms );
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated[04/07/2023]: Use distanceFromUnixTimestamp instead
|
|
325
|
+
*/
|
|
326
|
+
public fromTimestamp( timestamp: number ): TimeDuration {
|
|
327
|
+
return TimeDuration.ms( this.ms - timestamp );
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
public distanceFromUnixTimestamp( timestamp: number ): TimeDuration {
|
|
331
|
+
return TimeDuration.ms( this.ms - timestamp );
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
public atTime( parameters: Partial<TTimeInstantCreationParameters & { year: never; month: never; date: never; }> ) {
|
|
335
|
+
return TimeInstant.fromParameters( parameters, this );
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public atDate( parameters: Partial<TTimeInstantCreationParameters & { hours: never; minutes: never; seconds: never; milliseconds: never; }> ) {
|
|
339
|
+
return TimeInstant.fromParameters( parameters, this );
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
public at( parameters: Partial<TTimeInstantCreationParameters> ) {
|
|
343
|
+
return TimeInstant.fromParameters( parameters, this );
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
public isBetween( start: TimeInstant, end: TimeInstant ) {
|
|
347
|
+
return this.ms >= start.ms && this.ms <= end.ms;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
public static fromDate( date: Date ): TimeInstant {
|
|
351
|
+
return this.fromUnixTimestamp( date.getTime() );
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public static fromUnixTimestamp( unixTimestamp: number ): TimeInstant {
|
|
355
|
+
return new TimeInstant( unixTimestamp, TimeUnit.MILLISECONDS );
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public static fromUnixSeconds( unixSeconds: number ): TimeInstant {
|
|
359
|
+
return new TimeInstant( unixSeconds, TimeUnit.SECONDS );
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
public static fromParameters( parameters: Partial<TTimeInstantCreationParameters>, referenceDate?: Date | TimeInstant ): TimeInstant {
|
|
363
|
+
return createTimeInstantFromParameters( parameters, referenceDate );
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public static greatest( instant1: TimeInstant, instant2: TimeInstant ): TimeInstant {
|
|
367
|
+
return instant1.isAfter( instant2 ) ? instant1 : instant2;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
public static lowest( instant1: TimeInstant, instant2: TimeInstant ): TimeInstant {
|
|
371
|
+
return instant1.isBefore( instant2 ) ? instant1 : instant2;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
public static builder(): TTimeInstantBuilder {
|
|
375
|
+
return timeInstantBuilder();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* @deprecated[19/07/2023] Use {@link fromParameters} instead.
|
|
380
|
+
*/
|
|
381
|
+
public static fromUnits( { date, month, year, hours, minutes, seconds }: { date: number, month: number, year: number, hours?: number, minutes?: number, seconds?: number } ): TimeInstant {
|
|
382
|
+
const dt = Date.UTC( year, month - 1, date, hours ?? 0, minutes ?? 0, seconds ?? 0 );
|
|
383
|
+
if ( isNaN( dt ) )
|
|
384
|
+
throw new Error( `Unparseable date: ${date}, ${month}, ${year}, ${hours ?? '-'}, ${minutes ?? '-'}, ${seconds ?? '-'}` )
|
|
385
|
+
return TimeInstant.fromUnixTimestamp( dt );
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
public static fromIso8601( str: TIso8601DateString ) {
|
|
389
|
+
return TimeInstant.fromUnixTimestamp( new Date( str ).getTime() );
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
public static now(): TimeInstant {
|
|
393
|
+
return TimeInstant.fromUnixTimestamp( Date.now() );
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
public static get currentTimeStamp(): number {
|
|
397
|
+
return Date.now();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
public static compare( a: TimeInstant, b: TimeInstant ): TComparisonResult {
|
|
401
|
+
return a.compareTo( b );
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
public roundedToStartOf( unit: TimeUnit ) {
|
|
405
|
+
return TimeInstant.fromUnixTimestamp( this.ms - ( this.ms % unit.multiplier ) );
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
public roundedToEndOf( unit: TimeUnit ) {
|
|
409
|
+
return TimeInstant.fromUnixTimestamp( this.ms - ( this.ms % unit.multiplier ) + unit.toMs( 1 ) - 1 );
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
public roundedToNext( unit: TimeUnit, factor = 1 ) {
|
|
413
|
+
const unitMs = unit.toMs( factor );
|
|
414
|
+
const timestamp = Math.ceil( this.ms / unitMs ) * unitMs;
|
|
415
|
+
return TimeInstant.fromUnixTimestamp( timestamp );
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
public roundedToPrevious( unit: TimeUnit, factor = 1 ) {
|
|
419
|
+
const unitMs = unit.toMs( factor );
|
|
420
|
+
const timestamp = Math.floor( this.ms / unitMs ) * unitMs;
|
|
421
|
+
return TimeInstant.fromUnixTimestamp( timestamp );
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
public roundedTo( unit: TimeUnit, factor = 1 ) {
|
|
425
|
+
const unitMs = unit.toMs( factor );
|
|
426
|
+
const timestamp = Math.round( this.ms / unitMs ) * unitMs;
|
|
427
|
+
return TimeInstant.fromUnixTimestamp( timestamp );
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
public get dayOfMonth(): TDayOfMonth {
|
|
431
|
+
return this.asDate().getDate() as TDayOfMonth;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
public get dayOfWeek(): TDayOfWeek {
|
|
435
|
+
return this.asDate().getDay() + 1 as TDayOfWeek;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
public get month(): TMonth {
|
|
439
|
+
return this.asDate().getMonth() + 1 as TMonth;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
public get year(): number {
|
|
443
|
+
return this.asDate().getFullYear();
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Returns the week number represented by this instant, according to the ISO 8601 standard.
|
|
448
|
+
* Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
|
|
449
|
+
*/
|
|
450
|
+
public get weekNumber(): { weekNumber: TWeekNumber, year: number } {
|
|
451
|
+
/**
|
|
452
|
+
* According to the ISO 8601 Standard, week number 1 is defined as the week containing the 4th of january (or, equivalently, the week that contains the first Thursday of the year).
|
|
453
|
+
* As such, we basically have to count how many Thursdays there has been in this year.
|
|
454
|
+
* Please note that the thursdayOfThisWeek could be in the previous year.
|
|
455
|
+
*/
|
|
456
|
+
const date = this.asDate();
|
|
457
|
+
const oneDay = 1000 * 60 * 60 * 24;
|
|
458
|
+
const thursdayOfThisWeek = new Date( date.getFullYear(), date.getMonth(), date.getDate() + 4 - ( date.getDay() || 7 ), 14, 0, 0 );
|
|
459
|
+
const firstOfJanuary = new Date( thursdayOfThisWeek.getFullYear(), 0, 1, 14, 0, 0 );
|
|
460
|
+
const dayOfTheYear = Math.round( ( thursdayOfThisWeek.getTime() - firstOfJanuary.getTime() ) / oneDay );
|
|
461
|
+
const weekNumber = Math.floor( dayOfTheYear / 7 ) + 1;
|
|
462
|
+
return { weekNumber: weekNumber as TWeekNumber, year: thursdayOfThisWeek.getFullYear() };
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
|
|
467
|
+
*/
|
|
468
|
+
protected get _time() {
|
|
469
|
+
return this.asHumanTimestamp();
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
public override toString() {
|
|
473
|
+
return `${this.constructor.name}[${this.asHumanTimestamp()}]`;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public static ZERO: TimeInstant = TimeInstant.fromUnixTimestamp( 0 );
|
|
477
|
+
|
|
478
|
+
public static fromJSON( ms: number ) {
|
|
479
|
+
return TimeInstant.fromUnixTimestamp( ms );
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function isTimeInstant( x: unknown ): x is TimeInstant {
|
|
485
|
+
return x !== null && x !== undefined && x instanceof TimeInstant;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export default TimeInstant;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
|
|
2
|
+
import { TFunction } from "../types/functions.js";
|
|
3
|
+
import { ensureDefined } from "../types/nulls.js";
|
|
4
|
+
import { TimeInstant, isTimeInstant } from "./TimeInstant.js";
|
|
5
|
+
import { TDayOfMonth, THourOfDay, TMillisecondOfSecond, TMinuteOfHour, TMonth, TSecondOfMinute, TUpToTwoDigits } from "./types.js";
|
|
6
|
+
|
|
7
|
+
type TRelativeSignum = '+' | '-';
|
|
8
|
+
type TRelativeNumber = `${TRelativeSignum}${TUpToTwoDigits}`;
|
|
9
|
+
const isRelativeNumber = ( x: string ): x is TRelativeNumber => x !== undefined && x.length > 0 && ( x[ 0 ] === '+' || x[ 0 ] === '-' );
|
|
10
|
+
export type TTimeInstantCreationParameters = {
|
|
11
|
+
year: number | { absolute: number } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
12
|
+
month: TMonth | { absolute: TMonth } | keyof typeof monthNames | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
13
|
+
date: TDayOfMonth | { absolute: TDayOfMonth } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
14
|
+
hours: THourOfDay | { absolute: THourOfDay } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
15
|
+
minutes: TMinuteOfHour | { absolute: TMinuteOfHour } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
16
|
+
seconds: TSecondOfMinute | { absolute: TSecondOfMinute } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
17
|
+
milliseconds: TMillisecondOfSecond | { absolute: TMillisecondOfSecond } | TRelativeNumber | { relative: number, relativeTo: 'now' | TimeInstant } | 'next' | 'last' | 'current' | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const defaultTimeInstantCreationParameters: TTimeInstantCreationParameters = {
|
|
21
|
+
year: { relative: 0, relativeTo: 'now' },
|
|
22
|
+
month: { relative: 0, relativeTo: 'now' },
|
|
23
|
+
date: { relative: 0, relativeTo: 'now' },
|
|
24
|
+
hours: { relative: 0, relativeTo: 'now' },
|
|
25
|
+
minutes: { relative: 0, relativeTo: 'now' },
|
|
26
|
+
seconds: { relative: 0, relativeTo: 'now' },
|
|
27
|
+
milliseconds: { relative: 0, relativeTo: 'now' },
|
|
28
|
+
};
|
|
29
|
+
const timeInstantCreationRelativeAliases = {
|
|
30
|
+
current: 0,
|
|
31
|
+
last: -1,
|
|
32
|
+
next: +1,
|
|
33
|
+
} as const satisfies Record<string, number>;
|
|
34
|
+
const monthNames = {
|
|
35
|
+
january: 1,
|
|
36
|
+
february: 2,
|
|
37
|
+
march: 3,
|
|
38
|
+
april: 4,
|
|
39
|
+
may: 5,
|
|
40
|
+
june: 6,
|
|
41
|
+
july: 7,
|
|
42
|
+
august: 8,
|
|
43
|
+
september: 9,
|
|
44
|
+
october: 10,
|
|
45
|
+
november: 11,
|
|
46
|
+
december: 12,
|
|
47
|
+
} as const satisfies Record<string, number>;
|
|
48
|
+
type TAllowedTimeInstantCreationAlias = keyof typeof timeInstantCreationRelativeAliases;
|
|
49
|
+
type TAllowedTimeInstantCreationParameter = { absolute: number } | { relative: number, relativeTo?: TimeInstant | 'now' } | TAllowedTimeInstantCreationAlias | TRelativeNumber | keyof typeof monthNames | number | undefined;
|
|
50
|
+
const timeInstantResolveValue = ( getFromDate: TFunction<Date, number>, referenceDate: Date, x: TAllowedTimeInstantCreationParameter ): number => {
|
|
51
|
+
if ( x === undefined ) {
|
|
52
|
+
return getFromDate( referenceDate );
|
|
53
|
+
} else if ( typeof x === 'number' ) {
|
|
54
|
+
return x;
|
|
55
|
+
} else if ( typeof x === 'string' ) {
|
|
56
|
+
if ( isRelativeNumber( x ) ) {
|
|
57
|
+
return getFromDate( referenceDate ) + parseInt( x );
|
|
58
|
+
} else if ( x in timeInstantCreationRelativeAliases ) {
|
|
59
|
+
return getFromDate( referenceDate ) + timeInstantCreationRelativeAliases[ x ];
|
|
60
|
+
} else if ( x in monthNames ) {
|
|
61
|
+
return monthNames[x];
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error( 'Uparseable string detected: ' + x );
|
|
64
|
+
}
|
|
65
|
+
} else if ( "relative" in x ) {
|
|
66
|
+
const { relative, relativeTo } = x;
|
|
67
|
+
if ( relativeTo === undefined || relativeTo === 'now' ) {
|
|
68
|
+
return getFromDate( referenceDate ) + relative;
|
|
69
|
+
} else {
|
|
70
|
+
return getFromDate( relativeTo.asDateUTC() ) + relative;
|
|
71
|
+
}
|
|
72
|
+
} else if ( "absolute" in x ) {
|
|
73
|
+
return x.absolute
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error( 'Uparseable value detected: ' + x );
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const getFromDate = {
|
|
79
|
+
year: d => d.getFullYear(),
|
|
80
|
+
month: d => d.getMonth(),
|
|
81
|
+
date: d => d.getDate(),
|
|
82
|
+
hours: d => d.getHours(),
|
|
83
|
+
minutes: d => d.getMinutes(),
|
|
84
|
+
seconds: d => d.getSeconds(),
|
|
85
|
+
milliseconds: d => d.getMilliseconds(),
|
|
86
|
+
} as const satisfies Record<string, TFunction<Date, number>>;
|
|
87
|
+
const toReferenceDate = ( x: Date | TimeInstant ): Date => {
|
|
88
|
+
ensureDefined( x );
|
|
89
|
+
if ( isTimeInstant( x ) ) return x.asDateUTC();
|
|
90
|
+
return x;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function createTimeInstantFromParameters( aParameters: Partial<TTimeInstantCreationParameters>, aReferenceDate: TimeInstant | Date = TimeInstant.now() ): TimeInstant {
|
|
94
|
+
const { year, month, date, hours, minutes, seconds, milliseconds }: TTimeInstantCreationParameters = { ...defaultTimeInstantCreationParameters, ...aParameters };
|
|
95
|
+
const referenceDate = toReferenceDate( aReferenceDate );
|
|
96
|
+
const timestamp = Date.UTC(
|
|
97
|
+
timeInstantResolveValue( getFromDate.year, referenceDate, year ),
|
|
98
|
+
timeInstantResolveValue( getFromDate.month, referenceDate, month ),
|
|
99
|
+
timeInstantResolveValue( getFromDate.date, referenceDate, date ),
|
|
100
|
+
timeInstantResolveValue( getFromDate.hours, referenceDate, hours ),
|
|
101
|
+
timeInstantResolveValue( getFromDate.minutes, referenceDate, minutes ),
|
|
102
|
+
timeInstantResolveValue( getFromDate.seconds, referenceDate, seconds ),
|
|
103
|
+
timeInstantResolveValue( getFromDate.milliseconds, referenceDate, milliseconds )
|
|
104
|
+
);
|
|
105
|
+
if ( isNaN( timestamp ) )
|
|
106
|
+
throw new Error( `Unparseable date: ${JSON.stringify( aParameters )} }` );
|
|
107
|
+
return TimeInstant.fromUnixTimestamp( timestamp );
|
|
108
|
+
}
|
|
109
|
+
export function timeInstantBuilder() {
|
|
110
|
+
let referenceDate = TimeInstant.now().asDateUTC();
|
|
111
|
+
const value: TTimeInstantCreationParameters = { ...defaultTimeInstantCreationParameters };
|
|
112
|
+
const ret = {
|
|
113
|
+
year: ( x: TTimeInstantCreationParameters[ "year" ] ) => { value.year = x; return ret; },
|
|
114
|
+
month: ( x: TTimeInstantCreationParameters[ "month" ] ) => { value.month = x; return ret; },
|
|
115
|
+
date: ( x: TTimeInstantCreationParameters[ "date" ] ) => { value.date = x; return ret; },
|
|
116
|
+
hours: ( x: TTimeInstantCreationParameters[ "hours" ] ) => { value.hours = x; return ret; },
|
|
117
|
+
minutes: ( x: TTimeInstantCreationParameters[ "minutes" ] ) => { value.minutes = x; return ret; },
|
|
118
|
+
seconds: ( x: TTimeInstantCreationParameters[ "seconds" ] ) => { value.seconds = x; return ret; },
|
|
119
|
+
milliseconds: ( x: TTimeInstantCreationParameters[ "milliseconds" ] ) => { value.milliseconds = x; return ret; },
|
|
120
|
+
values: ( x: Partial<TTimeInstantCreationParameters> ) => { Object.keys( value ).forEach( key => value[key] = x[key] ?? value[key] ); return ret; },
|
|
121
|
+
relativeTo: ( x: TimeInstant | Date ) => { referenceDate = toReferenceDate( x ); return ret; },
|
|
122
|
+
build: () => createTimeInstantFromParameters( value, referenceDate ),
|
|
123
|
+
};
|
|
124
|
+
return ret;
|
|
125
|
+
}
|
|
126
|
+
export type TTimeInstantBuilder = ReturnType<typeof timeInstantBuilder>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
export default class TimeUnit {
|
|
3
|
+
|
|
4
|
+
private constructor(
|
|
5
|
+
public readonly multiplier: number
|
|
6
|
+
) { }
|
|
7
|
+
|
|
8
|
+
public toUnit( value: number, unit: TimeUnit ): number {
|
|
9
|
+
return value * ( this.multiplier / unit.multiplier );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public toMs( value: number ): number {
|
|
13
|
+
return this.toUnit( value, TimeUnit.MILLISECONDS );
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public toSeconds( value: number ): number {
|
|
17
|
+
return this.toUnit( value, TimeUnit.SECONDS );
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public toMinutes( value: number ): number {
|
|
21
|
+
return this.toUnit( value, TimeUnit.MINUTES );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public toHours( value: number ): number {
|
|
25
|
+
return this.toUnit( value, TimeUnit.HOURS );
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public toDays( value: number ): number {
|
|
29
|
+
return this.toUnit( value, TimeUnit.DAYS );
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public toWeeks( value: number ): number {
|
|
33
|
+
return this.toUnit( value, TimeUnit.WEEKS );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static readonly MILLISECONDS = new TimeUnit( 1 );
|
|
37
|
+
public static readonly SECONDS = new TimeUnit( 1000 * TimeUnit.MILLISECONDS.multiplier );
|
|
38
|
+
public static readonly MINUTES = new TimeUnit( 60 * TimeUnit.SECONDS.multiplier );
|
|
39
|
+
public static readonly HOURS = new TimeUnit( 60 * TimeUnit.MINUTES.multiplier );
|
|
40
|
+
public static readonly DAYS = new TimeUnit( 24 * TimeUnit.HOURS.multiplier );
|
|
41
|
+
public static readonly WEEKS = new TimeUnit( 7 * TimeUnit.DAYS.multiplier );
|
|
42
|
+
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
export { default as RandomTimeDuration } from './RandomTimeDuration';
|
|
3
|
+
export { TPredefinedTimeDuration, TValidTimeDuration, TimeDuration, isAllowedTimeDuration } from './TimeDuration';
|
|
4
|
+
export { default as TimeFrequency } from './TimeFrequency';
|
|
5
|
+
export * from './TimeInstant';
|
|
6
|
+
export { default as TimeUnit } from './TimeUnit';
|
|
7
|
+
export * from './types';
|
|
8
|
+
|