@bbn/bbn 1.0.439 → 1.0.441
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/date.js +91 -8
- package/package.json +1 -1
package/dist/date.js
CHANGED
|
@@ -9,11 +9,91 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _bbnDateTool_value, _bbnDateTool_daysInMonth
|
|
12
|
+
var _bbnDateTool_value, _bbnDateTool_daysInMonth;
|
|
13
13
|
import each from './fn/loop/each.js';
|
|
14
14
|
import substr from './fn/string/substr.js';
|
|
15
15
|
import isNumber from './fn/type/isNumber.js';
|
|
16
16
|
import isDate from './fn/type/isDate.js';
|
|
17
|
+
const patterns = [
|
|
18
|
+
// MariaDB DATETIME "YYYY-MM-DD HH:MM:SS"
|
|
19
|
+
{
|
|
20
|
+
name: 'mariadb-datetime',
|
|
21
|
+
re: /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})$/,
|
|
22
|
+
map: m => ({
|
|
23
|
+
year: +m[1],
|
|
24
|
+
month: +m[2],
|
|
25
|
+
day: +m[3],
|
|
26
|
+
hours: +m[4],
|
|
27
|
+
minutes: +m[5],
|
|
28
|
+
seconds: +m[6],
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
// MariaDB DATETIME without seconds "YYYY-MM-DD HH:MM"
|
|
32
|
+
{
|
|
33
|
+
name: 'mariadb-datetime-no-sec',
|
|
34
|
+
re: /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})$/,
|
|
35
|
+
map: m => ({
|
|
36
|
+
year: +m[1],
|
|
37
|
+
month: +m[2],
|
|
38
|
+
day: +m[3],
|
|
39
|
+
hours: +m[4],
|
|
40
|
+
minutes: +m[5],
|
|
41
|
+
seconds: 0,
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
// MariaDB DATE "YYYY-MM-DD"
|
|
45
|
+
{
|
|
46
|
+
name: 'mariadb-date',
|
|
47
|
+
re: /^(\d{4})-(\d{2})-(\d{2})$/,
|
|
48
|
+
map: m => ({
|
|
49
|
+
year: +m[1],
|
|
50
|
+
month: +m[2],
|
|
51
|
+
day: +m[3],
|
|
52
|
+
hours: 0,
|
|
53
|
+
minutes: 0,
|
|
54
|
+
seconds: 0,
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
// ISO / JS-style "YYYY-MM-DDTHH:MM[:SS][.sss][Z or ±HH:MM]"
|
|
58
|
+
{
|
|
59
|
+
name: 'iso-datetime',
|
|
60
|
+
re: /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?(?:Z|[+\-]\d{2}:?\d{2})?$/,
|
|
61
|
+
map: m => ({
|
|
62
|
+
year: +m[1],
|
|
63
|
+
month: +m[2],
|
|
64
|
+
day: +m[3],
|
|
65
|
+
hours: +m[4],
|
|
66
|
+
minutes: +m[5],
|
|
67
|
+
seconds: m[6] !== undefined ? +m[6] : 0,
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
// Simple slash date "YYYY/MM/DD"
|
|
71
|
+
{
|
|
72
|
+
name: 'slash-date',
|
|
73
|
+
re: /^(\d{2})\/(\d{2})\/(\d{4})$/,
|
|
74
|
+
map: m => ({
|
|
75
|
+
year: +m[3],
|
|
76
|
+
month: +m[2],
|
|
77
|
+
day: +m[1],
|
|
78
|
+
hours: 0,
|
|
79
|
+
minutes: 0,
|
|
80
|
+
seconds: 0,
|
|
81
|
+
})
|
|
82
|
+
},
|
|
83
|
+
// Slash datetime "YYYY/MM/DD HH:MM:SS"
|
|
84
|
+
{
|
|
85
|
+
name: 'slash-datetime',
|
|
86
|
+
re: /^(\d{2})\/(\d{2})\/(\d{4})[ T](\d{2}):(\d{2}):(\d{2})$/,
|
|
87
|
+
map: m => ({
|
|
88
|
+
year: +m[3],
|
|
89
|
+
month: +m[2],
|
|
90
|
+
day: +m[1],
|
|
91
|
+
hours: +m[4],
|
|
92
|
+
minutes: +m[5],
|
|
93
|
+
seconds: +m[6],
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
];
|
|
17
97
|
const unitsMap = {
|
|
18
98
|
'y': 'FullYear',
|
|
19
99
|
'm': 'Month',
|
|
@@ -62,7 +142,6 @@ class bbnDateTool {
|
|
|
62
142
|
constructor(value, inputFormat = null) {
|
|
63
143
|
_bbnDateTool_value.set(this, void 0);
|
|
64
144
|
_bbnDateTool_daysInMonth.set(this, undefined);
|
|
65
|
-
_bbnDateTool_parts.set(this, undefined);
|
|
66
145
|
if (!value) {
|
|
67
146
|
__classPrivateFieldSet(this, _bbnDateTool_value, new Date(), "f");
|
|
68
147
|
}
|
|
@@ -83,11 +162,15 @@ class bbnDateTool {
|
|
|
83
162
|
}
|
|
84
163
|
}
|
|
85
164
|
if (t === 'string') {
|
|
86
|
-
|
|
87
|
-
|
|
165
|
+
for (const p of patterns) {
|
|
166
|
+
const m = value.match(p.re);
|
|
167
|
+
if (m) {
|
|
168
|
+
const { year, month, day, hours, minutes, seconds } = p.map(m);
|
|
169
|
+
__classPrivateFieldSet(this, _bbnDateTool_value, new Date(year, month - 1, day, hours, minutes, seconds, 0), "f");
|
|
170
|
+
}
|
|
88
171
|
}
|
|
89
|
-
|
|
90
|
-
|
|
172
|
+
if (!__classPrivateFieldGet(this, _bbnDateTool_value, "f")) {
|
|
173
|
+
throw new Error('Invalid date string format: ' + value);
|
|
91
174
|
}
|
|
92
175
|
}
|
|
93
176
|
else if (isDate(value)) {
|
|
@@ -181,7 +264,7 @@ class bbnDateTool {
|
|
|
181
264
|
each(parts, (part) => {
|
|
182
265
|
if (part in unitsCorrespondence) {
|
|
183
266
|
const suffix = unitsMap[unitsCorrespondence[part]];
|
|
184
|
-
str += date[
|
|
267
|
+
str += date[suffix];
|
|
185
268
|
}
|
|
186
269
|
else {
|
|
187
270
|
str += part;
|
|
@@ -332,7 +415,7 @@ class bbnDateTool {
|
|
|
332
415
|
return __classPrivateFieldGet(this, _bbnDateTool_daysInMonth, "f");
|
|
333
416
|
}
|
|
334
417
|
}
|
|
335
|
-
_bbnDateTool_value = new WeakMap(), _bbnDateTool_daysInMonth = new WeakMap()
|
|
418
|
+
_bbnDateTool_value = new WeakMap(), _bbnDateTool_daysInMonth = new WeakMap();
|
|
336
419
|
function generatorFunction(value, inputFormat = null) {
|
|
337
420
|
return new bbnDateTool(value, inputFormat);
|
|
338
421
|
}
|