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