@naturalcycles/js-lib 14.228.0 → 14.229.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 +4 -0
- package/dist/datetime/localDate.js +9 -1
- package/dist/datetime/localTime.js +4 -35
- package/dist-esm/datetime/localDate.js +7 -0
- package/dist-esm/datetime/localTime.js +4 -35
- package/package.json +1 -1
- package/src/datetime/localDate.ts +8 -0
- package/src/datetime/localTime.ts +4 -42
|
@@ -145,3 +145,7 @@ export declare function localDateOrUndefined(d?: LocalDateInput | null): LocalDa
|
|
|
145
145
|
* Creates a LocalDate from the input, unless it's falsy - then returns LocalDate.today.
|
|
146
146
|
*/
|
|
147
147
|
export declare function localDateOrToday(d?: LocalDateInput | null): LocalDate;
|
|
148
|
+
/**
|
|
149
|
+
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
150
|
+
*/
|
|
151
|
+
export declare function todayIsoDateString(): IsoDateString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.localDateOrToday = exports.localDateOrUndefined = exports.localDateToday = exports.localDate = exports.localDateRangeIterable = exports.localDateRange = exports.LocalDate = void 0;
|
|
3
|
+
exports.todayIsoDateString = exports.localDateOrToday = exports.localDateOrUndefined = exports.localDateToday = exports.localDate = exports.localDateRangeIterable = exports.localDateRange = exports.LocalDate = void 0;
|
|
4
4
|
const assert_1 = require("../error/assert");
|
|
5
5
|
const iterable2_1 = require("../iter/iterable2");
|
|
6
6
|
const localTime_1 = require("./localTime");
|
|
@@ -496,3 +496,11 @@ function localDateOrToday(d) {
|
|
|
496
496
|
return d ? LocalDate.of(d) : LocalDate.today();
|
|
497
497
|
}
|
|
498
498
|
exports.localDateOrToday = localDateOrToday;
|
|
499
|
+
/**
|
|
500
|
+
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
501
|
+
*/
|
|
502
|
+
function todayIsoDateString() {
|
|
503
|
+
// It was benchmarked to be faster than by concatenating individual Date components
|
|
504
|
+
return new Date().toISOString().slice(0, 10);
|
|
505
|
+
}
|
|
506
|
+
exports.todayIsoDateString = todayIsoDateString;
|
|
@@ -443,25 +443,8 @@ class LocalTime {
|
|
|
443
443
|
return localDate_1.LocalDate.fromDate(this.$date);
|
|
444
444
|
}
|
|
445
445
|
toPretty(seconds = true) {
|
|
446
|
-
const
|
|
447
|
-
return (
|
|
448
|
-
String(year).padStart(4, '0'),
|
|
449
|
-
String(month).padStart(2, '0'),
|
|
450
|
-
String(day).padStart(2, '0'),
|
|
451
|
-
].join('-') +
|
|
452
|
-
' ' +
|
|
453
|
-
[
|
|
454
|
-
String(hour).padStart(2, '0'),
|
|
455
|
-
String(minute).padStart(2, '0'),
|
|
456
|
-
seconds && String(second).padStart(2, '0'),
|
|
457
|
-
]
|
|
458
|
-
.filter(Boolean)
|
|
459
|
-
.join(':'));
|
|
460
|
-
// return this.$date
|
|
461
|
-
// .toISOString()
|
|
462
|
-
// .slice(0, seconds ? 19 : 16)
|
|
463
|
-
// .split('T')
|
|
464
|
-
// .join(' ')
|
|
446
|
+
const s = this.$date.toISOString();
|
|
447
|
+
return s.slice(0, 10) + ' ' + s.slice(11, seconds ? 19 : 16);
|
|
465
448
|
}
|
|
466
449
|
/**
|
|
467
450
|
* Returns e.g: `1984-06-21T17:56:21`
|
|
@@ -473,27 +456,13 @@ class LocalTime {
|
|
|
473
456
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
474
457
|
*/
|
|
475
458
|
toISODate() {
|
|
476
|
-
|
|
477
|
-
return [
|
|
478
|
-
String(year).padStart(4, '0'),
|
|
479
|
-
String(month).padStart(2, '0'),
|
|
480
|
-
String(day).padStart(2, '0'),
|
|
481
|
-
].join('-');
|
|
482
|
-
// return this.$date.toISOString().slice(0, 10)
|
|
459
|
+
return this.$date.toISOString().slice(0, 10);
|
|
483
460
|
}
|
|
484
461
|
/**
|
|
485
462
|
* Returns e.g: `17:03:15` (or `17:03` with seconds=false)
|
|
486
463
|
*/
|
|
487
464
|
toISOTime(seconds = true) {
|
|
488
|
-
|
|
489
|
-
const { hour, minute, second } = this.components();
|
|
490
|
-
return [
|
|
491
|
-
String(hour).padStart(2, '0'),
|
|
492
|
-
String(minute).padStart(2, '0'),
|
|
493
|
-
seconds && String(second).padStart(2, '0'),
|
|
494
|
-
]
|
|
495
|
-
.filter(Boolean)
|
|
496
|
-
.join(':');
|
|
465
|
+
return this.$date.toISOString().slice(11, seconds ? 19 : 16);
|
|
497
466
|
}
|
|
498
467
|
/**
|
|
499
468
|
* Returns e.g: `19840621_1705`
|
|
@@ -486,3 +486,10 @@ export function localDateOrUndefined(d) {
|
|
|
486
486
|
export function localDateOrToday(d) {
|
|
487
487
|
return d ? LocalDate.of(d) : LocalDate.today();
|
|
488
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
491
|
+
*/
|
|
492
|
+
export function todayIsoDateString() {
|
|
493
|
+
// It was benchmarked to be faster than by concatenating individual Date components
|
|
494
|
+
return new Date().toISOString().slice(0, 10);
|
|
495
|
+
}
|
|
@@ -441,25 +441,8 @@ export class LocalTime {
|
|
|
441
441
|
return LocalDate.fromDate(this.$date);
|
|
442
442
|
}
|
|
443
443
|
toPretty(seconds = true) {
|
|
444
|
-
const
|
|
445
|
-
return (
|
|
446
|
-
String(year).padStart(4, '0'),
|
|
447
|
-
String(month).padStart(2, '0'),
|
|
448
|
-
String(day).padStart(2, '0'),
|
|
449
|
-
].join('-') +
|
|
450
|
-
' ' +
|
|
451
|
-
[
|
|
452
|
-
String(hour).padStart(2, '0'),
|
|
453
|
-
String(minute).padStart(2, '0'),
|
|
454
|
-
seconds && String(second).padStart(2, '0'),
|
|
455
|
-
]
|
|
456
|
-
.filter(Boolean)
|
|
457
|
-
.join(':'));
|
|
458
|
-
// return this.$date
|
|
459
|
-
// .toISOString()
|
|
460
|
-
// .slice(0, seconds ? 19 : 16)
|
|
461
|
-
// .split('T')
|
|
462
|
-
// .join(' ')
|
|
444
|
+
const s = this.$date.toISOString();
|
|
445
|
+
return s.slice(0, 10) + ' ' + s.slice(11, seconds ? 19 : 16);
|
|
463
446
|
}
|
|
464
447
|
/**
|
|
465
448
|
* Returns e.g: `1984-06-21T17:56:21`
|
|
@@ -471,27 +454,13 @@ export class LocalTime {
|
|
|
471
454
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
472
455
|
*/
|
|
473
456
|
toISODate() {
|
|
474
|
-
|
|
475
|
-
return [
|
|
476
|
-
String(year).padStart(4, '0'),
|
|
477
|
-
String(month).padStart(2, '0'),
|
|
478
|
-
String(day).padStart(2, '0'),
|
|
479
|
-
].join('-');
|
|
480
|
-
// return this.$date.toISOString().slice(0, 10)
|
|
457
|
+
return this.$date.toISOString().slice(0, 10);
|
|
481
458
|
}
|
|
482
459
|
/**
|
|
483
460
|
* Returns e.g: `17:03:15` (or `17:03` with seconds=false)
|
|
484
461
|
*/
|
|
485
462
|
toISOTime(seconds = true) {
|
|
486
|
-
|
|
487
|
-
const { hour, minute, second } = this.components();
|
|
488
|
-
return [
|
|
489
|
-
String(hour).padStart(2, '0'),
|
|
490
|
-
String(minute).padStart(2, '0'),
|
|
491
|
-
seconds && String(second).padStart(2, '0'),
|
|
492
|
-
]
|
|
493
|
-
.filter(Boolean)
|
|
494
|
-
.join(':');
|
|
463
|
+
return this.$date.toISOString().slice(11, seconds ? 19 : 16);
|
|
495
464
|
}
|
|
496
465
|
/**
|
|
497
466
|
* Returns e.g: `19840621_1705`
|
package/package.json
CHANGED
|
@@ -602,3 +602,11 @@ export function localDateOrUndefined(d?: LocalDateInput | null): LocalDate | und
|
|
|
602
602
|
export function localDateOrToday(d?: LocalDateInput | null): LocalDate {
|
|
603
603
|
return d ? LocalDate.of(d) : LocalDate.today()
|
|
604
604
|
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
608
|
+
*/
|
|
609
|
+
export function todayIsoDateString(): IsoDateString {
|
|
610
|
+
// It was benchmarked to be faster than by concatenating individual Date components
|
|
611
|
+
return new Date().toISOString().slice(0, 10)
|
|
612
|
+
}
|
|
@@ -541,29 +541,8 @@ export class LocalTime {
|
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
toPretty(seconds = true): IsoDateTimeString {
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
return (
|
|
547
|
-
[
|
|
548
|
-
String(year).padStart(4, '0'),
|
|
549
|
-
String(month).padStart(2, '0'),
|
|
550
|
-
String(day).padStart(2, '0'),
|
|
551
|
-
].join('-') +
|
|
552
|
-
' ' +
|
|
553
|
-
[
|
|
554
|
-
String(hour).padStart(2, '0'),
|
|
555
|
-
String(minute).padStart(2, '0'),
|
|
556
|
-
seconds && String(second).padStart(2, '0'),
|
|
557
|
-
]
|
|
558
|
-
.filter(Boolean)
|
|
559
|
-
.join(':')
|
|
560
|
-
)
|
|
561
|
-
|
|
562
|
-
// return this.$date
|
|
563
|
-
// .toISOString()
|
|
564
|
-
// .slice(0, seconds ? 19 : 16)
|
|
565
|
-
// .split('T')
|
|
566
|
-
// .join(' ')
|
|
544
|
+
const s = this.$date.toISOString()
|
|
545
|
+
return s.slice(0, 10) + ' ' + s.slice(11, seconds ? 19 : 16)
|
|
567
546
|
}
|
|
568
547
|
|
|
569
548
|
/**
|
|
@@ -577,31 +556,14 @@ export class LocalTime {
|
|
|
577
556
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
578
557
|
*/
|
|
579
558
|
toISODate(): IsoDateString {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return [
|
|
583
|
-
String(year).padStart(4, '0'),
|
|
584
|
-
String(month).padStart(2, '0'),
|
|
585
|
-
String(day).padStart(2, '0'),
|
|
586
|
-
].join('-')
|
|
587
|
-
|
|
588
|
-
// return this.$date.toISOString().slice(0, 10)
|
|
559
|
+
return this.$date.toISOString().slice(0, 10)
|
|
589
560
|
}
|
|
590
561
|
|
|
591
562
|
/**
|
|
592
563
|
* Returns e.g: `17:03:15` (or `17:03` with seconds=false)
|
|
593
564
|
*/
|
|
594
565
|
toISOTime(seconds = true): string {
|
|
595
|
-
|
|
596
|
-
const { hour, minute, second } = this.components()
|
|
597
|
-
|
|
598
|
-
return [
|
|
599
|
-
String(hour).padStart(2, '0'),
|
|
600
|
-
String(minute).padStart(2, '0'),
|
|
601
|
-
seconds && String(second).padStart(2, '0'),
|
|
602
|
-
]
|
|
603
|
-
.filter(Boolean)
|
|
604
|
-
.join(':')
|
|
566
|
+
return this.$date.toISOString().slice(11, seconds ? 19 : 16)
|
|
605
567
|
}
|
|
606
568
|
|
|
607
569
|
/**
|