@naturalcycles/js-lib 14.93.0 → 14.95.1
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 +12 -2
- package/dist/datetime/dateInterval.js +20 -0
- package/dist/datetime/localDate.d.ts +4 -2
- package/dist/datetime/localDate.js +11 -0
- package/dist/datetime/localTime.d.ts +4 -3
- package/dist/datetime/localTime.js +11 -0
- package/dist/decorators/debounce.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/string/safeJsonStringify.js +1 -1
- package/dist-esm/datetime/dateInterval.js +20 -0
- package/dist-esm/datetime/localDate.js +11 -0
- package/dist-esm/datetime/localTime.js +11 -0
- package/dist-esm/decorators/debounce.js +1 -1
- package/dist-esm/string/safeJsonStringify.js +1 -1
- package/package.json +1 -1
- package/src/datetime/dateInterval.ts +26 -2
- package/src/datetime/localDate.ts +12 -2
- package/src/datetime/localTime.ts +12 -3
- package/src/decorators/debounce.ts +1 -1
- package/src/index.ts +4 -2
- package/src/string/safeJsonStringify.ts +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LocalDate, LocalDateConfig } from './localDate';
|
|
2
2
|
export declare type DateIntervalConfig = DateInterval | string;
|
|
3
|
+
export declare type DateIntervalString = string;
|
|
3
4
|
/**
|
|
4
5
|
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
5
6
|
*
|
|
@@ -19,11 +20,20 @@ export declare class DateInterval {
|
|
|
19
20
|
isSameOrBefore(d: DateIntervalConfig): boolean;
|
|
20
21
|
isAfter(d: DateIntervalConfig): boolean;
|
|
21
22
|
isSameOrAfter(d: DateIntervalConfig): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
25
|
+
*/
|
|
26
|
+
includes(d: LocalDateConfig): boolean;
|
|
22
27
|
/**
|
|
23
28
|
* DateIntervals compare by start date.
|
|
24
29
|
* If it's the same - then by end date.
|
|
25
30
|
*/
|
|
26
31
|
cmp(d: DateIntervalConfig): -1 | 0 | 1;
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Returns an array of LocalDates that are included in the interval.
|
|
34
|
+
* Ranges are INCLUSIVE.
|
|
35
|
+
*/
|
|
36
|
+
getDays(): LocalDate[];
|
|
37
|
+
toString(): DateIntervalString;
|
|
38
|
+
toJSON(): DateIntervalString;
|
|
29
39
|
}
|
|
@@ -42,6 +42,13 @@ class DateInterval {
|
|
|
42
42
|
isSameOrAfter(d) {
|
|
43
43
|
return this.cmp(d) >= 0;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
47
|
+
*/
|
|
48
|
+
includes(d) {
|
|
49
|
+
d = localDate_1.LocalDate.of(d);
|
|
50
|
+
return d.isSameOrAfter(this.start) && d.isSameOrBefore(this.end);
|
|
51
|
+
}
|
|
45
52
|
/**
|
|
46
53
|
* DateIntervals compare by start date.
|
|
47
54
|
* If it's the same - then by end date.
|
|
@@ -50,6 +57,19 @@ class DateInterval {
|
|
|
50
57
|
d = DateInterval.parse(d);
|
|
51
58
|
return this.start.cmp(d.start) || this.end.cmp(d.end);
|
|
52
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns an array of LocalDates that are included in the interval.
|
|
62
|
+
* Ranges are INCLUSIVE.
|
|
63
|
+
*/
|
|
64
|
+
getDays() {
|
|
65
|
+
const days = [];
|
|
66
|
+
let current = this.start;
|
|
67
|
+
do {
|
|
68
|
+
days.push(current);
|
|
69
|
+
current = current.add(1, 'day');
|
|
70
|
+
} while (current.isSameOrBefore(this.end));
|
|
71
|
+
return days;
|
|
72
|
+
}
|
|
53
73
|
toString() {
|
|
54
74
|
return [this.start, this.end].join('/');
|
|
55
75
|
}
|
|
@@ -2,6 +2,7 @@ import { Sequence } from '../seq/seq';
|
|
|
2
2
|
import { IsoDate, UnixTimestamp } from '../types';
|
|
3
3
|
import { LocalTime } from './localTime';
|
|
4
4
|
export declare type LocalDateUnit = 'year' | 'month' | 'day';
|
|
5
|
+
export declare type Inclusiveness = '()' | '[]' | '[)' | '(]';
|
|
5
6
|
export declare type LocalDateConfig = LocalDate | string;
|
|
6
7
|
/**
|
|
7
8
|
* @experimental
|
|
@@ -23,8 +24,8 @@ export declare class LocalDate {
|
|
|
23
24
|
/**
|
|
24
25
|
* Returns null if invalid.
|
|
25
26
|
*/
|
|
26
|
-
static parseOrNull(d: LocalDateConfig): LocalDate | null;
|
|
27
|
-
static isValid(iso: string): boolean;
|
|
27
|
+
static parseOrNull(d: LocalDateConfig | undefined | null): LocalDate | null;
|
|
28
|
+
static isValid(iso: string | undefined | null): boolean;
|
|
28
29
|
static today(): LocalDate;
|
|
29
30
|
static todayUTC(): LocalDate;
|
|
30
31
|
static sort(items: LocalDate[], mutate?: boolean, descending?: boolean): LocalDate[];
|
|
@@ -42,6 +43,7 @@ export declare class LocalDate {
|
|
|
42
43
|
isSameOrBefore(d: LocalDateConfig): boolean;
|
|
43
44
|
isAfter(d: LocalDateConfig): boolean;
|
|
44
45
|
isSameOrAfter(d: LocalDateConfig): boolean;
|
|
46
|
+
isBetween(min: LocalDateConfig, max: LocalDateConfig, incl?: Inclusiveness): boolean;
|
|
45
47
|
/**
|
|
46
48
|
* Returns 1 if this > d
|
|
47
49
|
* returns 0 if they are equal
|
|
@@ -46,6 +46,8 @@ class LocalDate {
|
|
|
46
46
|
* Returns null if invalid.
|
|
47
47
|
*/
|
|
48
48
|
static parseOrNull(d) {
|
|
49
|
+
if (!d)
|
|
50
|
+
return null;
|
|
49
51
|
if (d instanceof LocalDate)
|
|
50
52
|
return d;
|
|
51
53
|
// todo: explore more performant options
|
|
@@ -131,6 +133,15 @@ class LocalDate {
|
|
|
131
133
|
isSameOrAfter(d) {
|
|
132
134
|
return this.cmp(d) >= 0;
|
|
133
135
|
}
|
|
136
|
+
isBetween(min, max, incl = '[)') {
|
|
137
|
+
let r = this.cmp(min);
|
|
138
|
+
if (r < 0 || (r === 0 && incl[0] === '('))
|
|
139
|
+
return false;
|
|
140
|
+
r = this.cmp(max);
|
|
141
|
+
if (r > 0 || (r === 0 && incl[1] === ')'))
|
|
142
|
+
return false;
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
134
145
|
/**
|
|
135
146
|
* Returns 1 if this > d
|
|
136
147
|
* returns 0 if they are equal
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IsoDate, IsoDateTime, UnixTimestamp } from '../types';
|
|
2
|
-
import { LocalDate } from './localDate';
|
|
2
|
+
import { Inclusiveness, LocalDate } from './localDate';
|
|
3
3
|
export declare type LocalTimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second';
|
|
4
4
|
export declare type LocalTimeConfig = LocalTime | Date | IsoDateTime | UnixTimestamp;
|
|
5
5
|
export interface LocalTimeComponents {
|
|
@@ -27,8 +27,8 @@ export declare class LocalTime {
|
|
|
27
27
|
/**
|
|
28
28
|
* Returns null if invalid
|
|
29
29
|
*/
|
|
30
|
-
static parseOrNull(d: LocalTimeConfig): LocalTime | null;
|
|
31
|
-
static isValid(d: LocalTimeConfig): boolean;
|
|
30
|
+
static parseOrNull(d: LocalTimeConfig | undefined | null): LocalTime | null;
|
|
31
|
+
static isValid(d: LocalTimeConfig | undefined | null): boolean;
|
|
32
32
|
static now(): LocalTime;
|
|
33
33
|
static fromComponents(c: {
|
|
34
34
|
year: number;
|
|
@@ -64,6 +64,7 @@ export declare class LocalTime {
|
|
|
64
64
|
isSameOrBefore(d: LocalTimeConfig): boolean;
|
|
65
65
|
isAfter(d: LocalTimeConfig): boolean;
|
|
66
66
|
isSameOrAfter(d: LocalTimeConfig): boolean;
|
|
67
|
+
isBetween(min: LocalTimeConfig, max: LocalTimeConfig, incl?: Inclusiveness): boolean;
|
|
67
68
|
/**
|
|
68
69
|
* Returns 1 if this > d
|
|
69
70
|
* returns 0 if they are equal
|
|
@@ -48,6 +48,8 @@ class LocalTime {
|
|
|
48
48
|
* Returns null if invalid
|
|
49
49
|
*/
|
|
50
50
|
static parseOrNull(d) {
|
|
51
|
+
if (!d)
|
|
52
|
+
return null;
|
|
51
53
|
if (d instanceof LocalTime)
|
|
52
54
|
return d;
|
|
53
55
|
let date;
|
|
@@ -263,6 +265,15 @@ class LocalTime {
|
|
|
263
265
|
isSameOrAfter(d) {
|
|
264
266
|
return this.cmp(d) >= 0;
|
|
265
267
|
}
|
|
268
|
+
isBetween(min, max, incl = '[)') {
|
|
269
|
+
let r = this.cmp(min);
|
|
270
|
+
if (r < 0 || (r === 0 && incl[0] === '('))
|
|
271
|
+
return false;
|
|
272
|
+
r = this.cmp(max);
|
|
273
|
+
if (r > 0 || (r === 0 && incl[1] === ')'))
|
|
274
|
+
return false;
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
266
277
|
/**
|
|
267
278
|
* Returns 1 if this > d
|
|
268
279
|
* returns 0 if they are equal
|
|
@@ -10,7 +10,7 @@ function _debounce(func, wait, opt = {}) {
|
|
|
10
10
|
let lastInvokeTime = 0;
|
|
11
11
|
const maxing = 'maxWait' in opt;
|
|
12
12
|
const { leading = false, trailing = true } = opt;
|
|
13
|
-
const maxWait = maxing ? Math.max(
|
|
13
|
+
const maxWait = maxing ? Math.max(Number(opt.maxWait) || 0, wait) : opt.maxWait;
|
|
14
14
|
function invokeFunc(time) {
|
|
15
15
|
const args = lastArgs;
|
|
16
16
|
const thisArg = lastThis;
|
package/dist/index.d.ts
CHANGED
|
@@ -64,8 +64,8 @@ export * from './string/leven';
|
|
|
64
64
|
export * from './datetime/localDate';
|
|
65
65
|
export * from './datetime/localTime';
|
|
66
66
|
export * from './datetime/dateInterval';
|
|
67
|
-
import { LocalDateConfig, LocalDateUnit } from './datetime/localDate';
|
|
67
|
+
import { LocalDateConfig, LocalDateUnit, Inclusiveness } from './datetime/localDate';
|
|
68
68
|
import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime';
|
|
69
|
-
import { DateIntervalConfig } from './datetime/dateInterval';
|
|
70
|
-
export type { DateIntervalConfig, LocalDateConfig, LocalDateUnit, LocalTimeConfig, LocalTimeUnit, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateTime, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
69
|
+
import { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval';
|
|
70
|
+
export type { DateIntervalConfig, DateIntervalString, LocalDateConfig, LocalDateUnit, Inclusiveness, LocalTimeConfig, LocalTimeUnit, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateTime, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
71
71
|
export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
|
|
@@ -17,7 +17,7 @@ function _safeJsonStringify(obj, replacer, spaces, cycleReplacer) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports._safeJsonStringify = _safeJsonStringify;
|
|
20
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions, no-bitwise */
|
|
20
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions, no-bitwise, no-implicit-coercion */
|
|
21
21
|
function serializer(replacer, cycleReplacer) {
|
|
22
22
|
const stack = [];
|
|
23
23
|
const keys = [];
|
|
@@ -39,6 +39,13 @@ export class DateInterval {
|
|
|
39
39
|
isSameOrAfter(d) {
|
|
40
40
|
return this.cmp(d) >= 0;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
44
|
+
*/
|
|
45
|
+
includes(d) {
|
|
46
|
+
d = LocalDate.of(d);
|
|
47
|
+
return d.isSameOrAfter(this.start) && d.isSameOrBefore(this.end);
|
|
48
|
+
}
|
|
42
49
|
/**
|
|
43
50
|
* DateIntervals compare by start date.
|
|
44
51
|
* If it's the same - then by end date.
|
|
@@ -47,6 +54,19 @@ export class DateInterval {
|
|
|
47
54
|
d = DateInterval.parse(d);
|
|
48
55
|
return this.start.cmp(d.start) || this.end.cmp(d.end);
|
|
49
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns an array of LocalDates that are included in the interval.
|
|
59
|
+
* Ranges are INCLUSIVE.
|
|
60
|
+
*/
|
|
61
|
+
getDays() {
|
|
62
|
+
const days = [];
|
|
63
|
+
let current = this.start;
|
|
64
|
+
do {
|
|
65
|
+
days.push(current);
|
|
66
|
+
current = current.add(1, 'day');
|
|
67
|
+
} while (current.isSameOrBefore(this.end));
|
|
68
|
+
return days;
|
|
69
|
+
}
|
|
50
70
|
toString() {
|
|
51
71
|
return [this.start, this.end].join('/');
|
|
52
72
|
}
|
|
@@ -43,6 +43,8 @@ export class LocalDate {
|
|
|
43
43
|
* Returns null if invalid.
|
|
44
44
|
*/
|
|
45
45
|
static parseOrNull(d) {
|
|
46
|
+
if (!d)
|
|
47
|
+
return null;
|
|
46
48
|
if (d instanceof LocalDate)
|
|
47
49
|
return d;
|
|
48
50
|
// todo: explore more performant options
|
|
@@ -128,6 +130,15 @@ export class LocalDate {
|
|
|
128
130
|
isSameOrAfter(d) {
|
|
129
131
|
return this.cmp(d) >= 0;
|
|
130
132
|
}
|
|
133
|
+
isBetween(min, max, incl = '[)') {
|
|
134
|
+
let r = this.cmp(min);
|
|
135
|
+
if (r < 0 || (r === 0 && incl[0] === '('))
|
|
136
|
+
return false;
|
|
137
|
+
r = this.cmp(max);
|
|
138
|
+
if (r > 0 || (r === 0 && incl[1] === ')'))
|
|
139
|
+
return false;
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
131
142
|
/**
|
|
132
143
|
* Returns 1 if this > d
|
|
133
144
|
* returns 0 if they are equal
|
|
@@ -45,6 +45,8 @@ export class LocalTime {
|
|
|
45
45
|
* Returns null if invalid
|
|
46
46
|
*/
|
|
47
47
|
static parseOrNull(d) {
|
|
48
|
+
if (!d)
|
|
49
|
+
return null;
|
|
48
50
|
if (d instanceof LocalTime)
|
|
49
51
|
return d;
|
|
50
52
|
let date;
|
|
@@ -260,6 +262,15 @@ export class LocalTime {
|
|
|
260
262
|
isSameOrAfter(d) {
|
|
261
263
|
return this.cmp(d) >= 0;
|
|
262
264
|
}
|
|
265
|
+
isBetween(min, max, incl = '[)') {
|
|
266
|
+
let r = this.cmp(min);
|
|
267
|
+
if (r < 0 || (r === 0 && incl[0] === '('))
|
|
268
|
+
return false;
|
|
269
|
+
r = this.cmp(max);
|
|
270
|
+
if (r > 0 || (r === 0 && incl[1] === ')'))
|
|
271
|
+
return false;
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
263
274
|
/**
|
|
264
275
|
* Returns 1 if this > d
|
|
265
276
|
* returns 0 if they are equal
|
|
@@ -7,7 +7,7 @@ export function _debounce(func, wait, opt = {}) {
|
|
|
7
7
|
let lastInvokeTime = 0;
|
|
8
8
|
const maxing = 'maxWait' in opt;
|
|
9
9
|
const { leading = false, trailing = true } = opt;
|
|
10
|
-
const maxWait = maxing ? Math.max(
|
|
10
|
+
const maxWait = maxing ? Math.max(Number(opt.maxWait) || 0, wait) : opt.maxWait;
|
|
11
11
|
function invokeFunc(time) {
|
|
12
12
|
const args = lastArgs;
|
|
13
13
|
const thisArg = lastThis;
|
|
@@ -13,7 +13,7 @@ export function _safeJsonStringify(obj, replacer, spaces, cycleReplacer) {
|
|
|
13
13
|
return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions, no-bitwise */
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions, no-bitwise, no-implicit-coercion */
|
|
17
17
|
function serializer(replacer, cycleReplacer) {
|
|
18
18
|
const stack = [];
|
|
19
19
|
const keys = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LocalDate, LocalDateConfig } from './localDate'
|
|
2
2
|
|
|
3
3
|
export type DateIntervalConfig = DateInterval | string
|
|
4
|
+
export type DateIntervalString = string
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
@@ -49,6 +50,14 @@ export class DateInterval {
|
|
|
49
50
|
return this.cmp(d) >= 0
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
55
|
+
*/
|
|
56
|
+
includes(d: LocalDateConfig): boolean {
|
|
57
|
+
d = LocalDate.of(d)
|
|
58
|
+
return d.isSameOrAfter(this.start) && d.isSameOrBefore(this.end)
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
/**
|
|
53
62
|
* DateIntervals compare by start date.
|
|
54
63
|
* If it's the same - then by end date.
|
|
@@ -58,11 +67,26 @@ export class DateInterval {
|
|
|
58
67
|
return this.start.cmp(d.start) || this.end.cmp(d.end)
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Returns an array of LocalDates that are included in the interval.
|
|
72
|
+
* Ranges are INCLUSIVE.
|
|
73
|
+
*/
|
|
74
|
+
getDays(): LocalDate[] {
|
|
75
|
+
const days: LocalDate[] = []
|
|
76
|
+
let current = this.start
|
|
77
|
+
do {
|
|
78
|
+
days.push(current)
|
|
79
|
+
current = current.add(1, 'day')
|
|
80
|
+
} while (current.isSameOrBefore(this.end))
|
|
81
|
+
|
|
82
|
+
return days
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
toString(): DateIntervalString {
|
|
62
86
|
return [this.start, this.end].join('/')
|
|
63
87
|
}
|
|
64
88
|
|
|
65
|
-
|
|
89
|
+
toJSON(): DateIntervalString {
|
|
66
90
|
return this.toString()
|
|
67
91
|
}
|
|
68
92
|
}
|
|
@@ -4,6 +4,7 @@ import { END, IsoDate, UnixTimestamp } from '../types'
|
|
|
4
4
|
import { LocalTime } from './localTime'
|
|
5
5
|
|
|
6
6
|
export type LocalDateUnit = 'year' | 'month' | 'day'
|
|
7
|
+
export type Inclusiveness = '()' | '[]' | '[)' | '(]'
|
|
7
8
|
|
|
8
9
|
const m31 = new Set<number>([1, 3, 5, 7, 8, 10, 12])
|
|
9
10
|
|
|
@@ -54,7 +55,8 @@ export class LocalDate {
|
|
|
54
55
|
/**
|
|
55
56
|
* Returns null if invalid.
|
|
56
57
|
*/
|
|
57
|
-
static parseOrNull(d: LocalDateConfig): LocalDate | null {
|
|
58
|
+
static parseOrNull(d: LocalDateConfig | undefined | null): LocalDate | null {
|
|
59
|
+
if (!d) return null
|
|
58
60
|
if (d instanceof LocalDate) return d
|
|
59
61
|
|
|
60
62
|
// todo: explore more performant options
|
|
@@ -75,7 +77,7 @@ export class LocalDate {
|
|
|
75
77
|
return new LocalDate(year, month, day)
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
static isValid(iso: string): boolean {
|
|
80
|
+
static isValid(iso: string | undefined | null): boolean {
|
|
79
81
|
return this.parseOrNull(iso) !== null
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -194,6 +196,14 @@ export class LocalDate {
|
|
|
194
196
|
return this.cmp(d) >= 0
|
|
195
197
|
}
|
|
196
198
|
|
|
199
|
+
isBetween(min: LocalDateConfig, max: LocalDateConfig, incl: Inclusiveness = '[)'): boolean {
|
|
200
|
+
let r = this.cmp(min)
|
|
201
|
+
if (r < 0 || (r === 0 && incl[0] === '(')) return false
|
|
202
|
+
r = this.cmp(max)
|
|
203
|
+
if (r > 0 || (r === 0 && incl[1] === ')')) return false
|
|
204
|
+
return true
|
|
205
|
+
}
|
|
206
|
+
|
|
197
207
|
/**
|
|
198
208
|
* Returns 1 if this > d
|
|
199
209
|
* returns 0 if they are equal
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _assert } from '../error/assert'
|
|
2
2
|
import { _ms } from '../time/time.util'
|
|
3
3
|
import { IsoDate, IsoDateTime, UnixTimestamp } from '../types'
|
|
4
|
-
import { LocalDate } from './localDate'
|
|
4
|
+
import { Inclusiveness, LocalDate } from './localDate'
|
|
5
5
|
|
|
6
6
|
export type LocalTimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'
|
|
7
7
|
|
|
@@ -63,7 +63,8 @@ export class LocalTime {
|
|
|
63
63
|
/**
|
|
64
64
|
* Returns null if invalid
|
|
65
65
|
*/
|
|
66
|
-
static parseOrNull(d: LocalTimeConfig): LocalTime | null {
|
|
66
|
+
static parseOrNull(d: LocalTimeConfig | undefined | null): LocalTime | null {
|
|
67
|
+
if (!d) return null
|
|
67
68
|
if (d instanceof LocalTime) return d
|
|
68
69
|
|
|
69
70
|
let date
|
|
@@ -89,7 +90,7 @@ export class LocalTime {
|
|
|
89
90
|
return new LocalTime(date, false)
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
static isValid(d: LocalTimeConfig): boolean {
|
|
93
|
+
static isValid(d: LocalTimeConfig | undefined | null): boolean {
|
|
93
94
|
return this.parseOrNull(d) !== null
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -322,6 +323,14 @@ export class LocalTime {
|
|
|
322
323
|
return this.cmp(d) >= 0
|
|
323
324
|
}
|
|
324
325
|
|
|
326
|
+
isBetween(min: LocalTimeConfig, max: LocalTimeConfig, incl: Inclusiveness = '[)'): boolean {
|
|
327
|
+
let r = this.cmp(min)
|
|
328
|
+
if (r < 0 || (r === 0 && incl[0] === '(')) return false
|
|
329
|
+
r = this.cmp(max)
|
|
330
|
+
if (r > 0 || (r === 0 && incl[1] === ')')) return false
|
|
331
|
+
return true
|
|
332
|
+
}
|
|
333
|
+
|
|
325
334
|
/**
|
|
326
335
|
* Returns 1 if this > d
|
|
327
336
|
* returns 0 if they are equal
|
|
@@ -49,7 +49,7 @@ export function _debounce<T extends AnyFunction>(
|
|
|
49
49
|
const maxing = 'maxWait' in opt
|
|
50
50
|
|
|
51
51
|
const { leading = false, trailing = true } = opt
|
|
52
|
-
const maxWait = maxing ? Math.max(
|
|
52
|
+
const maxWait = maxing ? Math.max(Number(opt.maxWait) || 0, wait) : opt.maxWait
|
|
53
53
|
|
|
54
54
|
function invokeFunc(time: number) {
|
|
55
55
|
const args = lastArgs
|
package/src/index.ts
CHANGED
|
@@ -159,14 +159,16 @@ export * from './string/leven'
|
|
|
159
159
|
export * from './datetime/localDate'
|
|
160
160
|
export * from './datetime/localTime'
|
|
161
161
|
export * from './datetime/dateInterval'
|
|
162
|
-
import { LocalDateConfig, LocalDateUnit } from './datetime/localDate'
|
|
162
|
+
import { LocalDateConfig, LocalDateUnit, Inclusiveness } from './datetime/localDate'
|
|
163
163
|
import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime'
|
|
164
|
-
import { DateIntervalConfig } from './datetime/dateInterval'
|
|
164
|
+
import { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval'
|
|
165
165
|
|
|
166
166
|
export type {
|
|
167
167
|
DateIntervalConfig,
|
|
168
|
+
DateIntervalString,
|
|
168
169
|
LocalDateConfig,
|
|
169
170
|
LocalDateUnit,
|
|
171
|
+
Inclusiveness,
|
|
170
172
|
LocalTimeConfig,
|
|
171
173
|
LocalTimeUnit,
|
|
172
174
|
LocalTimeComponents,
|
|
@@ -20,7 +20,7 @@ export function _safeJsonStringify(
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/* eslint-disable @typescript-eslint/no-unused-expressions, no-bitwise */
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions, no-bitwise, no-implicit-coercion */
|
|
24
24
|
|
|
25
25
|
function serializer(replacer?: Reviver, cycleReplacer?: Reviver): Reviver {
|
|
26
26
|
const stack: any[] = []
|