@naturalcycles/js-lib 14.155.1 → 14.156.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/datetime/dateInterval.d.ts +3 -3
- package/dist/datetime/localDate.d.ts +18 -18
- package/dist/datetime/localTime.d.ts +21 -21
- package/dist/datetime/timeInterval.d.ts +3 -3
- package/package.json +1 -1
- package/src/datetime/dateInterval.ts +3 -3
- package/src/datetime/localDate.ts +19 -19
- package/src/datetime/localTime.ts +21 -21
- package/src/datetime/timeInterval.ts +3 -3
- package/src/http/fetcher.ts +1 -1
- package/src/__exclude/lazyLocalDate.ts +0 -73
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Inclusiveness,
|
|
1
|
+
import type { Inclusiveness, LocalDateInput, LocalDateUnit } from './localDate';
|
|
2
2
|
import { LocalDate } from './localDate';
|
|
3
3
|
export type DateIntervalConfig = DateInterval | DateIntervalString;
|
|
4
4
|
export type DateIntervalString = string;
|
|
@@ -11,7 +11,7 @@ export declare class DateInterval {
|
|
|
11
11
|
start: LocalDate;
|
|
12
12
|
end: LocalDate;
|
|
13
13
|
private constructor();
|
|
14
|
-
static of(start:
|
|
14
|
+
static of(start: LocalDateInput, end: LocalDateInput): DateInterval;
|
|
15
15
|
/**
|
|
16
16
|
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
17
17
|
*/
|
|
@@ -24,7 +24,7 @@ export declare class DateInterval {
|
|
|
24
24
|
/**
|
|
25
25
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
26
26
|
*/
|
|
27
|
-
includes(d:
|
|
27
|
+
includes(d: LocalDateInput, incl?: Inclusiveness): boolean;
|
|
28
28
|
intersects(int: DateIntervalConfig, inclusive?: boolean): boolean;
|
|
29
29
|
/**
|
|
30
30
|
* DateIntervals compare by start date.
|
|
@@ -3,7 +3,7 @@ import { LocalTime } from './localTime';
|
|
|
3
3
|
export type LocalDateUnit = LocalDateUnitStrict | 'week';
|
|
4
4
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day';
|
|
5
5
|
export type Inclusiveness = '()' | '[]' | '[)' | '(]';
|
|
6
|
-
export type
|
|
6
|
+
export type LocalDateInput = LocalDate | Date | IsoDateString;
|
|
7
7
|
export type LocalDateFormatter = (ld: LocalDate) => string;
|
|
8
8
|
/**
|
|
9
9
|
* @experimental
|
|
@@ -18,23 +18,23 @@ export declare class LocalDate {
|
|
|
18
18
|
* Parses input String into LocalDate.
|
|
19
19
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
20
20
|
*/
|
|
21
|
-
static of(d:
|
|
21
|
+
static of(d: LocalDateInput): LocalDate;
|
|
22
22
|
static parseCompact(d: string): LocalDate;
|
|
23
23
|
static fromDate(d: Date): LocalDate;
|
|
24
24
|
static fromDateUTC(d: Date): LocalDate;
|
|
25
25
|
/**
|
|
26
26
|
* Returns null if invalid.
|
|
27
27
|
*/
|
|
28
|
-
static parseOrNull(d:
|
|
28
|
+
static parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null;
|
|
29
29
|
static isValid(iso: string | undefined | null): boolean;
|
|
30
30
|
static today(): LocalDate;
|
|
31
31
|
static todayUTC(): LocalDate;
|
|
32
32
|
static sort(items: LocalDate[], mutate?: boolean, descending?: boolean): LocalDate[];
|
|
33
|
-
static earliestOrUndefined(items:
|
|
34
|
-
static earliest(items:
|
|
35
|
-
static latestOrUndefined(items:
|
|
36
|
-
static latest(items:
|
|
37
|
-
static range(min:
|
|
33
|
+
static earliestOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
34
|
+
static earliest(items: LocalDateInput[]): LocalDate;
|
|
35
|
+
static latestOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
36
|
+
static latest(items: LocalDateInput[]): LocalDate;
|
|
37
|
+
static range(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): LocalDate[];
|
|
38
38
|
get(unit: LocalDateUnitStrict): number;
|
|
39
39
|
set(unit: LocalDateUnitStrict, v: number, mutate?: boolean): LocalDate;
|
|
40
40
|
year(): number;
|
|
@@ -43,28 +43,28 @@ export declare class LocalDate {
|
|
|
43
43
|
month(v: number): LocalDate;
|
|
44
44
|
day(): number;
|
|
45
45
|
day(v: number): LocalDate;
|
|
46
|
-
isSame(d:
|
|
47
|
-
isBefore(d:
|
|
48
|
-
isSameOrBefore(d:
|
|
49
|
-
isAfter(d:
|
|
50
|
-
isSameOrAfter(d:
|
|
51
|
-
isBetween(min:
|
|
46
|
+
isSame(d: LocalDateInput): boolean;
|
|
47
|
+
isBefore(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
48
|
+
isSameOrBefore(d: LocalDateInput): boolean;
|
|
49
|
+
isAfter(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
50
|
+
isSameOrAfter(d: LocalDateInput): boolean;
|
|
51
|
+
isBetween(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness): boolean;
|
|
52
52
|
/**
|
|
53
53
|
* Returns 1 if this > d
|
|
54
54
|
* returns 0 if they are equal
|
|
55
55
|
* returns -1 if this < d
|
|
56
56
|
*/
|
|
57
|
-
cmp(d:
|
|
57
|
+
cmp(d: LocalDateInput): -1 | 0 | 1;
|
|
58
58
|
/**
|
|
59
59
|
* Same as Math.abs( diff )
|
|
60
60
|
*/
|
|
61
|
-
absDiff(d:
|
|
61
|
+
absDiff(d: LocalDateInput, unit: LocalDateUnit): number;
|
|
62
62
|
/**
|
|
63
63
|
* Returns the number of **full** units difference (aka `Math.floor`).
|
|
64
64
|
*
|
|
65
65
|
* a.diff(b) means "a minus b"
|
|
66
66
|
*/
|
|
67
|
-
diff(d:
|
|
67
|
+
diff(d: LocalDateInput, unit: LocalDateUnit): number;
|
|
68
68
|
add(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
|
|
69
69
|
subtract(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
|
|
70
70
|
startOf(unit: LocalDateUnitStrict): LocalDate;
|
|
@@ -96,4 +96,4 @@ export declare class LocalDate {
|
|
|
96
96
|
/**
|
|
97
97
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
98
98
|
*/
|
|
99
|
-
export declare function localDate(d?:
|
|
99
|
+
export declare function localDate(d?: LocalDateInput): LocalDate;
|
|
@@ -11,7 +11,7 @@ export declare enum ISODayOfWeek {
|
|
|
11
11
|
SATURDAY = 6,
|
|
12
12
|
SUNDAY = 7
|
|
13
13
|
}
|
|
14
|
-
export type
|
|
14
|
+
export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestampNumber;
|
|
15
15
|
export type LocalTimeFormatter = (ld: LocalTime) => string;
|
|
16
16
|
export interface LocalTimeComponents {
|
|
17
17
|
year: number;
|
|
@@ -31,7 +31,7 @@ export declare class LocalTime {
|
|
|
31
31
|
* Parses input String into LocalDate.
|
|
32
32
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
33
33
|
*/
|
|
34
|
-
static of(d:
|
|
34
|
+
static of(d: LocalTimeInput): LocalTime;
|
|
35
35
|
/**
|
|
36
36
|
* Create LocalTime from unixTimestamp in milliseconds (not in seconds).
|
|
37
37
|
*/
|
|
@@ -39,10 +39,10 @@ export declare class LocalTime {
|
|
|
39
39
|
/**
|
|
40
40
|
* Returns null if invalid
|
|
41
41
|
*/
|
|
42
|
-
static parseOrNull(d:
|
|
43
|
-
static parseToDate(d:
|
|
44
|
-
static parseToUnixTimestamp(d:
|
|
45
|
-
static isValid(d:
|
|
42
|
+
static parseOrNull(d: LocalTimeInput | undefined | null): LocalTime | null;
|
|
43
|
+
static parseToDate(d: LocalTimeInput): Date;
|
|
44
|
+
static parseToUnixTimestamp(d: LocalTimeInput): UnixTimestampNumber;
|
|
45
|
+
static isValid(d: LocalTimeInput | undefined | null): boolean;
|
|
46
46
|
static now(): LocalTime;
|
|
47
47
|
static fromComponents(c: {
|
|
48
48
|
year: number;
|
|
@@ -72,29 +72,29 @@ export declare class LocalTime {
|
|
|
72
72
|
setComponents(c: Partial<LocalTimeComponents>, mutate?: boolean): LocalTime;
|
|
73
73
|
add(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
74
74
|
subtract(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
75
|
-
absDiff(other:
|
|
76
|
-
diff(other:
|
|
75
|
+
absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number;
|
|
76
|
+
diff(other: LocalTimeInput, unit: LocalTimeUnit): number;
|
|
77
77
|
startOf(unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
78
78
|
endOf(unit: LocalTimeUnit, mutate?: boolean): LocalTime;
|
|
79
79
|
static sort(items: LocalTime[], mutate?: boolean, descending?: boolean): LocalTime[];
|
|
80
|
-
static earliestOrUndefined(items:
|
|
81
|
-
static earliest(items:
|
|
82
|
-
static latestOrUndefined(items:
|
|
83
|
-
static latest(items:
|
|
84
|
-
isSame(d:
|
|
85
|
-
isBefore(d:
|
|
86
|
-
isSameOrBefore(d:
|
|
87
|
-
isAfter(d:
|
|
88
|
-
isSameOrAfter(d:
|
|
89
|
-
isBetween(min:
|
|
80
|
+
static earliestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined;
|
|
81
|
+
static earliest(items: LocalTimeInput[]): LocalTime;
|
|
82
|
+
static latestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined;
|
|
83
|
+
static latest(items: LocalTimeInput[]): LocalTime;
|
|
84
|
+
isSame(d: LocalTimeInput): boolean;
|
|
85
|
+
isBefore(d: LocalTimeInput, inclusive?: boolean): boolean;
|
|
86
|
+
isSameOrBefore(d: LocalTimeInput): boolean;
|
|
87
|
+
isAfter(d: LocalTimeInput, inclusive?: boolean): boolean;
|
|
88
|
+
isSameOrAfter(d: LocalTimeInput): boolean;
|
|
89
|
+
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl?: Inclusiveness): boolean;
|
|
90
90
|
/**
|
|
91
91
|
* Returns 1 if this > d
|
|
92
92
|
* returns 0 if they are equal
|
|
93
93
|
* returns -1 if this < d
|
|
94
94
|
*/
|
|
95
|
-
cmp(d:
|
|
95
|
+
cmp(d: LocalTimeInput): -1 | 0 | 1;
|
|
96
96
|
components(): LocalTimeComponents;
|
|
97
|
-
fromNow(now?:
|
|
97
|
+
fromNow(now?: LocalTimeInput): string;
|
|
98
98
|
getDate(): Date;
|
|
99
99
|
clone(): LocalTime;
|
|
100
100
|
unix(): UnixTimestampNumber;
|
|
@@ -125,4 +125,4 @@ export declare class LocalTime {
|
|
|
125
125
|
/**
|
|
126
126
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
127
127
|
*/
|
|
128
|
-
export declare function localTime(d?:
|
|
128
|
+
export declare function localTime(d?: LocalTimeInput): LocalTime;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnixTimestampNumber } from '../types';
|
|
2
2
|
import type { Inclusiveness } from './localDate';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LocalTimeInput } from './localTime';
|
|
4
4
|
import { LocalTime } from './localTime';
|
|
5
5
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString;
|
|
6
6
|
export type TimeIntervalString = string;
|
|
@@ -14,7 +14,7 @@ export declare class TimeInterval {
|
|
|
14
14
|
private $start;
|
|
15
15
|
private $end;
|
|
16
16
|
private constructor();
|
|
17
|
-
static of(start:
|
|
17
|
+
static of(start: LocalTimeInput, end: LocalTimeInput): TimeInterval;
|
|
18
18
|
get start(): UnixTimestampNumber;
|
|
19
19
|
get end(): UnixTimestampNumber;
|
|
20
20
|
get startTime(): LocalTime;
|
|
@@ -28,7 +28,7 @@ export declare class TimeInterval {
|
|
|
28
28
|
isSameOrBefore(d: TimeIntervalConfig): boolean;
|
|
29
29
|
isAfter(d: TimeIntervalConfig, inclusive?: boolean): boolean;
|
|
30
30
|
isSameOrAfter(d: TimeIntervalConfig): boolean;
|
|
31
|
-
includes(d:
|
|
31
|
+
includes(d: LocalTimeInput, incl?: Inclusiveness): boolean;
|
|
32
32
|
/**
|
|
33
33
|
* TimeIntervals compare by start date.
|
|
34
34
|
* If it's the same - then by end date.
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Inclusiveness,
|
|
1
|
+
import type { Inclusiveness, LocalDateInput, LocalDateUnit } from './localDate'
|
|
2
2
|
import { LocalDate } from './localDate'
|
|
3
3
|
|
|
4
4
|
export type DateIntervalConfig = DateInterval | DateIntervalString
|
|
@@ -15,7 +15,7 @@ export class DateInterval {
|
|
|
15
15
|
public end: LocalDate,
|
|
16
16
|
) {}
|
|
17
17
|
|
|
18
|
-
static of(start:
|
|
18
|
+
static of(start: LocalDateInput, end: LocalDateInput): DateInterval {
|
|
19
19
|
return new DateInterval(LocalDate.of(start), LocalDate.of(end))
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -59,7 +59,7 @@ export class DateInterval {
|
|
|
59
59
|
/**
|
|
60
60
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
61
61
|
*/
|
|
62
|
-
includes(d:
|
|
62
|
+
includes(d: LocalDateInput, incl: Inclusiveness = '[]'): boolean {
|
|
63
63
|
d = LocalDate.of(d)
|
|
64
64
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
65
65
|
return d.isAfter(this.start, incl[0] === '[') && d.isBefore(this.end, incl[1] === ']')
|
|
@@ -14,7 +14,7 @@ export type Inclusiveness = '()' | '[]' | '[)' | '(]'
|
|
|
14
14
|
const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
15
15
|
const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
|
|
16
16
|
|
|
17
|
-
export type
|
|
17
|
+
export type LocalDateInput = LocalDate | Date | IsoDateString
|
|
18
18
|
export type LocalDateFormatter = (ld: LocalDate) => string
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -35,7 +35,7 @@ export class LocalDate {
|
|
|
35
35
|
* Parses input String into LocalDate.
|
|
36
36
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
37
37
|
*/
|
|
38
|
-
static of(d:
|
|
38
|
+
static of(d: LocalDateInput): LocalDate {
|
|
39
39
|
const t = this.parseOrNull(d)
|
|
40
40
|
|
|
41
41
|
if (t === null) {
|
|
@@ -66,7 +66,7 @@ export class LocalDate {
|
|
|
66
66
|
/**
|
|
67
67
|
* Returns null if invalid.
|
|
68
68
|
*/
|
|
69
|
-
static parseOrNull(d:
|
|
69
|
+
static parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null {
|
|
70
70
|
if (!d) return null
|
|
71
71
|
if (d instanceof LocalDate) return d
|
|
72
72
|
if (d instanceof Date) {
|
|
@@ -118,11 +118,11 @@ export class LocalDate {
|
|
|
118
118
|
return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
static earliestOrUndefined(items:
|
|
121
|
+
static earliestOrUndefined(items: LocalDateInput[]): LocalDate | undefined {
|
|
122
122
|
return items.length ? LocalDate.earliest(items) : undefined
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
static earliest(items:
|
|
125
|
+
static earliest(items: LocalDateInput[]): LocalDate {
|
|
126
126
|
_assert(items.length, 'LocalDate.earliest called on empty array')
|
|
127
127
|
|
|
128
128
|
return items
|
|
@@ -130,11 +130,11 @@ export class LocalDate {
|
|
|
130
130
|
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item))
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
static latestOrUndefined(items:
|
|
133
|
+
static latestOrUndefined(items: LocalDateInput[]): LocalDate | undefined {
|
|
134
134
|
return items.length ? LocalDate.latest(items) : undefined
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
static latest(items:
|
|
137
|
+
static latest(items: LocalDateInput[]): LocalDate {
|
|
138
138
|
_assert(items.length, 'LocalDate.latest called on empty array')
|
|
139
139
|
|
|
140
140
|
return items
|
|
@@ -143,8 +143,8 @@ export class LocalDate {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
static range(
|
|
146
|
-
min:
|
|
147
|
-
max:
|
|
146
|
+
min: LocalDateInput,
|
|
147
|
+
max: LocalDateInput,
|
|
148
148
|
incl: Inclusiveness = '[)',
|
|
149
149
|
step = 1,
|
|
150
150
|
stepUnit: LocalDateUnit = 'day',
|
|
@@ -209,30 +209,30 @@ export class LocalDate {
|
|
|
209
209
|
return v === undefined ? this.$day : this.set('day', v)
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
isSame(d:
|
|
212
|
+
isSame(d: LocalDateInput): boolean {
|
|
213
213
|
d = LocalDate.of(d)
|
|
214
214
|
return this.$day === d.$day && this.$month === d.$month && this.$year === d.$year
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
isBefore(d:
|
|
217
|
+
isBefore(d: LocalDateInput, inclusive = false): boolean {
|
|
218
218
|
const r = this.cmp(d)
|
|
219
219
|
return r === -1 || (r === 0 && inclusive)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
isSameOrBefore(d:
|
|
222
|
+
isSameOrBefore(d: LocalDateInput): boolean {
|
|
223
223
|
return this.cmp(d) <= 0
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
isAfter(d:
|
|
226
|
+
isAfter(d: LocalDateInput, inclusive = false): boolean {
|
|
227
227
|
const r = this.cmp(d)
|
|
228
228
|
return r === 1 || (r === 0 && inclusive)
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
isSameOrAfter(d:
|
|
231
|
+
isSameOrAfter(d: LocalDateInput): boolean {
|
|
232
232
|
return this.cmp(d) >= 0
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
isBetween(min:
|
|
235
|
+
isBetween(min: LocalDateInput, max: LocalDateInput, incl: Inclusiveness = '[)'): boolean {
|
|
236
236
|
let r = this.cmp(min)
|
|
237
237
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
238
238
|
if (r < 0 || (r === 0 && incl[0] === '(')) return false
|
|
@@ -246,7 +246,7 @@ export class LocalDate {
|
|
|
246
246
|
* returns 0 if they are equal
|
|
247
247
|
* returns -1 if this < d
|
|
248
248
|
*/
|
|
249
|
-
cmp(d:
|
|
249
|
+
cmp(d: LocalDateInput): -1 | 0 | 1 {
|
|
250
250
|
d = LocalDate.of(d)
|
|
251
251
|
if (this.$year < d.$year) return -1
|
|
252
252
|
if (this.$year > d.$year) return 1
|
|
@@ -260,7 +260,7 @@ export class LocalDate {
|
|
|
260
260
|
/**
|
|
261
261
|
* Same as Math.abs( diff )
|
|
262
262
|
*/
|
|
263
|
-
absDiff(d:
|
|
263
|
+
absDiff(d: LocalDateInput, unit: LocalDateUnit): number {
|
|
264
264
|
return Math.abs(this.diff(d, unit))
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -269,7 +269,7 @@ export class LocalDate {
|
|
|
269
269
|
*
|
|
270
270
|
* a.diff(b) means "a minus b"
|
|
271
271
|
*/
|
|
272
|
-
diff(d:
|
|
272
|
+
diff(d: LocalDateInput, unit: LocalDateUnit): number {
|
|
273
273
|
d = LocalDate.of(d)
|
|
274
274
|
|
|
275
275
|
const sign = this.cmp(d)
|
|
@@ -509,6 +509,6 @@ export class LocalDate {
|
|
|
509
509
|
/**
|
|
510
510
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
511
511
|
*/
|
|
512
|
-
export function localDate(d?:
|
|
512
|
+
export function localDate(d?: LocalDateInput): LocalDate {
|
|
513
513
|
return d ? LocalDate.of(d) : LocalDate.today()
|
|
514
514
|
}
|
|
@@ -21,7 +21,7 @@ export enum ISODayOfWeek {
|
|
|
21
21
|
SUNDAY = 7,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type
|
|
24
|
+
export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestampNumber
|
|
25
25
|
export type LocalTimeFormatter = (ld: LocalTime) => string
|
|
26
26
|
|
|
27
27
|
export interface LocalTimeComponents {
|
|
@@ -50,7 +50,7 @@ export class LocalTime {
|
|
|
50
50
|
* Parses input String into LocalDate.
|
|
51
51
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
52
52
|
*/
|
|
53
|
-
static of(d:
|
|
53
|
+
static of(d: LocalTimeInput): LocalTime {
|
|
54
54
|
const t = this.parseOrNull(d)
|
|
55
55
|
|
|
56
56
|
if (t === null) {
|
|
@@ -70,7 +70,7 @@ export class LocalTime {
|
|
|
70
70
|
/**
|
|
71
71
|
* Returns null if invalid
|
|
72
72
|
*/
|
|
73
|
-
static parseOrNull(d:
|
|
73
|
+
static parseOrNull(d: LocalTimeInput | undefined | null): LocalTime | null {
|
|
74
74
|
if (!d) return null
|
|
75
75
|
if (d instanceof LocalTime) return d
|
|
76
76
|
|
|
@@ -100,7 +100,7 @@ export class LocalTime {
|
|
|
100
100
|
return new LocalTime(date)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
static parseToDate(d:
|
|
103
|
+
static parseToDate(d: LocalTimeInput): Date {
|
|
104
104
|
if (d instanceof LocalTime) return d.$date
|
|
105
105
|
if (d instanceof Date) return d
|
|
106
106
|
|
|
@@ -113,7 +113,7 @@ export class LocalTime {
|
|
|
113
113
|
return date
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
static parseToUnixTimestamp(d:
|
|
116
|
+
static parseToUnixTimestamp(d: LocalTimeInput): UnixTimestampNumber {
|
|
117
117
|
if (typeof d === 'number') return d
|
|
118
118
|
if (d instanceof LocalTime) return d.unix()
|
|
119
119
|
|
|
@@ -126,7 +126,7 @@ export class LocalTime {
|
|
|
126
126
|
return date.valueOf() / 1000
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
static isValid(d:
|
|
129
|
+
static isValid(d: LocalTimeInput | undefined | null): boolean {
|
|
130
130
|
return this.parseOrNull(d) !== null
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -283,11 +283,11 @@ export class LocalTime {
|
|
|
283
283
|
return this.add(num * -1, unit, mutate)
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
absDiff(other:
|
|
286
|
+
absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number {
|
|
287
287
|
return Math.abs(this.diff(other, unit))
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
diff(other:
|
|
290
|
+
diff(other: LocalTimeInput, unit: LocalTimeUnit): number {
|
|
291
291
|
const date2 = LocalTime.parseToDate(other)
|
|
292
292
|
|
|
293
293
|
const secDiff = (this.$date.valueOf() - date2.valueOf()) / 1000
|
|
@@ -384,11 +384,11 @@ export class LocalTime {
|
|
|
384
384
|
})
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
static earliestOrUndefined(items:
|
|
387
|
+
static earliestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined {
|
|
388
388
|
return items.length ? LocalTime.earliest(items) : undefined
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
static earliest(items:
|
|
391
|
+
static earliest(items: LocalTimeInput[]): LocalTime {
|
|
392
392
|
_assert(items.length, 'LocalTime.earliest called on empty array')
|
|
393
393
|
|
|
394
394
|
return items
|
|
@@ -396,11 +396,11 @@ export class LocalTime {
|
|
|
396
396
|
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item))
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
-
static latestOrUndefined(items:
|
|
399
|
+
static latestOrUndefined(items: LocalTimeInput[]): LocalTime | undefined {
|
|
400
400
|
return items.length ? LocalTime.latest(items) : undefined
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
static latest(items:
|
|
403
|
+
static latest(items: LocalTimeInput[]): LocalTime {
|
|
404
404
|
_assert(items.length, 'LocalTime.latest called on empty array')
|
|
405
405
|
|
|
406
406
|
return items
|
|
@@ -408,29 +408,29 @@ export class LocalTime {
|
|
|
408
408
|
.reduce((max, item) => (max.isSameOrAfter(item) ? max : item))
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
isSame(d:
|
|
411
|
+
isSame(d: LocalTimeInput): boolean {
|
|
412
412
|
return this.cmp(d) === 0
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
isBefore(d:
|
|
415
|
+
isBefore(d: LocalTimeInput, inclusive = false): boolean {
|
|
416
416
|
const r = this.cmp(d)
|
|
417
417
|
return r === -1 || (r === 0 && inclusive)
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
-
isSameOrBefore(d:
|
|
420
|
+
isSameOrBefore(d: LocalTimeInput): boolean {
|
|
421
421
|
return this.cmp(d) <= 0
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
isAfter(d:
|
|
424
|
+
isAfter(d: LocalTimeInput, inclusive = false): boolean {
|
|
425
425
|
const r = this.cmp(d)
|
|
426
426
|
return r === 1 || (r === 0 && inclusive)
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
isSameOrAfter(d:
|
|
429
|
+
isSameOrAfter(d: LocalTimeInput): boolean {
|
|
430
430
|
return this.cmp(d) >= 0
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
isBetween(min:
|
|
433
|
+
isBetween(min: LocalTimeInput, max: LocalTimeInput, incl: Inclusiveness = '[)'): boolean {
|
|
434
434
|
let r = this.cmp(min)
|
|
435
435
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
436
436
|
if (r < 0 || (r === 0 && incl[0] === '(')) return false
|
|
@@ -444,7 +444,7 @@ export class LocalTime {
|
|
|
444
444
|
* returns 0 if they are equal
|
|
445
445
|
* returns -1 if this < d
|
|
446
446
|
*/
|
|
447
|
-
cmp(d:
|
|
447
|
+
cmp(d: LocalTimeInput): -1 | 0 | 1 {
|
|
448
448
|
const t1 = this.$date.valueOf()
|
|
449
449
|
const t2 = LocalTime.parseToDate(d).valueOf()
|
|
450
450
|
if (t1 === t2) return 0
|
|
@@ -462,7 +462,7 @@ export class LocalTime {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
-
fromNow(now:
|
|
465
|
+
fromNow(now: LocalTimeInput = new Date()): string {
|
|
466
466
|
const msDiff = LocalTime.parseToDate(now).valueOf() - this.$date.valueOf()
|
|
467
467
|
|
|
468
468
|
if (msDiff === 0) return 'now'
|
|
@@ -599,7 +599,7 @@ export class LocalTime {
|
|
|
599
599
|
/**
|
|
600
600
|
* Shortcut wrapper around `LocalDate.parse` / `LocalDate.today`
|
|
601
601
|
*/
|
|
602
|
-
export function localTime(d?:
|
|
602
|
+
export function localTime(d?: LocalTimeInput): LocalTime {
|
|
603
603
|
return d ? LocalTime.of(d) : LocalTime.now()
|
|
604
604
|
}
|
|
605
605
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UnixTimestampNumber } from '../types'
|
|
2
2
|
import type { Inclusiveness } from './localDate'
|
|
3
|
-
import type {
|
|
3
|
+
import type { LocalTimeInput } from './localTime'
|
|
4
4
|
import { LocalTime } from './localTime'
|
|
5
5
|
|
|
6
6
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString
|
|
@@ -18,7 +18,7 @@ export class TimeInterval {
|
|
|
18
18
|
private $end: UnixTimestampNumber,
|
|
19
19
|
) {}
|
|
20
20
|
|
|
21
|
-
static of(start:
|
|
21
|
+
static of(start: LocalTimeInput, end: LocalTimeInput): TimeInterval {
|
|
22
22
|
return new TimeInterval(
|
|
23
23
|
LocalTime.parseToUnixTimestamp(start),
|
|
24
24
|
LocalTime.parseToUnixTimestamp(end),
|
|
@@ -78,7 +78,7 @@ export class TimeInterval {
|
|
|
78
78
|
return this.cmp(d) >= 0
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
includes(d:
|
|
81
|
+
includes(d: LocalTimeInput, incl: Inclusiveness = '[)'): boolean {
|
|
82
82
|
d = LocalTime.parseToUnixTimestamp(d)
|
|
83
83
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
84
84
|
if (d < this.$start || (d === this.$start && incl[0] === '(')) return false
|
package/src/http/fetcher.ts
CHANGED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { LocalDateUnit, LocalDate, LocalDateConfig } from '../datetime/localDate'
|
|
2
|
-
|
|
3
|
-
export class LazyLocalDate {
|
|
4
|
-
constructor(private str: string) {}
|
|
5
|
-
|
|
6
|
-
private ld?: LocalDate
|
|
7
|
-
|
|
8
|
-
eq(d: LocalDateConfig): boolean {
|
|
9
|
-
if (typeof d === 'string') return d === this.str
|
|
10
|
-
this.ld ||= LocalDate.of(this.str)
|
|
11
|
-
return this.ld.isSame(d)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
lt(d: LocalDateConfig): boolean {
|
|
15
|
-
return this.cmp(d) === -1
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
lte(d: LocalDateConfig): boolean {
|
|
19
|
-
return this.cmp(d) <= 0
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
gt(d: LocalDateConfig): boolean {
|
|
23
|
-
return this.cmp(d) === 1
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
gte(d: LocalDateConfig): boolean {
|
|
27
|
-
return this.cmp(d) >= 0
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
cmp(d: LocalDateConfig): -1 | 0 | 1 {
|
|
31
|
-
if (typeof d === 'string') {
|
|
32
|
-
return this.str < d ? -1 : this.str > d ? 1 : 0
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.ld ||= LocalDate.of(this.str)
|
|
36
|
-
return this.ld.cmp(d)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
absDiff(d: LocalDateConfig, unit: LocalDateUnit): number {
|
|
40
|
-
return Math.abs(this.diff(d, unit))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
diff(d: LocalDateConfig, unit: LocalDateUnit): number {
|
|
44
|
-
this.ld ||= LocalDate.of(this.str)
|
|
45
|
-
return this.ld.diff(d, unit)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
add(num: number, unit: LocalDateUnit): LocalDate {
|
|
49
|
-
this.ld ||= LocalDate.of(this.str)
|
|
50
|
-
return this.ld.add(num, unit)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
subtract(num: number, unit: LocalDateUnit): LocalDate {
|
|
54
|
-
return this.add(-num, unit)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
clone(): LazyLocalDate {
|
|
58
|
-
return new LazyLocalDate(this.str)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
toDate(): Date {
|
|
62
|
-
this.ld ||= LocalDate.of(this.str)
|
|
63
|
-
return this.ld.toDate()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
toString(): string {
|
|
67
|
-
return this.str
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
toJSON(): string {
|
|
71
|
-
return this.str
|
|
72
|
-
}
|
|
73
|
-
}
|