@fileverse-dev/fortune-core 1.3.3 → 1.3.4-date-format-2
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/es/canvas.js +1 -1
- package/es/events/paste.js +30 -13
- package/es/modules/cell.js +8 -6
- package/es/modules/format.js +29 -38
- package/es/modules/ssf.js +1 -1
- package/es/modules/toolbar.js +32 -11
- package/es/modules/validation.d.ts +10 -0
- package/es/modules/validation.js +281 -20
- package/lib/canvas.js +1 -1
- package/lib/events/paste.js +28 -11
- package/lib/modules/cell.js +8 -6
- package/lib/modules/format.js +28 -37
- package/lib/modules/ssf.js +1 -1
- package/lib/modules/toolbar.js +30 -9
- package/lib/modules/validation.d.ts +10 -0
- package/lib/modules/validation.js +282 -20
- package/package.json +1 -1
package/es/canvas.js
CHANGED
|
@@ -1012,7 +1012,7 @@ var Canvas = function () {
|
|
|
1012
1012
|
renderCtx.clip();
|
|
1013
1013
|
renderCtx.scale(this.sheetCtx.zoomRatio, this.sheetCtx.zoomRatio);
|
|
1014
1014
|
var measureText = getMeasureText(value, renderCtx, this.sheetCtx);
|
|
1015
|
-
var textMetrics = measureText.width +
|
|
1015
|
+
var textMetrics = measureText.width + 18;
|
|
1016
1016
|
var oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
|
|
1017
1017
|
var horizonAlignPos = pos_x + space_width;
|
|
1018
1018
|
if (horizonAlign === 0) {
|
package/es/events/paste.js
CHANGED
|
@@ -34,10 +34,10 @@ import { handlePastedTable } from "../paste-table-helpers";
|
|
|
34
34
|
import { getFlowdata } from "../context";
|
|
35
35
|
import { execfunction } from "../modules/formula";
|
|
36
36
|
import { getdatabyselection } from "../modules/cell";
|
|
37
|
-
import {
|
|
37
|
+
import { update, datenum_local } from "../modules/format";
|
|
38
38
|
import { normalizeSelection, selectionCache } from "../modules/selection";
|
|
39
39
|
import { getSheetIndex, isAllowEdit } from "../utils";
|
|
40
|
-
import { hasPartMC, isRealNum } from "../modules/validation";
|
|
40
|
+
import { hasPartMC, isRealNum, detectDateFormat } from "../modules/validation";
|
|
41
41
|
import { getBorderInfoCompute } from "../modules/border";
|
|
42
42
|
import { expandRowsAndColumns, storeSheetParamALL } from "../modules/sheet";
|
|
43
43
|
import { jfrefreshgrid } from "../modules/refresh";
|
|
@@ -209,14 +209,13 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
|
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
function pasteHandler(ctx, data, borderInfo) {
|
|
212
|
-
var _a;
|
|
213
|
-
var _b, _c, _d, _e, _f, _g;
|
|
212
|
+
var _a, _b, _c, _d, _e, _f;
|
|
214
213
|
if (ctx.luckysheet_selection_range) {
|
|
215
214
|
ctx.luckysheet_selection_range = [];
|
|
216
215
|
}
|
|
217
216
|
var allowEdit = isAllowEdit(ctx);
|
|
218
217
|
if (!allowEdit || ctx.isFlvReadOnly) return;
|
|
219
|
-
if (((
|
|
218
|
+
if (((_b = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) !== 1) {
|
|
220
219
|
return;
|
|
221
220
|
}
|
|
222
221
|
if (_typeof(data) === "object") {
|
|
@@ -265,7 +264,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
265
264
|
currentRowLen = cfg.rowlen[h];
|
|
266
265
|
}
|
|
267
266
|
for (var c = minc; c <= maxc; c += 1) {
|
|
268
|
-
if ((
|
|
267
|
+
if ((_c = x === null || x === void 0 ? void 0 : x[c]) === null || _c === void 0 ? void 0 : _c.mc) {
|
|
269
268
|
if ("rs" in x[c].mc) {
|
|
270
269
|
delete cfg.merge["".concat(x[c].mc.r, "_").concat(x[c].mc.c)];
|
|
271
270
|
}
|
|
@@ -276,7 +275,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
276
275
|
value = data[h - minh][c - minc];
|
|
277
276
|
}
|
|
278
277
|
x[c] = value;
|
|
279
|
-
if (value != null && ((
|
|
278
|
+
if (value != null && ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc)) {
|
|
280
279
|
if (x[c].mc.rs != null) {
|
|
281
280
|
x[c].mc.r = h;
|
|
282
281
|
x[c].mc.c = c;
|
|
@@ -303,7 +302,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
303
302
|
b: borderInfo["".concat(h - minh, "_").concat(c - minc)].b
|
|
304
303
|
}
|
|
305
304
|
};
|
|
306
|
-
(
|
|
305
|
+
(_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
|
|
307
306
|
}
|
|
308
307
|
}
|
|
309
308
|
d[h] = x;
|
|
@@ -335,7 +334,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
335
334
|
}
|
|
336
335
|
var d = getFlowdata(ctx);
|
|
337
336
|
if (!d) return;
|
|
338
|
-
var last = (
|
|
337
|
+
var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
|
|
339
338
|
if (!last) return;
|
|
340
339
|
var curR = last.row == null ? 0 : last.row[0];
|
|
341
340
|
var curC = last.column == null ? 0 : last.column[0];
|
|
@@ -376,9 +375,23 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
376
375
|
}
|
|
377
376
|
}
|
|
378
377
|
if (originCell) {
|
|
379
|
-
originCell.
|
|
378
|
+
if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
|
|
379
|
+
var df = detectDateFormat(originalValueStr);
|
|
380
|
+
if (df) {
|
|
381
|
+
var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
|
|
382
|
+
originCell.v = datenum_local(dateObj);
|
|
383
|
+
} else {
|
|
384
|
+
originCell.v = originalValueStr;
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
originCell.v = isUrl ? originalValueStr : value;
|
|
388
|
+
}
|
|
380
389
|
if (originCell.ct != null && originCell.ct.fa != null) {
|
|
381
|
-
|
|
390
|
+
if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
|
|
391
|
+
originCell.m = String(originCell.v);
|
|
392
|
+
} else {
|
|
393
|
+
originCell.m = update(originCell.ct.fa, originCell.v);
|
|
394
|
+
}
|
|
382
395
|
} else {
|
|
383
396
|
originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
|
|
384
397
|
}
|
|
@@ -407,8 +420,12 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
407
420
|
t: "s"
|
|
408
421
|
};
|
|
409
422
|
} else {
|
|
410
|
-
|
|
411
|
-
|
|
423
|
+
cell.v = originalValueStr;
|
|
424
|
+
cell.m = originalValueStr;
|
|
425
|
+
cell.ct = {
|
|
426
|
+
fa: "General",
|
|
427
|
+
t: "g"
|
|
428
|
+
};
|
|
412
429
|
if (/^0x?[a-fA-F0-9]+$/.test(value)) {
|
|
413
430
|
cell.m = value;
|
|
414
431
|
cell.ct = {
|
package/es/modules/cell.js
CHANGED
|
@@ -110,7 +110,7 @@ export function getCellValue(r, c, data, attr) {
|
|
|
110
110
|
return retv;
|
|
111
111
|
}
|
|
112
112
|
export function setCellValue(ctx, r, c, d, v) {
|
|
113
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
114
114
|
if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
|
|
115
115
|
if (_.isNil(d)) {
|
|
116
116
|
d = getFlowdata(ctx);
|
|
@@ -276,10 +276,7 @@ export function setCellValue(ctx, r, c, d, v) {
|
|
|
276
276
|
} else if (!_.isNil(cell.ct) && !_.isNil(cell.ct.fa) && cell.ct.fa !== "General") {
|
|
277
277
|
var fa = cell.ct.fa;
|
|
278
278
|
if (isRealNum(vupdate)) {
|
|
279
|
-
if (commaPresent && !fa.includes(",")
|
|
280
|
-
if (fa.includes(",") !== String(vupdate).includes(",")) {
|
|
281
|
-
commaPresent = true;
|
|
282
|
-
}
|
|
279
|
+
if (commaPresent && !fa.includes(",")) {
|
|
283
280
|
fa = getNumberFormat(String(vupdate), commaPresent);
|
|
284
281
|
}
|
|
285
282
|
vupdate = parseFloat(vupdate);
|
|
@@ -289,6 +286,9 @@ export function setCellValue(ctx, r, c, d, v) {
|
|
|
289
286
|
t: "n"
|
|
290
287
|
});
|
|
291
288
|
}
|
|
289
|
+
if (_.isNil(cell.ht)) {
|
|
290
|
+
cell.ht = 2;
|
|
291
|
+
}
|
|
292
292
|
}
|
|
293
293
|
var mask = update(fa, vupdate);
|
|
294
294
|
if (mask === vupdate) {
|
|
@@ -317,7 +317,9 @@ export function setCellValue(ctx, r, c, d, v) {
|
|
|
317
317
|
var strValue = String(vupdate);
|
|
318
318
|
var format = getNumberFormat(strValue, commaPresent);
|
|
319
319
|
cell.m = v.m ? v.m : update(format, cell.v);
|
|
320
|
-
|
|
320
|
+
if (_.isNil(cell.ht)) {
|
|
321
|
+
cell.ht = 2;
|
|
322
|
+
}
|
|
321
323
|
cell.ct = {
|
|
322
324
|
fa: format,
|
|
323
325
|
t: "n"
|
package/es/modules/format.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import numeral from "numeral";
|
|
2
2
|
import _ from "lodash";
|
|
3
|
-
import { isRealNum, valueIsError,
|
|
3
|
+
import { isRealNum, valueIsError, detectDateFormat } from "./validation";
|
|
4
4
|
import SSF from "./ssf";
|
|
5
5
|
import { getCellValue } from "./cell";
|
|
6
6
|
var base1904 = new Date(1900, 2, 1, 0, 0, 0);
|
|
@@ -10,29 +10,6 @@ export function datenum_local(v, date1904) {
|
|
|
10
10
|
if (date1904) epoch -= 1461 * 24 * 60 * 60 * 1000;else if (v >= base1904) epoch += 24 * 60 * 60 * 1000;
|
|
11
11
|
return (epoch - dnthresh_utc) / (24 * 60 * 60 * 1000);
|
|
12
12
|
}
|
|
13
|
-
var good_pd_date = new Date("2017-02-19T19:06:09.000Z");
|
|
14
|
-
if (Number.isNaN(good_pd_date.getFullYear())) good_pd_date = new Date("2/19/17");
|
|
15
|
-
var good_pd = good_pd_date.getFullYear() === 2017;
|
|
16
|
-
function parseDate(str, fixdate) {
|
|
17
|
-
var d = new Date(str);
|
|
18
|
-
if (good_pd) {
|
|
19
|
-
if (!_.isNil(fixdate)) {
|
|
20
|
-
if (fixdate > 0) d.setTime(d.getTime() + d.getTimezoneOffset() * 60 * 1000);else if (fixdate < 0) d.setTime(d.getTime() - d.getTimezoneOffset() * 60 * 1000);
|
|
21
|
-
}
|
|
22
|
-
return d;
|
|
23
|
-
}
|
|
24
|
-
if (str instanceof Date) return str;
|
|
25
|
-
if (good_pd_date.getFullYear() === 1917 && !Number.isNaN(d.getFullYear())) {
|
|
26
|
-
var s = d.getFullYear();
|
|
27
|
-
if (str.indexOf("".concat(s)) > -1) return d;
|
|
28
|
-
d.setFullYear(d.getFullYear() + 100);
|
|
29
|
-
return d;
|
|
30
|
-
}
|
|
31
|
-
var n = str.match(/\d+/g) || ["2017", "2", "19", "0", "0", "0"];
|
|
32
|
-
var out = new Date(+n[0], +n[1] - 1, +n[2], +n[3] || 0, +n[4] || 0, +n[5] || 0);
|
|
33
|
-
if (str.indexOf("Z") > -1) out = new Date(out.getTime() - out.getTimezoneOffset() * 60 * 1000);
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
13
|
export function genarate(value) {
|
|
37
14
|
var m = null;
|
|
38
15
|
var ct = {};
|
|
@@ -256,23 +233,37 @@ export function genarate(value) {
|
|
|
256
233
|
t: "n"
|
|
257
234
|
};
|
|
258
235
|
v = parseFloat(value);
|
|
259
|
-
} else if (
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
236
|
+
} else if (typeof value === "string") {
|
|
237
|
+
var df = detectDateFormat(value.toString());
|
|
238
|
+
if (df) {
|
|
239
|
+
var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
|
|
240
|
+
v = datenum_local(dateObj);
|
|
241
|
+
ct.t = "d";
|
|
242
|
+
var map = {
|
|
243
|
+
"yyyy-MM-dd": "dd/MM/yyyy",
|
|
244
|
+
"yyyy-MM-dd HH:mm": "dd/MM/yyyy",
|
|
245
|
+
"yyyy-MM-ddTHH:mm": "dd/MM/yyyy",
|
|
246
|
+
"yyyy/MM/dd": "dd/MM/yyyy",
|
|
247
|
+
"yyyy/MM/dd HH:mm": "dd/MM/yyyy",
|
|
248
|
+
"yyyy.MM.dd": "yyyy.MM.dd",
|
|
249
|
+
"MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
|
|
250
|
+
"MM/dd/yyyy": "MM/dd/yyyy",
|
|
251
|
+
"M/d/yyyy": "M/d/yyyy",
|
|
252
|
+
"MM/dd/yy": "MM/dd/yy",
|
|
253
|
+
"dd/MM/yyyy": "dd/MM/yyyy",
|
|
254
|
+
"dd-MM-yyyy": "dd/MM/yyyy",
|
|
255
|
+
"dd.MM.yyyy": "dd.MM.yyyy",
|
|
256
|
+
named: "dd/MM/yyyy"
|
|
257
|
+
};
|
|
258
|
+
ct.fa = map[df.formatType] || "dd/MM/yyyy";
|
|
259
|
+
m = SSF.format(ct.fa, v);
|
|
269
260
|
} else {
|
|
270
|
-
|
|
261
|
+
m = value.toString();
|
|
262
|
+
ct.fa = "General";
|
|
263
|
+
ct.t = "g";
|
|
271
264
|
}
|
|
272
|
-
ct.t = "d";
|
|
273
|
-
m = SSF.format(ct.fa, v);
|
|
274
265
|
} else {
|
|
275
|
-
m = value;
|
|
266
|
+
m = value.toString();
|
|
276
267
|
ct.fa = "General";
|
|
277
268
|
ct.t = "g";
|
|
278
269
|
}
|
package/es/modules/ssf.js
CHANGED
|
@@ -1364,7 +1364,7 @@ var make_ssf = function make_ssf(SSF) {
|
|
|
1364
1364
|
if (typeof n !== "number" || !Number.isFinite(n)) return null;
|
|
1365
1365
|
if (!Number.isInteger(n)) return null;
|
|
1366
1366
|
if (n < 0) return null;
|
|
1367
|
-
var minSec =
|
|
1367
|
+
var minSec = 100000; // Excel serial numbers max ~73050 for year 2100; avoids collision
|
|
1368
1368
|
var maxSec = 4102444800; // ~2100-01-01
|
|
1369
1369
|
var minMs = minSec * 1000;
|
|
1370
1370
|
var maxMs = maxSec * 1000;
|
package/es/modules/toolbar.js
CHANGED
|
@@ -4,13 +4,13 @@ import { getFlowdata } from "../context";
|
|
|
4
4
|
import { getSheetIndex, isAllowEdit, getLineCount } from "../utils";
|
|
5
5
|
import { getRangetxt, isAllSelectedCellsInStatus, normalizedAttr, setCellValue } from "./cell";
|
|
6
6
|
import { colors } from "./color";
|
|
7
|
-
import { genarate, is_date, update } from "./format";
|
|
7
|
+
import { datenum_local, genarate, is_date, update } from "./format";
|
|
8
8
|
import { execfunction, execFunctionGroup, israngeseleciton, rangeSetValue, setCaretPosition, createFormulaRangeSelect } from "./formula";
|
|
9
9
|
import { inlineStyleAffectAttribute, updateInlineStringFormat, updateInlineStringFormatOutside } from "./inline-string";
|
|
10
10
|
import { colLocationByIndex, rowLocationByIndex } from "./location";
|
|
11
11
|
import { normalizeSelection, selectionCopyShow, selectIsOverlap } from "./selection";
|
|
12
12
|
import { sortSelection } from "./sort";
|
|
13
|
-
import { hasPartMC, isdatatypemulti, isRealNull, isRealNum } from "./validation";
|
|
13
|
+
import { detectDateFormat, hasPartMC, isdatatypemulti, isRealNull, isRealNum } from "./validation";
|
|
14
14
|
import { showLinkCard } from "./hyperlink";
|
|
15
15
|
import { cfSplitRange } from "./conditionalFormat";
|
|
16
16
|
import { clearMeasureTextCache, getCellTextInfo } from "./text";
|
|
@@ -33,21 +33,42 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
33
33
|
} else {
|
|
34
34
|
value = cell;
|
|
35
35
|
}
|
|
36
|
+
var type = "n";
|
|
37
|
+
if (is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
|
|
38
|
+
type = "d";
|
|
39
|
+
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
40
|
+
type = "s";
|
|
41
|
+
}
|
|
36
42
|
if (_.isNil(value)) {
|
|
43
|
+
if (!_.isNil(d[r])) {
|
|
44
|
+
if (_.isNil(d[r][c])) {
|
|
45
|
+
d[r][c] = {
|
|
46
|
+
ct: {
|
|
47
|
+
fa: foucsStatus,
|
|
48
|
+
t: type
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
} else if (_.isPlainObject(d[r][c])) {
|
|
52
|
+
if (_.isNil(d[r][c].ct)) d[r][c].ct = {};
|
|
53
|
+
d[r][c].ct.fa = foucsStatus;
|
|
54
|
+
d[r][c].ct.t = type;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
37
57
|
continue;
|
|
38
58
|
}
|
|
39
59
|
if (foucsStatus !== "@" && isRealNum(value)) {
|
|
40
60
|
value = Number(value);
|
|
61
|
+
} else if (type === "d" && typeof value === "string") {
|
|
62
|
+
var dateInfo = detectDateFormat(value);
|
|
63
|
+
if (dateInfo) {
|
|
64
|
+
var dateObj = new Date(dateInfo.year, dateInfo.month - 1, dateInfo.day, dateInfo.hours, dateInfo.minutes, dateInfo.seconds);
|
|
65
|
+
value = datenum_local(dateObj);
|
|
66
|
+
}
|
|
41
67
|
}
|
|
42
|
-
|
|
43
|
-
var type = "n";
|
|
44
|
-
if (is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
|
|
45
|
-
type = "d";
|
|
46
|
-
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
47
|
-
type = "s";
|
|
48
|
-
} else if (foucsStatus === "General" || foucsStatus === 0) {
|
|
68
|
+
if (foucsStatus === "General" || foucsStatus === 0) {
|
|
49
69
|
type = isRealNum(value) ? "n" : "g";
|
|
50
70
|
}
|
|
71
|
+
var mask = update(foucsStatus, value);
|
|
51
72
|
if (cell && _.isPlainObject(cell)) {
|
|
52
73
|
cell.m = "".concat(mask);
|
|
53
74
|
if (_.isNil(cell.ct)) {
|
|
@@ -55,7 +76,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
55
76
|
}
|
|
56
77
|
cell.ct.fa = foucsStatus;
|
|
57
78
|
cell.ct.t = type;
|
|
58
|
-
cell.v = String(value);
|
|
79
|
+
cell.v = typeof value === "number" ? value : String(value);
|
|
59
80
|
cell.fc = cell.fc || ((_f = (_e = (_d = cell.ct) === null || _d === void 0 ? void 0 : _d.s) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.fc);
|
|
60
81
|
cell.bl = cell.bl || ((_j = (_h = (_g = cell.ct) === null || _g === void 0 ? void 0 : _g.s) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.bl);
|
|
61
82
|
cell.it = cell.it || ((_m = (_l = (_k = cell.ct) === null || _k === void 0 ? void 0 : _k.s) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.it);
|
|
@@ -68,7 +89,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
68
89
|
fa: foucsStatus,
|
|
69
90
|
t: type
|
|
70
91
|
},
|
|
71
|
-
v: value,
|
|
92
|
+
v: typeof value === "number" ? value : value,
|
|
72
93
|
m: mask
|
|
73
94
|
};
|
|
74
95
|
}
|
|
@@ -15,6 +15,16 @@ export declare function valueIsError(value: string): boolean;
|
|
|
15
15
|
export declare function isRealNull(val: any): boolean;
|
|
16
16
|
export declare function isHexValue(str: string): boolean;
|
|
17
17
|
export declare function isRealNum(val: any): boolean;
|
|
18
|
+
export type DateFormatInfo = {
|
|
19
|
+
year: number;
|
|
20
|
+
month: number;
|
|
21
|
+
day: number;
|
|
22
|
+
hours: number;
|
|
23
|
+
minutes: number;
|
|
24
|
+
seconds: number;
|
|
25
|
+
formatType: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function detectDateFormat(str: string): DateFormatInfo | null;
|
|
18
28
|
export declare function isdatetime(s: any): boolean;
|
|
19
29
|
export declare function diff(now: any, then: any): number;
|
|
20
30
|
export declare function isdatatypemulti(s: any): any;
|
package/es/modules/validation.js
CHANGED
|
@@ -39,33 +39,294 @@ export function isRealNum(val) {
|
|
|
39
39
|
}
|
|
40
40
|
return !Number.isNaN(Number(val));
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
var MONTH_NAME_MAP = {
|
|
43
|
+
january: 1,
|
|
44
|
+
february: 2,
|
|
45
|
+
march: 3,
|
|
46
|
+
april: 4,
|
|
47
|
+
may: 5,
|
|
48
|
+
june: 6,
|
|
49
|
+
july: 7,
|
|
50
|
+
august: 8,
|
|
51
|
+
september: 9,
|
|
52
|
+
october: 10,
|
|
53
|
+
november: 11,
|
|
54
|
+
december: 12,
|
|
55
|
+
jan: 1,
|
|
56
|
+
feb: 2,
|
|
57
|
+
mar: 3,
|
|
58
|
+
apr: 4,
|
|
59
|
+
jun: 6,
|
|
60
|
+
jul: 7,
|
|
61
|
+
aug: 8,
|
|
62
|
+
sep: 9,
|
|
63
|
+
oct: 10,
|
|
64
|
+
nov: 11,
|
|
65
|
+
dec: 12
|
|
66
|
+
};
|
|
67
|
+
var MONTH_NAMES_RE = "january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec";
|
|
68
|
+
var MONTH_ABBR_RE = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
|
|
69
|
+
function isValidDateParts(year, month, day) {
|
|
70
|
+
if (year < 1900) return false;
|
|
71
|
+
if (month < 1 || month > 12) return false;
|
|
72
|
+
if (day < 1 || day > 31) return false;
|
|
73
|
+
if (month === 2) {
|
|
74
|
+
var isLeap = new Date(year, 1, 29).getDate() === 29;
|
|
75
|
+
if (isLeap && day > 29) return false;
|
|
76
|
+
if (!isLeap && day > 28) return false;
|
|
47
77
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
if ([4, 6, 9, 11].includes(month) && day > 30) return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
export function detectDateFormat(str) {
|
|
82
|
+
if (!str || str.toString().length < 5) return null;
|
|
83
|
+
var s = str.toString().trim();
|
|
84
|
+
var m;
|
|
85
|
+
m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(s);
|
|
86
|
+
if (m) {
|
|
87
|
+
var y = +m[1],
|
|
88
|
+
mo = +m[2],
|
|
89
|
+
d = +m[3],
|
|
90
|
+
h = +m[4],
|
|
91
|
+
mi = +m[5],
|
|
92
|
+
sec = m[6] != null ? +m[6] : 0;
|
|
93
|
+
if (isValidDateParts(y, mo, d)) {
|
|
94
|
+
return {
|
|
95
|
+
year: y,
|
|
96
|
+
month: mo,
|
|
97
|
+
day: d,
|
|
98
|
+
hours: h,
|
|
99
|
+
minutes: mi,
|
|
100
|
+
seconds: sec,
|
|
101
|
+
formatType: "yyyy-MM-ddTHH:mm"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
53
104
|
}
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
m = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
106
|
+
if (m) {
|
|
107
|
+
var y = +m[1],
|
|
108
|
+
mo = +m[2],
|
|
109
|
+
d = +m[3];
|
|
110
|
+
if (isValidDateParts(y, mo, d)) {
|
|
111
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
112
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
113
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
114
|
+
return {
|
|
115
|
+
year: y,
|
|
116
|
+
month: mo,
|
|
117
|
+
day: d,
|
|
118
|
+
hours: h,
|
|
119
|
+
minutes: mi,
|
|
120
|
+
seconds: sec,
|
|
121
|
+
formatType: m[4] != null ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd"
|
|
122
|
+
};
|
|
123
|
+
}
|
|
56
124
|
}
|
|
57
|
-
|
|
58
|
-
|
|
125
|
+
m = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
126
|
+
if (m) {
|
|
127
|
+
var y = +m[1],
|
|
128
|
+
mo = +m[2],
|
|
129
|
+
d = +m[3];
|
|
130
|
+
if (isValidDateParts(y, mo, d)) {
|
|
131
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
132
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
133
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
134
|
+
return {
|
|
135
|
+
year: y,
|
|
136
|
+
month: mo,
|
|
137
|
+
day: d,
|
|
138
|
+
hours: h,
|
|
139
|
+
minutes: mi,
|
|
140
|
+
seconds: sec,
|
|
141
|
+
formatType: m[4] != null ? "yyyy/MM/dd HH:mm" : "yyyy/MM/dd"
|
|
142
|
+
};
|
|
143
|
+
}
|
|
59
144
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
145
|
+
m = /^(\d{4})\.(\d{1,2})\.(\d{1,2})$/.exec(s);
|
|
146
|
+
if (m) {
|
|
147
|
+
var y = +m[1],
|
|
148
|
+
mo = +m[2],
|
|
149
|
+
d = +m[3];
|
|
150
|
+
if (isValidDateParts(y, mo, d)) {
|
|
151
|
+
return {
|
|
152
|
+
year: y,
|
|
153
|
+
month: mo,
|
|
154
|
+
day: d,
|
|
155
|
+
hours: 0,
|
|
156
|
+
minutes: 0,
|
|
157
|
+
seconds: 0,
|
|
158
|
+
formatType: "yyyy.MM.dd"
|
|
159
|
+
};
|
|
63
160
|
}
|
|
64
|
-
|
|
65
|
-
|
|
161
|
+
}
|
|
162
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})\s(\d{1,2}):(\d{2})\s?(AM|PM)$/i.exec(s);
|
|
163
|
+
if (m) {
|
|
164
|
+
var p1 = +m[1],
|
|
165
|
+
p2 = +m[2],
|
|
166
|
+
y = +m[3],
|
|
167
|
+
h = +m[4],
|
|
168
|
+
mi = +m[5];
|
|
169
|
+
var ampm = m[6].toUpperCase();
|
|
170
|
+
if (p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
171
|
+
var actualH = h;
|
|
172
|
+
if (ampm === "PM" && h !== 12) actualH = h + 12;
|
|
173
|
+
if (ampm === "AM" && h === 12) actualH = 0;
|
|
174
|
+
return {
|
|
175
|
+
year: y,
|
|
176
|
+
month: p1,
|
|
177
|
+
day: p2,
|
|
178
|
+
hours: actualH,
|
|
179
|
+
minutes: mi,
|
|
180
|
+
seconds: 0,
|
|
181
|
+
formatType: "MM/dd/yyyy h:mm AM/PM"
|
|
182
|
+
};
|
|
66
183
|
}
|
|
67
184
|
}
|
|
68
|
-
|
|
185
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(s);
|
|
186
|
+
if (m) {
|
|
187
|
+
var p1 = +m[1],
|
|
188
|
+
p2 = +m[2],
|
|
189
|
+
y = +m[3];
|
|
190
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
191
|
+
return {
|
|
192
|
+
year: y,
|
|
193
|
+
month: p2,
|
|
194
|
+
day: p1,
|
|
195
|
+
hours: 0,
|
|
196
|
+
minutes: 0,
|
|
197
|
+
seconds: 0,
|
|
198
|
+
formatType: "dd/MM/yyyy"
|
|
199
|
+
};
|
|
200
|
+
} else if (p2 > 12 && p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
201
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
202
|
+
return {
|
|
203
|
+
year: y,
|
|
204
|
+
month: p1,
|
|
205
|
+
day: p2,
|
|
206
|
+
hours: 0,
|
|
207
|
+
minutes: 0,
|
|
208
|
+
seconds: 0,
|
|
209
|
+
formatType: formatType
|
|
210
|
+
};
|
|
211
|
+
} else if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
212
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
213
|
+
return {
|
|
214
|
+
year: y,
|
|
215
|
+
month: p1,
|
|
216
|
+
day: p2,
|
|
217
|
+
hours: 0,
|
|
218
|
+
minutes: 0,
|
|
219
|
+
seconds: 0,
|
|
220
|
+
formatType: formatType
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
m = /^(\d{2})\/(\d{2})\/(\d{2})$/.exec(s);
|
|
225
|
+
if (m) {
|
|
226
|
+
var p1 = +m[1],
|
|
227
|
+
p2 = +m[2],
|
|
228
|
+
y = 2000 + +m[3];
|
|
229
|
+
if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
230
|
+
return {
|
|
231
|
+
year: y,
|
|
232
|
+
month: p1,
|
|
233
|
+
day: p2,
|
|
234
|
+
hours: 0,
|
|
235
|
+
minutes: 0,
|
|
236
|
+
seconds: 0,
|
|
237
|
+
formatType: "MM/dd/yy"
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
m = /^(\d{1,2})-(\d{1,2})-(\d{4})$/.exec(s);
|
|
242
|
+
if (m) {
|
|
243
|
+
var p1 = +m[1],
|
|
244
|
+
p2 = +m[2],
|
|
245
|
+
y = +m[3];
|
|
246
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
247
|
+
return {
|
|
248
|
+
year: y,
|
|
249
|
+
month: p2,
|
|
250
|
+
day: p1,
|
|
251
|
+
hours: 0,
|
|
252
|
+
minutes: 0,
|
|
253
|
+
seconds: 0,
|
|
254
|
+
formatType: "dd-MM-yyyy"
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
m = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/.exec(s);
|
|
259
|
+
if (m) {
|
|
260
|
+
var p1 = +m[1],
|
|
261
|
+
p2 = +m[2],
|
|
262
|
+
y = +m[3];
|
|
263
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
264
|
+
return {
|
|
265
|
+
year: y,
|
|
266
|
+
month: p2,
|
|
267
|
+
day: p1,
|
|
268
|
+
hours: 0,
|
|
269
|
+
minutes: 0,
|
|
270
|
+
seconds: 0,
|
|
271
|
+
formatType: "dd.MM.yyyy"
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
m = new RegExp("^(".concat(MONTH_NAMES_RE, ")\\s+(\\d{1,2}),?\\s+(\\d{4})$"), "i").exec(s);
|
|
276
|
+
if (m) {
|
|
277
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
278
|
+
var d = +m[2],
|
|
279
|
+
y = +m[3];
|
|
280
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
281
|
+
return {
|
|
282
|
+
year: y,
|
|
283
|
+
month: mo,
|
|
284
|
+
day: d,
|
|
285
|
+
hours: 0,
|
|
286
|
+
minutes: 0,
|
|
287
|
+
seconds: 0,
|
|
288
|
+
formatType: "named"
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
m = new RegExp("^(\\d{1,2})\\s+(".concat(MONTH_NAMES_RE, ")\\s+(\\d{4})$"), "i").exec(s);
|
|
293
|
+
if (m) {
|
|
294
|
+
var d = +m[1],
|
|
295
|
+
mo = MONTH_NAME_MAP[m[2].toLowerCase()],
|
|
296
|
+
y = +m[3];
|
|
297
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
298
|
+
return {
|
|
299
|
+
year: y,
|
|
300
|
+
month: mo,
|
|
301
|
+
day: d,
|
|
302
|
+
hours: 0,
|
|
303
|
+
minutes: 0,
|
|
304
|
+
seconds: 0,
|
|
305
|
+
formatType: "named"
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
m = new RegExp("^(".concat(MONTH_ABBR_RE, ")-(\\d{1,2})-(\\d{4})$"), "i").exec(s);
|
|
310
|
+
if (m) {
|
|
311
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
312
|
+
var d = +m[2],
|
|
313
|
+
y = +m[3];
|
|
314
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
315
|
+
return {
|
|
316
|
+
year: y,
|
|
317
|
+
month: mo,
|
|
318
|
+
day: d,
|
|
319
|
+
hours: 0,
|
|
320
|
+
minutes: 0,
|
|
321
|
+
seconds: 0,
|
|
322
|
+
formatType: "named"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
function checkDateTime(str) {
|
|
329
|
+
return detectDateFormat(str) !== null;
|
|
69
330
|
}
|
|
70
331
|
export function isdatetime(s) {
|
|
71
332
|
if (s === null || s.toString().length < 5) {
|
package/lib/canvas.js
CHANGED
|
@@ -1019,7 +1019,7 @@ var Canvas = exports.Canvas = function () {
|
|
|
1019
1019
|
renderCtx.clip();
|
|
1020
1020
|
renderCtx.scale(this.sheetCtx.zoomRatio, this.sheetCtx.zoomRatio);
|
|
1021
1021
|
var measureText = (0, _text.getMeasureText)(value, renderCtx, this.sheetCtx);
|
|
1022
|
-
var textMetrics = measureText.width +
|
|
1022
|
+
var textMetrics = measureText.width + 18;
|
|
1023
1023
|
var oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
|
|
1024
1024
|
var horizonAlignPos = pos_x + space_width;
|
|
1025
1025
|
if (horizonAlign === 0) {
|
package/lib/events/paste.js
CHANGED
|
@@ -222,14 +222,13 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
|
|
|
222
222
|
}
|
|
223
223
|
};
|
|
224
224
|
function pasteHandler(ctx, data, borderInfo) {
|
|
225
|
-
var _a;
|
|
226
|
-
var _b, _c, _d, _e, _f, _g;
|
|
225
|
+
var _a, _b, _c, _d, _e, _f;
|
|
227
226
|
if (ctx.luckysheet_selection_range) {
|
|
228
227
|
ctx.luckysheet_selection_range = [];
|
|
229
228
|
}
|
|
230
229
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
231
230
|
if (!allowEdit || ctx.isFlvReadOnly) return;
|
|
232
|
-
if (((
|
|
231
|
+
if (((_b = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) !== 1) {
|
|
233
232
|
return;
|
|
234
233
|
}
|
|
235
234
|
if (_typeof(data) === "object") {
|
|
@@ -278,7 +277,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
278
277
|
currentRowLen = cfg.rowlen[h];
|
|
279
278
|
}
|
|
280
279
|
for (var c = minc; c <= maxc; c += 1) {
|
|
281
|
-
if ((
|
|
280
|
+
if ((_c = x === null || x === void 0 ? void 0 : x[c]) === null || _c === void 0 ? void 0 : _c.mc) {
|
|
282
281
|
if ("rs" in x[c].mc) {
|
|
283
282
|
delete cfg.merge["".concat(x[c].mc.r, "_").concat(x[c].mc.c)];
|
|
284
283
|
}
|
|
@@ -289,7 +288,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
289
288
|
value = data[h - minh][c - minc];
|
|
290
289
|
}
|
|
291
290
|
x[c] = value;
|
|
292
|
-
if (value != null && ((
|
|
291
|
+
if (value != null && ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc)) {
|
|
293
292
|
if (x[c].mc.rs != null) {
|
|
294
293
|
x[c].mc.r = h;
|
|
295
294
|
x[c].mc.c = c;
|
|
@@ -316,7 +315,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
316
315
|
b: borderInfo["".concat(h - minh, "_").concat(c - minc)].b
|
|
317
316
|
}
|
|
318
317
|
};
|
|
319
|
-
(
|
|
318
|
+
(_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
|
|
320
319
|
}
|
|
321
320
|
}
|
|
322
321
|
d[h] = x;
|
|
@@ -348,7 +347,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
348
347
|
}
|
|
349
348
|
var d = (0, _context.getFlowdata)(ctx);
|
|
350
349
|
if (!d) return;
|
|
351
|
-
var last = (
|
|
350
|
+
var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
|
|
352
351
|
if (!last) return;
|
|
353
352
|
var curR = last.row == null ? 0 : last.row[0];
|
|
354
353
|
var curC = last.column == null ? 0 : last.column[0];
|
|
@@ -389,9 +388,23 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
389
388
|
}
|
|
390
389
|
}
|
|
391
390
|
if (originCell) {
|
|
392
|
-
originCell.
|
|
391
|
+
if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
|
|
392
|
+
var df = (0, _validation.detectDateFormat)(originalValueStr);
|
|
393
|
+
if (df) {
|
|
394
|
+
var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
|
|
395
|
+
originCell.v = (0, _format.datenum_local)(dateObj);
|
|
396
|
+
} else {
|
|
397
|
+
originCell.v = originalValueStr;
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
originCell.v = isUrl ? originalValueStr : value;
|
|
401
|
+
}
|
|
393
402
|
if (originCell.ct != null && originCell.ct.fa != null) {
|
|
394
|
-
|
|
403
|
+
if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
|
|
404
|
+
originCell.m = String(originCell.v);
|
|
405
|
+
} else {
|
|
406
|
+
originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
|
|
407
|
+
}
|
|
395
408
|
} else {
|
|
396
409
|
originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
|
|
397
410
|
}
|
|
@@ -420,8 +433,12 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
420
433
|
t: "s"
|
|
421
434
|
};
|
|
422
435
|
} else {
|
|
423
|
-
|
|
424
|
-
|
|
436
|
+
cell.v = originalValueStr;
|
|
437
|
+
cell.m = originalValueStr;
|
|
438
|
+
cell.ct = {
|
|
439
|
+
fa: "General",
|
|
440
|
+
t: "g"
|
|
441
|
+
};
|
|
425
442
|
if (/^0x?[a-fA-F0-9]+$/.test(value)) {
|
|
426
443
|
cell.m = value;
|
|
427
444
|
cell.ct = {
|
package/lib/modules/cell.js
CHANGED
|
@@ -143,7 +143,7 @@ function getCellValue(r, c, data, attr) {
|
|
|
143
143
|
return retv;
|
|
144
144
|
}
|
|
145
145
|
function setCellValue(ctx, r, c, d, v) {
|
|
146
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
146
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
147
147
|
if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
|
|
148
148
|
if (_lodash.default.isNil(d)) {
|
|
149
149
|
d = (0, _context.getFlowdata)(ctx);
|
|
@@ -309,10 +309,7 @@ function setCellValue(ctx, r, c, d, v) {
|
|
|
309
309
|
} else if (!_lodash.default.isNil(cell.ct) && !_lodash.default.isNil(cell.ct.fa) && cell.ct.fa !== "General") {
|
|
310
310
|
var fa = cell.ct.fa;
|
|
311
311
|
if ((0, _validation.isRealNum)(vupdate)) {
|
|
312
|
-
if (commaPresent && !fa.includes(",")
|
|
313
|
-
if (fa.includes(",") !== String(vupdate).includes(",")) {
|
|
314
|
-
commaPresent = true;
|
|
315
|
-
}
|
|
312
|
+
if (commaPresent && !fa.includes(",")) {
|
|
316
313
|
fa = (0, _utils.getNumberFormat)(String(vupdate), commaPresent);
|
|
317
314
|
}
|
|
318
315
|
vupdate = parseFloat(vupdate);
|
|
@@ -322,6 +319,9 @@ function setCellValue(ctx, r, c, d, v) {
|
|
|
322
319
|
t: "n"
|
|
323
320
|
});
|
|
324
321
|
}
|
|
322
|
+
if (_lodash.default.isNil(cell.ht)) {
|
|
323
|
+
cell.ht = 2;
|
|
324
|
+
}
|
|
325
325
|
}
|
|
326
326
|
var mask = (0, _format.update)(fa, vupdate);
|
|
327
327
|
if (mask === vupdate) {
|
|
@@ -350,7 +350,9 @@ function setCellValue(ctx, r, c, d, v) {
|
|
|
350
350
|
var strValue = String(vupdate);
|
|
351
351
|
var format = (0, _utils.getNumberFormat)(strValue, commaPresent);
|
|
352
352
|
cell.m = v.m ? v.m : (0, _format.update)(format, cell.v);
|
|
353
|
-
|
|
353
|
+
if (_lodash.default.isNil(cell.ht)) {
|
|
354
|
+
cell.ht = 2;
|
|
355
|
+
}
|
|
354
356
|
cell.ct = {
|
|
355
357
|
fa: format,
|
|
356
358
|
t: "n"
|
package/lib/modules/format.js
CHANGED
|
@@ -21,29 +21,6 @@ function datenum_local(v, date1904) {
|
|
|
21
21
|
if (date1904) epoch -= 1461 * 24 * 60 * 60 * 1000;else if (v >= base1904) epoch += 24 * 60 * 60 * 1000;
|
|
22
22
|
return (epoch - dnthresh_utc) / (24 * 60 * 60 * 1000);
|
|
23
23
|
}
|
|
24
|
-
var good_pd_date = new Date("2017-02-19T19:06:09.000Z");
|
|
25
|
-
if (Number.isNaN(good_pd_date.getFullYear())) good_pd_date = new Date("2/19/17");
|
|
26
|
-
var good_pd = good_pd_date.getFullYear() === 2017;
|
|
27
|
-
function parseDate(str, fixdate) {
|
|
28
|
-
var d = new Date(str);
|
|
29
|
-
if (good_pd) {
|
|
30
|
-
if (!_lodash.default.isNil(fixdate)) {
|
|
31
|
-
if (fixdate > 0) d.setTime(d.getTime() + d.getTimezoneOffset() * 60 * 1000);else if (fixdate < 0) d.setTime(d.getTime() - d.getTimezoneOffset() * 60 * 1000);
|
|
32
|
-
}
|
|
33
|
-
return d;
|
|
34
|
-
}
|
|
35
|
-
if (str instanceof Date) return str;
|
|
36
|
-
if (good_pd_date.getFullYear() === 1917 && !Number.isNaN(d.getFullYear())) {
|
|
37
|
-
var s = d.getFullYear();
|
|
38
|
-
if (str.indexOf("".concat(s)) > -1) return d;
|
|
39
|
-
d.setFullYear(d.getFullYear() + 100);
|
|
40
|
-
return d;
|
|
41
|
-
}
|
|
42
|
-
var n = str.match(/\d+/g) || ["2017", "2", "19", "0", "0", "0"];
|
|
43
|
-
var out = new Date(+n[0], +n[1] - 1, +n[2], +n[3] || 0, +n[4] || 0, +n[5] || 0);
|
|
44
|
-
if (str.indexOf("Z") > -1) out = new Date(out.getTime() - out.getTimezoneOffset() * 60 * 1000);
|
|
45
|
-
return out;
|
|
46
|
-
}
|
|
47
24
|
function genarate(value) {
|
|
48
25
|
var m = null;
|
|
49
26
|
var ct = {};
|
|
@@ -267,23 +244,37 @@ function genarate(value) {
|
|
|
267
244
|
t: "n"
|
|
268
245
|
};
|
|
269
246
|
v = parseFloat(value);
|
|
270
|
-
} else if (
|
|
271
|
-
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
247
|
+
} else if (typeof value === "string") {
|
|
248
|
+
var df = (0, _validation.detectDateFormat)(value.toString());
|
|
249
|
+
if (df) {
|
|
250
|
+
var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
|
|
251
|
+
v = datenum_local(dateObj);
|
|
252
|
+
ct.t = "d";
|
|
253
|
+
var map = {
|
|
254
|
+
"yyyy-MM-dd": "dd/MM/yyyy",
|
|
255
|
+
"yyyy-MM-dd HH:mm": "dd/MM/yyyy",
|
|
256
|
+
"yyyy-MM-ddTHH:mm": "dd/MM/yyyy",
|
|
257
|
+
"yyyy/MM/dd": "dd/MM/yyyy",
|
|
258
|
+
"yyyy/MM/dd HH:mm": "dd/MM/yyyy",
|
|
259
|
+
"yyyy.MM.dd": "yyyy.MM.dd",
|
|
260
|
+
"MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
|
|
261
|
+
"MM/dd/yyyy": "MM/dd/yyyy",
|
|
262
|
+
"M/d/yyyy": "M/d/yyyy",
|
|
263
|
+
"MM/dd/yy": "MM/dd/yy",
|
|
264
|
+
"dd/MM/yyyy": "dd/MM/yyyy",
|
|
265
|
+
"dd-MM-yyyy": "dd/MM/yyyy",
|
|
266
|
+
"dd.MM.yyyy": "dd.MM.yyyy",
|
|
267
|
+
named: "dd/MM/yyyy"
|
|
268
|
+
};
|
|
269
|
+
ct.fa = map[df.formatType] || "dd/MM/yyyy";
|
|
270
|
+
m = _ssf.default.format(ct.fa, v);
|
|
280
271
|
} else {
|
|
281
|
-
|
|
272
|
+
m = value.toString();
|
|
273
|
+
ct.fa = "General";
|
|
274
|
+
ct.t = "g";
|
|
282
275
|
}
|
|
283
|
-
ct.t = "d";
|
|
284
|
-
m = _ssf.default.format(ct.fa, v);
|
|
285
276
|
} else {
|
|
286
|
-
m = value;
|
|
277
|
+
m = value.toString();
|
|
287
278
|
ct.fa = "General";
|
|
288
279
|
ct.t = "g";
|
|
289
280
|
}
|
package/lib/modules/ssf.js
CHANGED
|
@@ -1370,7 +1370,7 @@ var make_ssf = function make_ssf(SSF) {
|
|
|
1370
1370
|
if (typeof n !== "number" || !Number.isFinite(n)) return null;
|
|
1371
1371
|
if (!Number.isInteger(n)) return null;
|
|
1372
1372
|
if (n < 0) return null;
|
|
1373
|
-
var minSec =
|
|
1373
|
+
var minSec = 100000; // Excel serial numbers max ~73050 for year 2100; avoids collision
|
|
1374
1374
|
var maxSec = 4102444800; // ~2100-01-01
|
|
1375
1375
|
var minMs = minSec * 1000;
|
|
1376
1376
|
var maxMs = maxSec * 1000;
|
package/lib/modules/toolbar.js
CHANGED
|
@@ -66,21 +66,42 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
66
66
|
} else {
|
|
67
67
|
value = cell;
|
|
68
68
|
}
|
|
69
|
+
var type = "n";
|
|
70
|
+
if ((0, _format.is_date)(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
|
|
71
|
+
type = "d";
|
|
72
|
+
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
73
|
+
type = "s";
|
|
74
|
+
}
|
|
69
75
|
if (_lodash.default.isNil(value)) {
|
|
76
|
+
if (!_lodash.default.isNil(d[r])) {
|
|
77
|
+
if (_lodash.default.isNil(d[r][c])) {
|
|
78
|
+
d[r][c] = {
|
|
79
|
+
ct: {
|
|
80
|
+
fa: foucsStatus,
|
|
81
|
+
t: type
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
} else if (_lodash.default.isPlainObject(d[r][c])) {
|
|
85
|
+
if (_lodash.default.isNil(d[r][c].ct)) d[r][c].ct = {};
|
|
86
|
+
d[r][c].ct.fa = foucsStatus;
|
|
87
|
+
d[r][c].ct.t = type;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
70
90
|
continue;
|
|
71
91
|
}
|
|
72
92
|
if (foucsStatus !== "@" && (0, _validation.isRealNum)(value)) {
|
|
73
93
|
value = Number(value);
|
|
94
|
+
} else if (type === "d" && typeof value === "string") {
|
|
95
|
+
var dateInfo = (0, _validation.detectDateFormat)(value);
|
|
96
|
+
if (dateInfo) {
|
|
97
|
+
var dateObj = new Date(dateInfo.year, dateInfo.month - 1, dateInfo.day, dateInfo.hours, dateInfo.minutes, dateInfo.seconds);
|
|
98
|
+
value = (0, _format.datenum_local)(dateObj);
|
|
99
|
+
}
|
|
74
100
|
}
|
|
75
|
-
|
|
76
|
-
var type = "n";
|
|
77
|
-
if ((0, _format.is_date)(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
|
|
78
|
-
type = "d";
|
|
79
|
-
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
80
|
-
type = "s";
|
|
81
|
-
} else if (foucsStatus === "General" || foucsStatus === 0) {
|
|
101
|
+
if (foucsStatus === "General" || foucsStatus === 0) {
|
|
82
102
|
type = (0, _validation.isRealNum)(value) ? "n" : "g";
|
|
83
103
|
}
|
|
104
|
+
var mask = (0, _format.update)(foucsStatus, value);
|
|
84
105
|
if (cell && _lodash.default.isPlainObject(cell)) {
|
|
85
106
|
cell.m = "".concat(mask);
|
|
86
107
|
if (_lodash.default.isNil(cell.ct)) {
|
|
@@ -88,7 +109,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
88
109
|
}
|
|
89
110
|
cell.ct.fa = foucsStatus;
|
|
90
111
|
cell.ct.t = type;
|
|
91
|
-
cell.v = String(value);
|
|
112
|
+
cell.v = typeof value === "number" ? value : String(value);
|
|
92
113
|
cell.fc = cell.fc || ((_f = (_e = (_d = cell.ct) === null || _d === void 0 ? void 0 : _d.s) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.fc);
|
|
93
114
|
cell.bl = cell.bl || ((_j = (_h = (_g = cell.ct) === null || _g === void 0 ? void 0 : _g.s) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.bl);
|
|
94
115
|
cell.it = cell.it || ((_m = (_l = (_k = cell.ct) === null || _k === void 0 ? void 0 : _k.s) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.it);
|
|
@@ -101,7 +122,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
101
122
|
fa: foucsStatus,
|
|
102
123
|
t: type
|
|
103
124
|
},
|
|
104
|
-
v: value,
|
|
125
|
+
v: typeof value === "number" ? value : value,
|
|
105
126
|
m: mask
|
|
106
127
|
};
|
|
107
128
|
}
|
|
@@ -15,6 +15,16 @@ export declare function valueIsError(value: string): boolean;
|
|
|
15
15
|
export declare function isRealNull(val: any): boolean;
|
|
16
16
|
export declare function isHexValue(str: string): boolean;
|
|
17
17
|
export declare function isRealNum(val: any): boolean;
|
|
18
|
+
export type DateFormatInfo = {
|
|
19
|
+
year: number;
|
|
20
|
+
month: number;
|
|
21
|
+
day: number;
|
|
22
|
+
hours: number;
|
|
23
|
+
minutes: number;
|
|
24
|
+
seconds: number;
|
|
25
|
+
formatType: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function detectDateFormat(str: string): DateFormatInfo | null;
|
|
18
28
|
export declare function isdatetime(s: any): boolean;
|
|
19
29
|
export declare function diff(now: any, then: any): number;
|
|
20
30
|
export declare function isdatatypemulti(s: any): any;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.detectDateFormat = detectDateFormat;
|
|
6
7
|
exports.detectErrorFromValue = detectErrorFromValue;
|
|
7
8
|
exports.diff = diff;
|
|
8
9
|
exports.errorMessagesFromValue = exports.error = void 0;
|
|
@@ -56,33 +57,294 @@ function isRealNum(val) {
|
|
|
56
57
|
}
|
|
57
58
|
return !Number.isNaN(Number(val));
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
var MONTH_NAME_MAP = {
|
|
61
|
+
january: 1,
|
|
62
|
+
february: 2,
|
|
63
|
+
march: 3,
|
|
64
|
+
april: 4,
|
|
65
|
+
may: 5,
|
|
66
|
+
june: 6,
|
|
67
|
+
july: 7,
|
|
68
|
+
august: 8,
|
|
69
|
+
september: 9,
|
|
70
|
+
october: 10,
|
|
71
|
+
november: 11,
|
|
72
|
+
december: 12,
|
|
73
|
+
jan: 1,
|
|
74
|
+
feb: 2,
|
|
75
|
+
mar: 3,
|
|
76
|
+
apr: 4,
|
|
77
|
+
jun: 6,
|
|
78
|
+
jul: 7,
|
|
79
|
+
aug: 8,
|
|
80
|
+
sep: 9,
|
|
81
|
+
oct: 10,
|
|
82
|
+
nov: 11,
|
|
83
|
+
dec: 12
|
|
84
|
+
};
|
|
85
|
+
var MONTH_NAMES_RE = "january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec";
|
|
86
|
+
var MONTH_ABBR_RE = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
|
|
87
|
+
function isValidDateParts(year, month, day) {
|
|
88
|
+
if (year < 1900) return false;
|
|
89
|
+
if (month < 1 || month > 12) return false;
|
|
90
|
+
if (day < 1 || day > 31) return false;
|
|
91
|
+
if (month === 2) {
|
|
92
|
+
var isLeap = new Date(year, 1, 29).getDate() === 29;
|
|
93
|
+
if (isLeap && day > 29) return false;
|
|
94
|
+
if (!isLeap && day > 28) return false;
|
|
64
95
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
if ([4, 6, 9, 11].includes(month) && day > 30) return false;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
function detectDateFormat(str) {
|
|
100
|
+
if (!str || str.toString().length < 5) return null;
|
|
101
|
+
var s = str.toString().trim();
|
|
102
|
+
var m;
|
|
103
|
+
m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(s);
|
|
104
|
+
if (m) {
|
|
105
|
+
var y = +m[1],
|
|
106
|
+
mo = +m[2],
|
|
107
|
+
d = +m[3],
|
|
108
|
+
h = +m[4],
|
|
109
|
+
mi = +m[5],
|
|
110
|
+
sec = m[6] != null ? +m[6] : 0;
|
|
111
|
+
if (isValidDateParts(y, mo, d)) {
|
|
112
|
+
return {
|
|
113
|
+
year: y,
|
|
114
|
+
month: mo,
|
|
115
|
+
day: d,
|
|
116
|
+
hours: h,
|
|
117
|
+
minutes: mi,
|
|
118
|
+
seconds: sec,
|
|
119
|
+
formatType: "yyyy-MM-ddTHH:mm"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
70
122
|
}
|
|
71
|
-
|
|
72
|
-
|
|
123
|
+
m = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
124
|
+
if (m) {
|
|
125
|
+
var y = +m[1],
|
|
126
|
+
mo = +m[2],
|
|
127
|
+
d = +m[3];
|
|
128
|
+
if (isValidDateParts(y, mo, d)) {
|
|
129
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
130
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
131
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
132
|
+
return {
|
|
133
|
+
year: y,
|
|
134
|
+
month: mo,
|
|
135
|
+
day: d,
|
|
136
|
+
hours: h,
|
|
137
|
+
minutes: mi,
|
|
138
|
+
seconds: sec,
|
|
139
|
+
formatType: m[4] != null ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
73
142
|
}
|
|
74
|
-
|
|
75
|
-
|
|
143
|
+
m = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
144
|
+
if (m) {
|
|
145
|
+
var y = +m[1],
|
|
146
|
+
mo = +m[2],
|
|
147
|
+
d = +m[3];
|
|
148
|
+
if (isValidDateParts(y, mo, d)) {
|
|
149
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
150
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
151
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
152
|
+
return {
|
|
153
|
+
year: y,
|
|
154
|
+
month: mo,
|
|
155
|
+
day: d,
|
|
156
|
+
hours: h,
|
|
157
|
+
minutes: mi,
|
|
158
|
+
seconds: sec,
|
|
159
|
+
formatType: m[4] != null ? "yyyy/MM/dd HH:mm" : "yyyy/MM/dd"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
76
162
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
163
|
+
m = /^(\d{4})\.(\d{1,2})\.(\d{1,2})$/.exec(s);
|
|
164
|
+
if (m) {
|
|
165
|
+
var y = +m[1],
|
|
166
|
+
mo = +m[2],
|
|
167
|
+
d = +m[3];
|
|
168
|
+
if (isValidDateParts(y, mo, d)) {
|
|
169
|
+
return {
|
|
170
|
+
year: y,
|
|
171
|
+
month: mo,
|
|
172
|
+
day: d,
|
|
173
|
+
hours: 0,
|
|
174
|
+
minutes: 0,
|
|
175
|
+
seconds: 0,
|
|
176
|
+
formatType: "yyyy.MM.dd"
|
|
177
|
+
};
|
|
80
178
|
}
|
|
81
|
-
|
|
82
|
-
|
|
179
|
+
}
|
|
180
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})\s(\d{1,2}):(\d{2})\s?(AM|PM)$/i.exec(s);
|
|
181
|
+
if (m) {
|
|
182
|
+
var p1 = +m[1],
|
|
183
|
+
p2 = +m[2],
|
|
184
|
+
y = +m[3],
|
|
185
|
+
h = +m[4],
|
|
186
|
+
mi = +m[5];
|
|
187
|
+
var ampm = m[6].toUpperCase();
|
|
188
|
+
if (p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
189
|
+
var actualH = h;
|
|
190
|
+
if (ampm === "PM" && h !== 12) actualH = h + 12;
|
|
191
|
+
if (ampm === "AM" && h === 12) actualH = 0;
|
|
192
|
+
return {
|
|
193
|
+
year: y,
|
|
194
|
+
month: p1,
|
|
195
|
+
day: p2,
|
|
196
|
+
hours: actualH,
|
|
197
|
+
minutes: mi,
|
|
198
|
+
seconds: 0,
|
|
199
|
+
formatType: "MM/dd/yyyy h:mm AM/PM"
|
|
200
|
+
};
|
|
83
201
|
}
|
|
84
202
|
}
|
|
85
|
-
|
|
203
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(s);
|
|
204
|
+
if (m) {
|
|
205
|
+
var p1 = +m[1],
|
|
206
|
+
p2 = +m[2],
|
|
207
|
+
y = +m[3];
|
|
208
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
209
|
+
return {
|
|
210
|
+
year: y,
|
|
211
|
+
month: p2,
|
|
212
|
+
day: p1,
|
|
213
|
+
hours: 0,
|
|
214
|
+
minutes: 0,
|
|
215
|
+
seconds: 0,
|
|
216
|
+
formatType: "dd/MM/yyyy"
|
|
217
|
+
};
|
|
218
|
+
} else if (p2 > 12 && p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
219
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
220
|
+
return {
|
|
221
|
+
year: y,
|
|
222
|
+
month: p1,
|
|
223
|
+
day: p2,
|
|
224
|
+
hours: 0,
|
|
225
|
+
minutes: 0,
|
|
226
|
+
seconds: 0,
|
|
227
|
+
formatType: formatType
|
|
228
|
+
};
|
|
229
|
+
} else if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
230
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
231
|
+
return {
|
|
232
|
+
year: y,
|
|
233
|
+
month: p1,
|
|
234
|
+
day: p2,
|
|
235
|
+
hours: 0,
|
|
236
|
+
minutes: 0,
|
|
237
|
+
seconds: 0,
|
|
238
|
+
formatType: formatType
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
m = /^(\d{2})\/(\d{2})\/(\d{2})$/.exec(s);
|
|
243
|
+
if (m) {
|
|
244
|
+
var p1 = +m[1],
|
|
245
|
+
p2 = +m[2],
|
|
246
|
+
y = 2000 + +m[3];
|
|
247
|
+
if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
248
|
+
return {
|
|
249
|
+
year: y,
|
|
250
|
+
month: p1,
|
|
251
|
+
day: p2,
|
|
252
|
+
hours: 0,
|
|
253
|
+
minutes: 0,
|
|
254
|
+
seconds: 0,
|
|
255
|
+
formatType: "MM/dd/yy"
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
m = /^(\d{1,2})-(\d{1,2})-(\d{4})$/.exec(s);
|
|
260
|
+
if (m) {
|
|
261
|
+
var p1 = +m[1],
|
|
262
|
+
p2 = +m[2],
|
|
263
|
+
y = +m[3];
|
|
264
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
265
|
+
return {
|
|
266
|
+
year: y,
|
|
267
|
+
month: p2,
|
|
268
|
+
day: p1,
|
|
269
|
+
hours: 0,
|
|
270
|
+
minutes: 0,
|
|
271
|
+
seconds: 0,
|
|
272
|
+
formatType: "dd-MM-yyyy"
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
m = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/.exec(s);
|
|
277
|
+
if (m) {
|
|
278
|
+
var p1 = +m[1],
|
|
279
|
+
p2 = +m[2],
|
|
280
|
+
y = +m[3];
|
|
281
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
282
|
+
return {
|
|
283
|
+
year: y,
|
|
284
|
+
month: p2,
|
|
285
|
+
day: p1,
|
|
286
|
+
hours: 0,
|
|
287
|
+
minutes: 0,
|
|
288
|
+
seconds: 0,
|
|
289
|
+
formatType: "dd.MM.yyyy"
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
m = new RegExp("^(".concat(MONTH_NAMES_RE, ")\\s+(\\d{1,2}),?\\s+(\\d{4})$"), "i").exec(s);
|
|
294
|
+
if (m) {
|
|
295
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
296
|
+
var d = +m[2],
|
|
297
|
+
y = +m[3];
|
|
298
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
299
|
+
return {
|
|
300
|
+
year: y,
|
|
301
|
+
month: mo,
|
|
302
|
+
day: d,
|
|
303
|
+
hours: 0,
|
|
304
|
+
minutes: 0,
|
|
305
|
+
seconds: 0,
|
|
306
|
+
formatType: "named"
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
m = new RegExp("^(\\d{1,2})\\s+(".concat(MONTH_NAMES_RE, ")\\s+(\\d{4})$"), "i").exec(s);
|
|
311
|
+
if (m) {
|
|
312
|
+
var d = +m[1],
|
|
313
|
+
mo = MONTH_NAME_MAP[m[2].toLowerCase()],
|
|
314
|
+
y = +m[3];
|
|
315
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
316
|
+
return {
|
|
317
|
+
year: y,
|
|
318
|
+
month: mo,
|
|
319
|
+
day: d,
|
|
320
|
+
hours: 0,
|
|
321
|
+
minutes: 0,
|
|
322
|
+
seconds: 0,
|
|
323
|
+
formatType: "named"
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
m = new RegExp("^(".concat(MONTH_ABBR_RE, ")-(\\d{1,2})-(\\d{4})$"), "i").exec(s);
|
|
328
|
+
if (m) {
|
|
329
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
330
|
+
var d = +m[2],
|
|
331
|
+
y = +m[3];
|
|
332
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
333
|
+
return {
|
|
334
|
+
year: y,
|
|
335
|
+
month: mo,
|
|
336
|
+
day: d,
|
|
337
|
+
hours: 0,
|
|
338
|
+
minutes: 0,
|
|
339
|
+
seconds: 0,
|
|
340
|
+
formatType: "named"
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
function checkDateTime(str) {
|
|
347
|
+
return detectDateFormat(str) !== null;
|
|
86
348
|
}
|
|
87
349
|
function isdatetime(s) {
|
|
88
350
|
if (s === null || s.toString().length < 5) {
|