@naturalcycles/js-lib 14.139.3 → 14.140.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/localDate.d.ts +1 -1
- package/dist/datetime/localDate.js +3 -0
- package/dist/datetime/localTime.js +1 -1
- package/dist-esm/datetime/localDate.js +3 -0
- package/dist-esm/datetime/localTime.js +1 -1
- package/package.json +1 -1
- package/src/datetime/localDate.ts +4 -1
- package/src/datetime/localTime.ts +1 -5
|
@@ -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 LocalDateConfig = LocalDate | IsoDateString;
|
|
6
|
+
export type LocalDateConfig = LocalDate | Date | IsoDateString;
|
|
7
7
|
export type LocalDateFormatter = (ld: LocalDate) => string;
|
|
8
8
|
/**
|
|
9
9
|
* @experimental
|
|
@@ -50,6 +50,9 @@ class LocalDate {
|
|
|
50
50
|
return null;
|
|
51
51
|
if (d instanceof LocalDate)
|
|
52
52
|
return d;
|
|
53
|
+
if (d instanceof Date) {
|
|
54
|
+
return this.fromDate(d);
|
|
55
|
+
}
|
|
53
56
|
// const [year, month, day] = d.slice(0, 10).split('-').map(Number)
|
|
54
57
|
const matches = typeof d === 'string' && DATE_REGEX.exec(d.slice(0, 10));
|
|
55
58
|
if (!matches)
|
|
@@ -406,7 +406,7 @@ class LocalTime {
|
|
|
406
406
|
return Math.floor(this.$date.valueOf() / 1000);
|
|
407
407
|
}
|
|
408
408
|
toLocalDate() {
|
|
409
|
-
return localDate_1.LocalDate.
|
|
409
|
+
return localDate_1.LocalDate.fromDate(this.$date);
|
|
410
410
|
}
|
|
411
411
|
toPretty(seconds = true) {
|
|
412
412
|
const { year, month, day, hour, minute, second } = this.components();
|
|
@@ -47,6 +47,9 @@ export class LocalDate {
|
|
|
47
47
|
return null;
|
|
48
48
|
if (d instanceof LocalDate)
|
|
49
49
|
return d;
|
|
50
|
+
if (d instanceof Date) {
|
|
51
|
+
return this.fromDate(d);
|
|
52
|
+
}
|
|
50
53
|
// const [year, month, day] = d.slice(0, 10).split('-').map(Number)
|
|
51
54
|
const matches = typeof d === 'string' && DATE_REGEX.exec(d.slice(0, 10));
|
|
52
55
|
if (!matches)
|
|
@@ -404,7 +404,7 @@ export class LocalTime {
|
|
|
404
404
|
return Math.floor(this.$date.valueOf() / 1000);
|
|
405
405
|
}
|
|
406
406
|
toLocalDate() {
|
|
407
|
-
return LocalDate.
|
|
407
|
+
return LocalDate.fromDate(this.$date);
|
|
408
408
|
}
|
|
409
409
|
toPretty(seconds = true) {
|
|
410
410
|
const { year, month, day, hour, minute, second } = this.components();
|
package/package.json
CHANGED
|
@@ -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 LocalDateConfig = LocalDate | IsoDateString
|
|
17
|
+
export type LocalDateConfig = LocalDate | Date | IsoDateString
|
|
18
18
|
export type LocalDateFormatter = (ld: LocalDate) => string
|
|
19
19
|
|
|
20
20
|
/* eslint-disable no-dupe-class-members */
|
|
@@ -67,6 +67,9 @@ export class LocalDate {
|
|
|
67
67
|
static parseOrNull(d: LocalDateConfig | undefined | null): LocalDate | null {
|
|
68
68
|
if (!d) return null
|
|
69
69
|
if (d instanceof LocalDate) return d
|
|
70
|
+
if (d instanceof Date) {
|
|
71
|
+
return this.fromDate(d)
|
|
72
|
+
}
|
|
70
73
|
|
|
71
74
|
// const [year, month, day] = d.slice(0, 10).split('-').map(Number)
|
|
72
75
|
const matches = typeof (d as any) === 'string' && DATE_REGEX.exec(d.slice(0, 10))
|
|
@@ -497,11 +497,7 @@ export class LocalTime {
|
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
toLocalDate(): LocalDate {
|
|
500
|
-
return LocalDate.
|
|
501
|
-
this.$date.getFullYear(),
|
|
502
|
-
this.$date.getMonth() + 1,
|
|
503
|
-
this.$date.getDate(),
|
|
504
|
-
)
|
|
500
|
+
return LocalDate.fromDate(this.$date)
|
|
505
501
|
}
|
|
506
502
|
|
|
507
503
|
toPretty(seconds = true): IsoDateTimeString {
|