@zkwq/business 0.0.2 → 0.0.3
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/index.css +1 -1
- package/dist/index.js +4449 -4444
- package/dist/index.umd.cjs +14 -14
- package/dist/var.scss +1011 -0
- package/package.json +1 -1
- package/src/components/base/ui/style/var.scss +4 -0
- package/src/components/base/ui/util/date.js +294 -309
- package/vite.config.js +1 -0
package/package.json
CHANGED
|
@@ -25,346 +25,331 @@
|
|
|
25
25
|
|
|
26
26
|
/*eslint-disable*/
|
|
27
27
|
// 把 YYYY-MM-DD 改成了 yyyy-MM-dd
|
|
28
|
-
let fecha1;
|
|
29
|
-
(function (main) {
|
|
30
|
-
'use strict';
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Parse or format dates
|
|
31
|
+
* @class fecha
|
|
32
|
+
*/
|
|
33
|
+
var fecha = {};
|
|
34
|
+
var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
|
|
35
|
+
var twoDigits = '\\d\\d?';
|
|
36
|
+
var threeDigits = '\\d{3}';
|
|
37
|
+
var fourDigits = '\\d{4}';
|
|
38
|
+
var word = '[^\\s]+';
|
|
39
|
+
var literal = /\[([^]*?)\]/gm;
|
|
40
|
+
var noop = function () {
|
|
41
|
+
};
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
function regexEscape(str) {
|
|
44
|
+
return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function shorten(arr, sLen) {
|
|
48
|
+
var newArr = [];
|
|
49
|
+
for (var i = 0, len = arr.length; i < len; i++) {
|
|
50
|
+
newArr.push(arr[i].substr(0, sLen));
|
|
48
51
|
}
|
|
52
|
+
return newArr;
|
|
53
|
+
}
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
function monthUpdate(arrName) {
|
|
56
|
+
return function (d, v, i18n) {
|
|
57
|
+
var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
|
|
58
|
+
if (~index) {
|
|
59
|
+
d.month = index;
|
|
54
60
|
}
|
|
55
|
-
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function pad(val, len) {
|
|
65
|
+
val = String(val);
|
|
66
|
+
len = len || 2;
|
|
67
|
+
while (val.length < len) {
|
|
68
|
+
val = '0' + val;
|
|
56
69
|
}
|
|
70
|
+
return val;
|
|
71
|
+
}
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
74
|
+
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
75
|
+
var monthNamesShort = shorten(monthNames, 3);
|
|
76
|
+
var dayNamesShort = shorten(dayNames, 3);
|
|
77
|
+
fecha.i18n = {
|
|
78
|
+
dayNamesShort: dayNamesShort,
|
|
79
|
+
dayNames: dayNames,
|
|
80
|
+
monthNamesShort: monthNamesShort,
|
|
81
|
+
monthNames: monthNames,
|
|
82
|
+
amPm: ['am', 'pm'],
|
|
83
|
+
DoFn: function DoFn(D) {
|
|
84
|
+
return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
|
|
65
85
|
}
|
|
86
|
+
};
|
|
66
87
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
var formatFlags = {
|
|
89
|
+
D: function (dateObj) {
|
|
90
|
+
return dateObj.getDay();
|
|
91
|
+
},
|
|
92
|
+
DD: function (dateObj) {
|
|
93
|
+
return pad(dateObj.getDay());
|
|
94
|
+
},
|
|
95
|
+
Do: function (dateObj, i18n) {
|
|
96
|
+
return i18n.DoFn(dateObj.getDate());
|
|
97
|
+
},
|
|
98
|
+
d: function (dateObj) {
|
|
99
|
+
return dateObj.getDate();
|
|
100
|
+
},
|
|
101
|
+
dd: function (dateObj) {
|
|
102
|
+
return pad(dateObj.getDate());
|
|
103
|
+
},
|
|
104
|
+
ddd: function (dateObj, i18n) {
|
|
105
|
+
return i18n.dayNamesShort[dateObj.getDay()];
|
|
106
|
+
},
|
|
107
|
+
dddd: function (dateObj, i18n) {
|
|
108
|
+
return i18n.dayNames[dateObj.getDay()];
|
|
109
|
+
},
|
|
110
|
+
M: function (dateObj) {
|
|
111
|
+
return dateObj.getMonth() + 1;
|
|
112
|
+
},
|
|
113
|
+
MM: function (dateObj) {
|
|
114
|
+
return pad(dateObj.getMonth() + 1);
|
|
115
|
+
},
|
|
116
|
+
MMM: function (dateObj, i18n) {
|
|
117
|
+
return i18n.monthNamesShort[dateObj.getMonth()];
|
|
118
|
+
},
|
|
119
|
+
MMMM: function (dateObj, i18n) {
|
|
120
|
+
return i18n.monthNames[dateObj.getMonth()];
|
|
121
|
+
},
|
|
122
|
+
yy: function (dateObj) {
|
|
123
|
+
return pad(String(dateObj.getFullYear()), 4).substr(2);
|
|
124
|
+
},
|
|
125
|
+
yyyy: function (dateObj) {
|
|
126
|
+
return pad(dateObj.getFullYear(), 4);
|
|
127
|
+
},
|
|
128
|
+
h: function (dateObj) {
|
|
129
|
+
return dateObj.getHours() % 12 || 12;
|
|
130
|
+
},
|
|
131
|
+
hh: function (dateObj) {
|
|
132
|
+
return pad(dateObj.getHours() % 12 || 12);
|
|
133
|
+
},
|
|
134
|
+
H: function (dateObj) {
|
|
135
|
+
return dateObj.getHours();
|
|
136
|
+
},
|
|
137
|
+
HH: function (dateObj) {
|
|
138
|
+
return pad(dateObj.getHours());
|
|
139
|
+
},
|
|
140
|
+
m: function (dateObj) {
|
|
141
|
+
return dateObj.getMinutes();
|
|
142
|
+
},
|
|
143
|
+
mm: function (dateObj) {
|
|
144
|
+
return pad(dateObj.getMinutes());
|
|
145
|
+
},
|
|
146
|
+
s: function (dateObj) {
|
|
147
|
+
return dateObj.getSeconds();
|
|
148
|
+
},
|
|
149
|
+
ss: function (dateObj) {
|
|
150
|
+
return pad(dateObj.getSeconds());
|
|
151
|
+
},
|
|
152
|
+
S: function (dateObj) {
|
|
153
|
+
return Math.round(dateObj.getMilliseconds() / 100);
|
|
154
|
+
},
|
|
155
|
+
SS: function (dateObj) {
|
|
156
|
+
return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
|
|
157
|
+
},
|
|
158
|
+
SSS: function (dateObj) {
|
|
159
|
+
return pad(dateObj.getMilliseconds(), 3);
|
|
160
|
+
},
|
|
161
|
+
a: function (dateObj, i18n) {
|
|
162
|
+
return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
|
|
163
|
+
},
|
|
164
|
+
A: function (dateObj, i18n) {
|
|
165
|
+
return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
|
|
166
|
+
},
|
|
167
|
+
ZZ: function (dateObj) {
|
|
168
|
+
var o = dateObj.getTimezoneOffset();
|
|
169
|
+
return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
|
|
74
170
|
}
|
|
171
|
+
};
|
|
75
172
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
173
|
+
var parseFlags = {
|
|
174
|
+
d: [twoDigits, function (d, v) {
|
|
175
|
+
d.day = v;
|
|
176
|
+
}],
|
|
177
|
+
Do: [twoDigits + word, function (d, v) {
|
|
178
|
+
d.day = parseInt(v, 10);
|
|
179
|
+
}],
|
|
180
|
+
M: [twoDigits, function (d, v) {
|
|
181
|
+
d.month = v - 1;
|
|
182
|
+
}],
|
|
183
|
+
yy: [twoDigits, function (d, v) {
|
|
184
|
+
var da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
|
|
185
|
+
d.year = '' + (v > 68 ? cent - 1 : cent) + v;
|
|
186
|
+
}],
|
|
187
|
+
h: [twoDigits, function (d, v) {
|
|
188
|
+
d.hour = v;
|
|
189
|
+
}],
|
|
190
|
+
m: [twoDigits, function (d, v) {
|
|
191
|
+
d.minute = v;
|
|
192
|
+
}],
|
|
193
|
+
s: [twoDigits, function (d, v) {
|
|
194
|
+
d.second = v;
|
|
195
|
+
}],
|
|
196
|
+
yyyy: [fourDigits, function (d, v) {
|
|
197
|
+
d.year = v;
|
|
198
|
+
}],
|
|
199
|
+
S: ['\\d', function (d, v) {
|
|
200
|
+
d.millisecond = v * 100;
|
|
201
|
+
}],
|
|
202
|
+
SS: ['\\d{2}', function (d, v) {
|
|
203
|
+
d.millisecond = v * 10;
|
|
204
|
+
}],
|
|
205
|
+
SSS: [threeDigits, function (d, v) {
|
|
206
|
+
d.millisecond = v;
|
|
207
|
+
}],
|
|
208
|
+
D: [twoDigits, noop],
|
|
209
|
+
ddd: [word, noop],
|
|
210
|
+
MMM: [word, monthUpdate('monthNamesShort')],
|
|
211
|
+
MMMM: [word, monthUpdate('monthNames')],
|
|
212
|
+
a: [word, function (d, v, i18n) {
|
|
213
|
+
var val = v.toLowerCase();
|
|
214
|
+
if (val === i18n.amPm[0]) {
|
|
215
|
+
d.isPm = false;
|
|
216
|
+
} else if (val === i18n.amPm[1]) {
|
|
217
|
+
d.isPm = true;
|
|
88
218
|
}
|
|
89
|
-
}
|
|
219
|
+
}],
|
|
220
|
+
ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
|
|
221
|
+
var parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
|
|
90
222
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
DD: function(dateObj) {
|
|
96
|
-
return pad(dateObj.getDay());
|
|
97
|
-
},
|
|
98
|
-
Do: function(dateObj, i18n) {
|
|
99
|
-
return i18n.DoFn(dateObj.getDate());
|
|
100
|
-
},
|
|
101
|
-
d: function(dateObj) {
|
|
102
|
-
return dateObj.getDate();
|
|
103
|
-
},
|
|
104
|
-
dd: function(dateObj) {
|
|
105
|
-
return pad(dateObj.getDate());
|
|
106
|
-
},
|
|
107
|
-
ddd: function(dateObj, i18n) {
|
|
108
|
-
return i18n.dayNamesShort[dateObj.getDay()];
|
|
109
|
-
},
|
|
110
|
-
dddd: function(dateObj, i18n) {
|
|
111
|
-
return i18n.dayNames[dateObj.getDay()];
|
|
112
|
-
},
|
|
113
|
-
M: function(dateObj) {
|
|
114
|
-
return dateObj.getMonth() + 1;
|
|
115
|
-
},
|
|
116
|
-
MM: function(dateObj) {
|
|
117
|
-
return pad(dateObj.getMonth() + 1);
|
|
118
|
-
},
|
|
119
|
-
MMM: function(dateObj, i18n) {
|
|
120
|
-
return i18n.monthNamesShort[dateObj.getMonth()];
|
|
121
|
-
},
|
|
122
|
-
MMMM: function(dateObj, i18n) {
|
|
123
|
-
return i18n.monthNames[dateObj.getMonth()];
|
|
124
|
-
},
|
|
125
|
-
yy: function(dateObj) {
|
|
126
|
-
return pad(String(dateObj.getFullYear()), 4).substr(2);
|
|
127
|
-
},
|
|
128
|
-
yyyy: function(dateObj) {
|
|
129
|
-
return pad(dateObj.getFullYear(), 4);
|
|
130
|
-
},
|
|
131
|
-
h: function(dateObj) {
|
|
132
|
-
return dateObj.getHours() % 12 || 12;
|
|
133
|
-
},
|
|
134
|
-
hh: function(dateObj) {
|
|
135
|
-
return pad(dateObj.getHours() % 12 || 12);
|
|
136
|
-
},
|
|
137
|
-
H: function(dateObj) {
|
|
138
|
-
return dateObj.getHours();
|
|
139
|
-
},
|
|
140
|
-
HH: function(dateObj) {
|
|
141
|
-
return pad(dateObj.getHours());
|
|
142
|
-
},
|
|
143
|
-
m: function(dateObj) {
|
|
144
|
-
return dateObj.getMinutes();
|
|
145
|
-
},
|
|
146
|
-
mm: function(dateObj) {
|
|
147
|
-
return pad(dateObj.getMinutes());
|
|
148
|
-
},
|
|
149
|
-
s: function(dateObj) {
|
|
150
|
-
return dateObj.getSeconds();
|
|
151
|
-
},
|
|
152
|
-
ss: function(dateObj) {
|
|
153
|
-
return pad(dateObj.getSeconds());
|
|
154
|
-
},
|
|
155
|
-
S: function(dateObj) {
|
|
156
|
-
return Math.round(dateObj.getMilliseconds() / 100);
|
|
157
|
-
},
|
|
158
|
-
SS: function(dateObj) {
|
|
159
|
-
return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
|
|
160
|
-
},
|
|
161
|
-
SSS: function(dateObj) {
|
|
162
|
-
return pad(dateObj.getMilliseconds(), 3);
|
|
163
|
-
},
|
|
164
|
-
a: function(dateObj, i18n) {
|
|
165
|
-
return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
|
|
166
|
-
},
|
|
167
|
-
A: function(dateObj, i18n) {
|
|
168
|
-
return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
|
|
169
|
-
},
|
|
170
|
-
ZZ: function(dateObj) {
|
|
171
|
-
var o = dateObj.getTimezoneOffset();
|
|
172
|
-
return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
|
|
223
|
+
if (parts) {
|
|
224
|
+
minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
|
|
225
|
+
d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
|
|
173
226
|
}
|
|
174
|
-
}
|
|
227
|
+
}]
|
|
228
|
+
};
|
|
229
|
+
parseFlags.dd = parseFlags.d;
|
|
230
|
+
parseFlags.dddd = parseFlags.ddd;
|
|
231
|
+
parseFlags.DD = parseFlags.D;
|
|
232
|
+
parseFlags.mm = parseFlags.m;
|
|
233
|
+
parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
|
|
234
|
+
parseFlags.MM = parseFlags.M;
|
|
235
|
+
parseFlags.ss = parseFlags.s;
|
|
236
|
+
parseFlags.A = parseFlags.a;
|
|
175
237
|
|
|
176
|
-
var parseFlags = {
|
|
177
|
-
d: [twoDigits, function (d, v) {
|
|
178
|
-
d.day = v;
|
|
179
|
-
}],
|
|
180
|
-
Do: [twoDigits + word, function (d, v) {
|
|
181
|
-
d.day = parseInt(v, 10);
|
|
182
|
-
}],
|
|
183
|
-
M: [twoDigits, function (d, v) {
|
|
184
|
-
d.month = v - 1;
|
|
185
|
-
}],
|
|
186
|
-
yy: [twoDigits, function (d, v) {
|
|
187
|
-
var da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
|
|
188
|
-
d.year = '' + (v > 68 ? cent - 1 : cent) + v;
|
|
189
|
-
}],
|
|
190
|
-
h: [twoDigits, function (d, v) {
|
|
191
|
-
d.hour = v;
|
|
192
|
-
}],
|
|
193
|
-
m: [twoDigits, function (d, v) {
|
|
194
|
-
d.minute = v;
|
|
195
|
-
}],
|
|
196
|
-
s: [twoDigits, function (d, v) {
|
|
197
|
-
d.second = v;
|
|
198
|
-
}],
|
|
199
|
-
yyyy: [fourDigits, function (d, v) {
|
|
200
|
-
d.year = v;
|
|
201
|
-
}],
|
|
202
|
-
S: ['\\d', function (d, v) {
|
|
203
|
-
d.millisecond = v * 100;
|
|
204
|
-
}],
|
|
205
|
-
SS: ['\\d{2}', function (d, v) {
|
|
206
|
-
d.millisecond = v * 10;
|
|
207
|
-
}],
|
|
208
|
-
SSS: [threeDigits, function (d, v) {
|
|
209
|
-
d.millisecond = v;
|
|
210
|
-
}],
|
|
211
|
-
D: [twoDigits, noop],
|
|
212
|
-
ddd: [word, noop],
|
|
213
|
-
MMM: [word, monthUpdate('monthNamesShort')],
|
|
214
|
-
MMMM: [word, monthUpdate('monthNames')],
|
|
215
|
-
a: [word, function (d, v, i18n) {
|
|
216
|
-
var val = v.toLowerCase();
|
|
217
|
-
if (val === i18n.amPm[0]) {
|
|
218
|
-
d.isPm = false;
|
|
219
|
-
} else if (val === i18n.amPm[1]) {
|
|
220
|
-
d.isPm = true;
|
|
221
|
-
}
|
|
222
|
-
}],
|
|
223
|
-
ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
|
|
224
|
-
var parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
|
|
225
238
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
parseFlags.MM = parseFlags.M;
|
|
238
|
-
parseFlags.ss = parseFlags.s;
|
|
239
|
-
parseFlags.A = parseFlags.a;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
// Some common format strings
|
|
243
|
-
fecha.masks = {
|
|
244
|
-
default: 'ddd MMM dd yyyy HH:mm:ss',
|
|
245
|
-
shortDate: 'M/D/yy',
|
|
246
|
-
mediumDate: 'MMM d, yyyy',
|
|
247
|
-
longDate: 'MMMM d, yyyy',
|
|
248
|
-
fullDate: 'dddd, MMMM d, yyyy',
|
|
249
|
-
shortTime: 'HH:mm',
|
|
250
|
-
mediumTime: 'HH:mm:ss',
|
|
251
|
-
longTime: 'HH:mm:ss.SSS'
|
|
252
|
-
};
|
|
239
|
+
// Some common format strings
|
|
240
|
+
fecha.masks = {
|
|
241
|
+
default: 'ddd MMM dd yyyy HH:mm:ss',
|
|
242
|
+
shortDate: 'M/D/yy',
|
|
243
|
+
mediumDate: 'MMM d, yyyy',
|
|
244
|
+
longDate: 'MMMM d, yyyy',
|
|
245
|
+
fullDate: 'dddd, MMMM d, yyyy',
|
|
246
|
+
shortTime: 'HH:mm',
|
|
247
|
+
mediumTime: 'HH:mm:ss',
|
|
248
|
+
longTime: 'HH:mm:ss.SSS'
|
|
249
|
+
};
|
|
253
250
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (typeof dateObj === 'number') {
|
|
264
|
-
dateObj = new Date(dateObj);
|
|
265
|
-
}
|
|
251
|
+
/***
|
|
252
|
+
* Format a date
|
|
253
|
+
* @method format
|
|
254
|
+
* @param {Date|number} dateObj
|
|
255
|
+
* @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
|
|
256
|
+
*/
|
|
257
|
+
fecha.format = function (dateObj, mask, i18nSettings) {
|
|
258
|
+
var i18n = i18nSettings || fecha.i18n;
|
|
266
259
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
260
|
+
if (typeof dateObj === 'number') {
|
|
261
|
+
dateObj = new Date(dateObj);
|
|
262
|
+
}
|
|
270
263
|
|
|
271
|
-
|
|
264
|
+
if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
|
|
265
|
+
throw new Error('Invalid Date in fecha.format');
|
|
266
|
+
}
|
|
272
267
|
|
|
273
|
-
|
|
268
|
+
mask = fecha.masks[mask] || mask || fecha.masks['default'];
|
|
274
269
|
|
|
275
|
-
|
|
276
|
-
mask = mask.replace(literal, function($0, $1) {
|
|
277
|
-
literals.push($1);
|
|
278
|
-
return '@@@';
|
|
279
|
-
});
|
|
280
|
-
// Apply formatting rules
|
|
281
|
-
mask = mask.replace(token, function ($0) {
|
|
282
|
-
return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
|
|
283
|
-
});
|
|
284
|
-
// Inline literal values back into the formatted value
|
|
285
|
-
return mask.replace(/@@@/g, function() {
|
|
286
|
-
return literals.shift();
|
|
287
|
-
});
|
|
288
|
-
};
|
|
270
|
+
var literals = [];
|
|
289
271
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
272
|
+
// Make literals inactive by replacing them with ??
|
|
273
|
+
mask = mask.replace(literal, function ($0, $1) {
|
|
274
|
+
literals.push($1);
|
|
275
|
+
return '@@@';
|
|
276
|
+
});
|
|
277
|
+
// Apply formatting rules
|
|
278
|
+
mask = mask.replace(token, function ($0) {
|
|
279
|
+
return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
|
|
280
|
+
});
|
|
281
|
+
// Inline literal values back into the formatted value
|
|
282
|
+
return mask.replace(/@@@/g, function () {
|
|
283
|
+
return literals.shift();
|
|
284
|
+
});
|
|
285
|
+
};
|
|
299
286
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Parse a date string into an object, changes - into /
|
|
289
|
+
* @method parse
|
|
290
|
+
* @param {string} dateStr Date string
|
|
291
|
+
* @param {string} format Date parse format
|
|
292
|
+
* @returns {Date|boolean}
|
|
293
|
+
*/
|
|
294
|
+
fecha.parse = function (dateStr, format, i18nSettings) {
|
|
295
|
+
var i18n = i18nSettings || fecha.i18n;
|
|
303
296
|
|
|
304
|
-
|
|
297
|
+
if (typeof format !== 'string') {
|
|
298
|
+
throw new Error('Invalid format in fecha.parse');
|
|
299
|
+
}
|
|
305
300
|
|
|
306
|
-
|
|
307
|
-
// https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
|
|
308
|
-
if (dateStr.length > 1000) {
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
301
|
+
format = fecha.masks[format] || format;
|
|
311
302
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return '@@@';
|
|
318
|
-
});
|
|
319
|
-
var newFormat = regexEscape(format).replace(token, function ($0) {
|
|
320
|
-
if (parseFlags[$0]) {
|
|
321
|
-
var info = parseFlags[$0];
|
|
322
|
-
parseInfo.push(info[1]);
|
|
323
|
-
return '(' + info[0] + ')';
|
|
324
|
-
}
|
|
303
|
+
// Avoid regular expression denial of service, fail early for really long strings
|
|
304
|
+
// https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
|
|
305
|
+
if (dateStr.length > 1000) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
325
308
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
309
|
+
var dateInfo = {};
|
|
310
|
+
var parseInfo = [];
|
|
311
|
+
var literals = [];
|
|
312
|
+
format = format.replace(literal, function ($0, $1) {
|
|
313
|
+
literals.push($1);
|
|
314
|
+
return '@@@';
|
|
315
|
+
});
|
|
316
|
+
var newFormat = regexEscape(format).replace(token, function ($0) {
|
|
317
|
+
if (parseFlags[$0]) {
|
|
318
|
+
var info = parseFlags[$0];
|
|
319
|
+
parseInfo.push(info[1]);
|
|
320
|
+
return '(' + info[0] + ')';
|
|
334
321
|
}
|
|
335
322
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
323
|
+
return $0;
|
|
324
|
+
});
|
|
325
|
+
newFormat = newFormat.replace(/@@@/g, function () {
|
|
326
|
+
return literals.shift();
|
|
327
|
+
});
|
|
328
|
+
var matches = dateStr.match(new RegExp(newFormat, 'i'));
|
|
329
|
+
if (!matches) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
339
332
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
} else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
|
|
344
|
-
dateInfo.hour = 0;
|
|
345
|
-
}
|
|
333
|
+
for (var i = 1; i < matches.length; i++) {
|
|
334
|
+
parseInfo[i - 1](dateInfo, matches[i], i18n);
|
|
335
|
+
}
|
|
346
336
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
|
|
354
|
-
dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
|
|
355
|
-
}
|
|
356
|
-
return date;
|
|
357
|
-
};
|
|
337
|
+
var today = new Date();
|
|
338
|
+
if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
|
|
339
|
+
dateInfo.hour = +dateInfo.hour + 12;
|
|
340
|
+
} else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
|
|
341
|
+
dateInfo.hour = 0;
|
|
342
|
+
}
|
|
358
343
|
|
|
359
|
-
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return fecha;
|
|
365
|
-
});
|
|
344
|
+
var date;
|
|
345
|
+
if (dateInfo.timezoneOffset != null) {
|
|
346
|
+
dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
|
|
347
|
+
date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
|
|
348
|
+
dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
|
|
366
349
|
} else {
|
|
367
|
-
|
|
350
|
+
date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
|
|
351
|
+
dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
|
|
368
352
|
}
|
|
369
|
-
|
|
370
|
-
|
|
353
|
+
return date;
|
|
354
|
+
};
|
|
355
|
+
export default fecha;
|