@naturalcycles/js-lib 14.92.0 → 14.93.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 +29 -0
- package/dist/datetime/dateInterval.js +60 -0
- package/dist/datetime/localTime.js +3 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist-esm/datetime/dateInterval.js +56 -0
- package/dist-esm/datetime/localTime.js +3 -0
- package/dist-esm/index.js +1 -0
- package/package.json +1 -1
- package/src/datetime/dateInterval.ts +68 -0
- package/src/datetime/localTime.ts +3 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LocalDate, LocalDateConfig } from './localDate';
|
|
2
|
+
export declare type DateIntervalConfig = DateInterval | string;
|
|
3
|
+
/**
|
|
4
|
+
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export declare class DateInterval {
|
|
9
|
+
start: LocalDate;
|
|
10
|
+
end: LocalDate;
|
|
11
|
+
private constructor();
|
|
12
|
+
static of(start: LocalDateConfig, end: LocalDateConfig): DateInterval;
|
|
13
|
+
/**
|
|
14
|
+
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
15
|
+
*/
|
|
16
|
+
static parse(d: DateIntervalConfig): DateInterval;
|
|
17
|
+
isSame(d: DateIntervalConfig): boolean;
|
|
18
|
+
isBefore(d: DateIntervalConfig): boolean;
|
|
19
|
+
isSameOrBefore(d: DateIntervalConfig): boolean;
|
|
20
|
+
isAfter(d: DateIntervalConfig): boolean;
|
|
21
|
+
isSameOrAfter(d: DateIntervalConfig): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* DateIntervals compare by start date.
|
|
24
|
+
* If it's the same - then by end date.
|
|
25
|
+
*/
|
|
26
|
+
cmp(d: DateIntervalConfig): -1 | 0 | 1;
|
|
27
|
+
toString(): string;
|
|
28
|
+
private toJSON;
|
|
29
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateInterval = void 0;
|
|
4
|
+
const localDate_1 = require("./localDate");
|
|
5
|
+
/**
|
|
6
|
+
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
class DateInterval {
|
|
11
|
+
constructor(start, end) {
|
|
12
|
+
this.start = start;
|
|
13
|
+
this.end = end;
|
|
14
|
+
}
|
|
15
|
+
static of(start, end) {
|
|
16
|
+
return new DateInterval(localDate_1.LocalDate.of(start), localDate_1.LocalDate.of(end));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
20
|
+
*/
|
|
21
|
+
static parse(d) {
|
|
22
|
+
if (d instanceof DateInterval)
|
|
23
|
+
return d;
|
|
24
|
+
const [start, end] = d.split('/');
|
|
25
|
+
if (!end || !start) {
|
|
26
|
+
throw new Error(`Cannot parse "${d}" into DateInterval`);
|
|
27
|
+
}
|
|
28
|
+
return new DateInterval(localDate_1.LocalDate.of(start), localDate_1.LocalDate.of(end));
|
|
29
|
+
}
|
|
30
|
+
isSame(d) {
|
|
31
|
+
return this.cmp(d) === 0;
|
|
32
|
+
}
|
|
33
|
+
isBefore(d) {
|
|
34
|
+
return this.cmp(d) === -1;
|
|
35
|
+
}
|
|
36
|
+
isSameOrBefore(d) {
|
|
37
|
+
return this.cmp(d) <= 0;
|
|
38
|
+
}
|
|
39
|
+
isAfter(d) {
|
|
40
|
+
return this.cmp(d) === 1;
|
|
41
|
+
}
|
|
42
|
+
isSameOrAfter(d) {
|
|
43
|
+
return this.cmp(d) >= 0;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* DateIntervals compare by start date.
|
|
47
|
+
* If it's the same - then by end date.
|
|
48
|
+
*/
|
|
49
|
+
cmp(d) {
|
|
50
|
+
d = DateInterval.parse(d);
|
|
51
|
+
return this.start.cmp(d.start) || this.end.cmp(d.end);
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
return [this.start, this.end].join('/');
|
|
55
|
+
}
|
|
56
|
+
toJSON() {
|
|
57
|
+
return this.toString();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.DateInterval = DateInterval;
|
|
@@ -14,6 +14,9 @@ const localDate_1 = require("./localDate");
|
|
|
14
14
|
// .valueOf returns unix timestamp (no millis)
|
|
15
15
|
// Prevents dayjs(undefined) being dayjs.now()
|
|
16
16
|
// Validates on parse, throws if invalid. Doesn't allow invalid objects
|
|
17
|
+
// No arbitrary .format('') (which is slow to parse) vs well-defined (opinionated) formats
|
|
18
|
+
// Separate LocalTime, powered by native js Date, and LocalDate - a smaller functionality class when
|
|
19
|
+
// you only need "whole dates", no time, no timezone worry
|
|
17
20
|
/**
|
|
18
21
|
* @experimental
|
|
19
22
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -63,7 +63,9 @@ export * from './math/stack.util';
|
|
|
63
63
|
export * from './string/leven';
|
|
64
64
|
export * from './datetime/localDate';
|
|
65
65
|
export * from './datetime/localTime';
|
|
66
|
+
export * from './datetime/dateInterval';
|
|
66
67
|
import { LocalDateConfig, LocalDateUnit } from './datetime/localDate';
|
|
67
68
|
import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime';
|
|
68
|
-
|
|
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
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, };
|
package/dist/index.js
CHANGED
|
@@ -95,3 +95,4 @@ tslib_1.__exportStar(require("./math/stack.util"), exports);
|
|
|
95
95
|
tslib_1.__exportStar(require("./string/leven"), exports);
|
|
96
96
|
tslib_1.__exportStar(require("./datetime/localDate"), exports);
|
|
97
97
|
tslib_1.__exportStar(require("./datetime/localTime"), exports);
|
|
98
|
+
tslib_1.__exportStar(require("./datetime/dateInterval"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { LocalDate } from './localDate';
|
|
2
|
+
/**
|
|
3
|
+
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
4
|
+
*
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
export class DateInterval {
|
|
8
|
+
constructor(start, end) {
|
|
9
|
+
this.start = start;
|
|
10
|
+
this.end = end;
|
|
11
|
+
}
|
|
12
|
+
static of(start, end) {
|
|
13
|
+
return new DateInterval(LocalDate.of(start), LocalDate.of(end));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
17
|
+
*/
|
|
18
|
+
static parse(d) {
|
|
19
|
+
if (d instanceof DateInterval)
|
|
20
|
+
return d;
|
|
21
|
+
const [start, end] = d.split('/');
|
|
22
|
+
if (!end || !start) {
|
|
23
|
+
throw new Error(`Cannot parse "${d}" into DateInterval`);
|
|
24
|
+
}
|
|
25
|
+
return new DateInterval(LocalDate.of(start), LocalDate.of(end));
|
|
26
|
+
}
|
|
27
|
+
isSame(d) {
|
|
28
|
+
return this.cmp(d) === 0;
|
|
29
|
+
}
|
|
30
|
+
isBefore(d) {
|
|
31
|
+
return this.cmp(d) === -1;
|
|
32
|
+
}
|
|
33
|
+
isSameOrBefore(d) {
|
|
34
|
+
return this.cmp(d) <= 0;
|
|
35
|
+
}
|
|
36
|
+
isAfter(d) {
|
|
37
|
+
return this.cmp(d) === 1;
|
|
38
|
+
}
|
|
39
|
+
isSameOrAfter(d) {
|
|
40
|
+
return this.cmp(d) >= 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* DateIntervals compare by start date.
|
|
44
|
+
* If it's the same - then by end date.
|
|
45
|
+
*/
|
|
46
|
+
cmp(d) {
|
|
47
|
+
d = DateInterval.parse(d);
|
|
48
|
+
return this.start.cmp(d.start) || this.end.cmp(d.end);
|
|
49
|
+
}
|
|
50
|
+
toString() {
|
|
51
|
+
return [this.start, this.end].join('/');
|
|
52
|
+
}
|
|
53
|
+
toJSON() {
|
|
54
|
+
return this.toString();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -11,6 +11,9 @@ import { LocalDate } from './localDate';
|
|
|
11
11
|
// .valueOf returns unix timestamp (no millis)
|
|
12
12
|
// Prevents dayjs(undefined) being dayjs.now()
|
|
13
13
|
// Validates on parse, throws if invalid. Doesn't allow invalid objects
|
|
14
|
+
// No arbitrary .format('') (which is slow to parse) vs well-defined (opinionated) formats
|
|
15
|
+
// Separate LocalTime, powered by native js Date, and LocalDate - a smaller functionality class when
|
|
16
|
+
// you only need "whole dates", no time, no timezone worry
|
|
14
17
|
/**
|
|
15
18
|
* @experimental
|
|
16
19
|
*/
|
package/dist-esm/index.js
CHANGED
|
@@ -59,4 +59,5 @@ export * from './math/stack.util';
|
|
|
59
59
|
export * from './string/leven';
|
|
60
60
|
export * from './datetime/localDate';
|
|
61
61
|
export * from './datetime/localTime';
|
|
62
|
+
export * from './datetime/dateInterval';
|
|
62
63
|
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, };
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { LocalDate, LocalDateConfig } from './localDate'
|
|
2
|
+
|
|
3
|
+
export type DateIntervalConfig = DateInterval | string
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class that supports ISO8601 "Time interval" standard that looks like `2022-02-24/2022-03-30`.
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
export class DateInterval {
|
|
11
|
+
private constructor(public start: LocalDate, public end: LocalDate) {}
|
|
12
|
+
|
|
13
|
+
static of(start: LocalDateConfig, end: LocalDateConfig): DateInterval {
|
|
14
|
+
return new DateInterval(LocalDate.of(start), LocalDate.of(end))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
19
|
+
*/
|
|
20
|
+
static parse(d: DateIntervalConfig): DateInterval {
|
|
21
|
+
if (d instanceof DateInterval) return d
|
|
22
|
+
|
|
23
|
+
const [start, end] = d.split('/')
|
|
24
|
+
|
|
25
|
+
if (!end || !start) {
|
|
26
|
+
throw new Error(`Cannot parse "${d}" into DateInterval`)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new DateInterval(LocalDate.of(start), LocalDate.of(end))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
isSame(d: DateIntervalConfig): boolean {
|
|
33
|
+
return this.cmp(d) === 0
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
isBefore(d: DateIntervalConfig): boolean {
|
|
37
|
+
return this.cmp(d) === -1
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
isSameOrBefore(d: DateIntervalConfig): boolean {
|
|
41
|
+
return this.cmp(d) <= 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
isAfter(d: DateIntervalConfig): boolean {
|
|
45
|
+
return this.cmp(d) === 1
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
isSameOrAfter(d: DateIntervalConfig): boolean {
|
|
49
|
+
return this.cmp(d) >= 0
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* DateIntervals compare by start date.
|
|
54
|
+
* If it's the same - then by end date.
|
|
55
|
+
*/
|
|
56
|
+
cmp(d: DateIntervalConfig): -1 | 0 | 1 {
|
|
57
|
+
d = DateInterval.parse(d)
|
|
58
|
+
return this.start.cmp(d.start) || this.end.cmp(d.end)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toString(): string {
|
|
62
|
+
return [this.start, this.end].join('/')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private toJSON(): string {
|
|
66
|
+
return this.toString()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -27,6 +27,9 @@ export interface LocalTimeComponents {
|
|
|
27
27
|
// .valueOf returns unix timestamp (no millis)
|
|
28
28
|
// Prevents dayjs(undefined) being dayjs.now()
|
|
29
29
|
// Validates on parse, throws if invalid. Doesn't allow invalid objects
|
|
30
|
+
// No arbitrary .format('') (which is slow to parse) vs well-defined (opinionated) formats
|
|
31
|
+
// Separate LocalTime, powered by native js Date, and LocalDate - a smaller functionality class when
|
|
32
|
+
// you only need "whole dates", no time, no timezone worry
|
|
30
33
|
/**
|
|
31
34
|
* @experimental
|
|
32
35
|
*/
|
package/src/index.ts
CHANGED
|
@@ -158,10 +158,13 @@ export * from './math/stack.util'
|
|
|
158
158
|
export * from './string/leven'
|
|
159
159
|
export * from './datetime/localDate'
|
|
160
160
|
export * from './datetime/localTime'
|
|
161
|
+
export * from './datetime/dateInterval'
|
|
161
162
|
import { LocalDateConfig, LocalDateUnit } from './datetime/localDate'
|
|
162
163
|
import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime'
|
|
164
|
+
import { DateIntervalConfig } from './datetime/dateInterval'
|
|
163
165
|
|
|
164
166
|
export type {
|
|
167
|
+
DateIntervalConfig,
|
|
165
168
|
LocalDateConfig,
|
|
166
169
|
LocalDateUnit,
|
|
167
170
|
LocalTimeConfig,
|