@bbn/bbn 2.0.149 → 2.0.151
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/dt/classes/dt.d.ts +3 -1
- package/dist/dt/classes/dt.js +19 -5
- package/dist/dt/functions/parse.js +25 -14
- package/dist/dt/vars/units.js +7 -3
- package/package.json +5 -4
package/dist/dt/classes/dt.d.ts
CHANGED
|
@@ -90,6 +90,8 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
90
90
|
get S(): string;
|
|
91
91
|
get WW(): string;
|
|
92
92
|
get W(): string;
|
|
93
|
+
get Z(): string;
|
|
94
|
+
get ZZ(): string;
|
|
93
95
|
unix(ms?: boolean | number): number | bbnDt<any>;
|
|
94
96
|
format(format?: string): string;
|
|
95
97
|
calendar(short?: boolean): string;
|
|
@@ -113,7 +115,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
113
115
|
startOf(unit?: string): bbnDt<any>;
|
|
114
116
|
endOf(unit?: string): bbnDt<any>;
|
|
115
117
|
clone(): bbnDt<any>;
|
|
116
|
-
|
|
118
|
+
isLeapYear(): boolean;
|
|
117
119
|
daysInMonth(): number;
|
|
118
120
|
valueOf(): number;
|
|
119
121
|
}
|
package/dist/dt/classes/dt.js
CHANGED
|
@@ -431,7 +431,7 @@ export class bbnDt {
|
|
|
431
431
|
if ((v !== undefined) && !(v instanceof Event)) {
|
|
432
432
|
return this.setWeekday(v, past);
|
|
433
433
|
}
|
|
434
|
-
return this.value.dayOfWeek;
|
|
434
|
+
return this.value.dayOfWeek % 7;
|
|
435
435
|
}
|
|
436
436
|
date(v) {
|
|
437
437
|
if (!this.value) {
|
|
@@ -640,6 +640,20 @@ export class bbnDt {
|
|
|
640
640
|
}
|
|
641
641
|
return undefined;
|
|
642
642
|
}
|
|
643
|
+
get Z() {
|
|
644
|
+
if (this.kind === 'zoned') {
|
|
645
|
+
const zdt = this.value;
|
|
646
|
+
return zdt.offset;
|
|
647
|
+
}
|
|
648
|
+
return undefined;
|
|
649
|
+
}
|
|
650
|
+
get ZZ() {
|
|
651
|
+
if (this.kind === 'zoned') {
|
|
652
|
+
const zdt = this.value;
|
|
653
|
+
return zdt.offset.replace(':', '');
|
|
654
|
+
}
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
643
657
|
unix(ms = false) {
|
|
644
658
|
if (typeof ms === 'number') {
|
|
645
659
|
const Ctor = this.constructor;
|
|
@@ -673,7 +687,7 @@ export class bbnDt {
|
|
|
673
687
|
}
|
|
674
688
|
else {
|
|
675
689
|
const suffix = formatsMap[unitsCorrespondence[part]];
|
|
676
|
-
str += this[suffix];
|
|
690
|
+
str += this[suffix] || '';
|
|
677
691
|
}
|
|
678
692
|
}
|
|
679
693
|
else {
|
|
@@ -826,7 +840,7 @@ export class bbnDt {
|
|
|
826
840
|
throw new Error('Invalid unit for diff: ' + unit);
|
|
827
841
|
}
|
|
828
842
|
const [, , ms] = match; // [shortUnit, rtfUnit, ms]
|
|
829
|
-
return Math.
|
|
843
|
+
return Math.floor(diff / ms);
|
|
830
844
|
}
|
|
831
845
|
guessUnit(valueInMs) {
|
|
832
846
|
const absDiff = Math.abs(valueInMs);
|
|
@@ -1059,7 +1073,7 @@ export class bbnDt {
|
|
|
1059
1073
|
clone() {
|
|
1060
1074
|
return this.withValue(this.value);
|
|
1061
1075
|
}
|
|
1062
|
-
|
|
1076
|
+
isLeapYear() {
|
|
1063
1077
|
if (this.isValid) {
|
|
1064
1078
|
const year = this.year();
|
|
1065
1079
|
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
|
|
@@ -1088,7 +1102,7 @@ export class bbnDt {
|
|
|
1088
1102
|
}
|
|
1089
1103
|
}
|
|
1090
1104
|
valueOf() {
|
|
1091
|
-
return this.unix();
|
|
1105
|
+
return this.unix(true);
|
|
1092
1106
|
}
|
|
1093
1107
|
}
|
|
1094
1108
|
_bbnDt_value = new WeakMap();
|
|
@@ -411,10 +411,10 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
411
411
|
ctx.week = n;
|
|
412
412
|
}
|
|
413
413
|
},
|
|
414
|
-
// Timezone offset
|
|
414
|
+
// Timezone offset
|
|
415
415
|
{
|
|
416
|
-
token: '
|
|
417
|
-
regex: '(?:Z
|
|
416
|
+
token: 'ZZ',
|
|
417
|
+
regex: '(?:Z?[+-]\\d{2}\\d{2})',
|
|
418
418
|
apply: (v, ctx) => {
|
|
419
419
|
if (v === 'Z' || v === 'z') {
|
|
420
420
|
ctx.offsetMinutes = 0;
|
|
@@ -422,17 +422,27 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
422
422
|
}
|
|
423
423
|
const sign = v[0] === '-' ? -1 : 1;
|
|
424
424
|
const rest = v.slice(1); // "02:00" or "0500"
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
hh = parseInt(h, 10);
|
|
430
|
-
mm = parseInt(m, 10);
|
|
425
|
+
const hh = parseInt(rest.slice(0, 2), 10);
|
|
426
|
+
const mm = parseInt(rest.slice(2), 10);
|
|
427
|
+
if (hh < 0 || hh > 23 || mm < 0 || mm > 59) {
|
|
428
|
+
throw new Error('Invalid timezone offset: ' + v);
|
|
431
429
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
430
|
+
ctx.offsetMinutes = sign * (hh * 60 + mm);
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
token: 'Z',
|
|
435
|
+
regex: '(?:Z?[+-]\\d{2}\\:{1}\\d{2})',
|
|
436
|
+
apply: (v, ctx) => {
|
|
437
|
+
if (v === 'Z' || v === 'z') {
|
|
438
|
+
ctx.offsetMinutes = 0;
|
|
439
|
+
return;
|
|
435
440
|
}
|
|
441
|
+
const sign = v[0] === '-' ? -1 : 1;
|
|
442
|
+
const rest = v.slice(1); // "02:00" or "0500"
|
|
443
|
+
const [h, m] = rest.split(':');
|
|
444
|
+
let hh = parseInt(h, 10);
|
|
445
|
+
let mm = parseInt(m, 10);
|
|
436
446
|
if (hh < 0 || hh > 23 || mm < 0 || mm > 59) {
|
|
437
447
|
throw new Error('Invalid timezone offset: ' + v);
|
|
438
448
|
}
|
|
@@ -467,8 +477,9 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
467
477
|
];
|
|
468
478
|
function parseWithFormat(fmt, cls = 'auto') {
|
|
469
479
|
var _a;
|
|
480
|
+
const currentDate = new bbnDtDateTime();
|
|
470
481
|
const ctx = {
|
|
471
|
-
year:
|
|
482
|
+
year: currentDate.year(),
|
|
472
483
|
month: 1,
|
|
473
484
|
day: 1,
|
|
474
485
|
hour: 0,
|
|
@@ -545,7 +556,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
545
556
|
let match = fullRegex.exec(input);
|
|
546
557
|
if (!match) {
|
|
547
558
|
if (force) {
|
|
548
|
-
const inputDate = new bbnDtDateTime(
|
|
559
|
+
const inputDate = new bbnDtDateTime(currentDate.year(), 1, 1, 0, 0, 0, 0);
|
|
549
560
|
input = inputDate.format(fmt);
|
|
550
561
|
isValid = false;
|
|
551
562
|
match = fullRegex.exec(input);
|
package/dist/dt/vars/units.js
CHANGED
|
@@ -85,7 +85,9 @@ const unitsCorrespondence = {
|
|
|
85
85
|
's': 's',
|
|
86
86
|
'S': 's',
|
|
87
87
|
'W': 'w',
|
|
88
|
-
'w': 'w'
|
|
88
|
+
'w': 'w',
|
|
89
|
+
'ZZ': 'z',
|
|
90
|
+
'Z': 'z'
|
|
89
91
|
};
|
|
90
92
|
const unitsMap = {
|
|
91
93
|
'y': 'Year',
|
|
@@ -94,7 +96,8 @@ const unitsMap = {
|
|
|
94
96
|
'w': 'Week',
|
|
95
97
|
'h': 'Hours',
|
|
96
98
|
'i': 'Minutes',
|
|
97
|
-
's': 'Seconds'
|
|
99
|
+
's': 'Seconds',
|
|
100
|
+
'z': 'Offset'
|
|
98
101
|
};
|
|
99
102
|
const formatsMap = {
|
|
100
103
|
'y': 'YYYY',
|
|
@@ -104,6 +107,7 @@ const formatsMap = {
|
|
|
104
107
|
'w': 'WW',
|
|
105
108
|
'h': 'HH',
|
|
106
109
|
'i': 'II',
|
|
107
|
-
's': 'SS'
|
|
110
|
+
's': 'SS',
|
|
111
|
+
'z': 'Z'
|
|
108
112
|
};
|
|
109
113
|
export { units, unitsCorrespondence, unitsMap, formatsMap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbn/bbn",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.151",
|
|
4
4
|
"description": "Javascript toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"pub": "npm version patch && npm publish",
|
|
16
16
|
"build": "./node_modules/.bin/rollup -c",
|
|
17
17
|
"all": "npm run type && npm run test && npm run gitauto && npm version patch && npm run build && npm run gitend && npm publish",
|
|
18
|
-
"test": "IS_TESTING=true mocha
|
|
18
|
+
"test": "IS_TESTING=true npx mocha",
|
|
19
19
|
"wtf": "echo \"Error: no test specified\" && exit 1"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
33
33
|
"@types/mocha": "^10.0.10",
|
|
34
34
|
"chai": "^6.2.1",
|
|
35
|
-
"
|
|
36
|
-
"jsdom
|
|
35
|
+
"dayjs": "^1.11.19",
|
|
36
|
+
"jsdom": "^27.2.0",
|
|
37
|
+
"jsdom-global": "^3.0.2",
|
|
37
38
|
"mocha": "^11.7.5",
|
|
38
39
|
"rollup": "^4.53.2",
|
|
39
40
|
"ts-loader": "^9.5.4",
|