@fileverse-dev/fortune-core 1.3.4-date-format-1 → 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.
@@ -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 { genarate, update } from "../modules/format";
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 (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) !== 1) {
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 ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc) {
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 && ((_e = x === null || x === void 0 ? void 0 : x[c]) === null || _e === void 0 ? void 0 : _e.mc)) {
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
- (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
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 = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
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.v = isUrl ? originalValueStr : value;
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
- originCell.m = update(originCell.ct.fa, originCell.v);
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
- var mask = genarate(value);
411
- _a = mask, cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
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 = {
@@ -1,6 +1,6 @@
1
1
  import numeral from "numeral";
2
2
  import _ from "lodash";
3
- import { isRealNum, valueIsError, isdatetime } from "./validation";
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 (isdatetime(value) && (value.toString().indexOf(".") > -1 || value.toString().indexOf(":") > -1 || value.toString().length < 16)) {
260
- v = datenum_local(parseDate(value.toString().replace(/-/g, "/")));
261
- if (v.toString().indexOf(".") > -1) {
262
- if (value.toString().length > 18) {
263
- ct.fa = "yyyy-MM-dd hh:mm:ss";
264
- } else if (value.toString().length > 11) {
265
- ct.fa = "yyyy-MM-dd hh:mm";
266
- } else {
267
- ct.fa = "yyyy-MM-dd";
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
- ct.fa = "yyyy-MM-dd";
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
  }
@@ -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";
@@ -59,10 +59,10 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
59
59
  if (foucsStatus !== "@" && isRealNum(value)) {
60
60
  value = Number(value);
61
61
  } else if (type === "d" && typeof value === "string") {
62
- var dateMask = genarate(value);
63
- if (dateMask && dateMask[1].t === "d") {
64
- var numericSerial = dateMask[2];
65
- value = numericSerial;
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
66
  }
67
67
  }
68
68
  if (foucsStatus === "General" || foucsStatus === 0) {
@@ -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;
@@ -39,33 +39,294 @@ export function isRealNum(val) {
39
39
  }
40
40
  return !Number.isNaN(Number(val));
41
41
  }
42
- function checkDateTime(str) {
43
- var reg1 = /^(\d{4})-(\d{1,2})-(\d{1,2})(\s(\d{1,2}):(\d{1,2})(:(\d{1,2}))?)?$/;
44
- var reg2 = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(\s(\d{1,2}):(\d{1,2})(:(\d{1,2}))?)?$/;
45
- if (!reg1.test(str) && !reg2.test(str)) {
46
- return false;
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
- var year = Number(RegExp.$1);
49
- var month = Number(RegExp.$2);
50
- var day = Number(RegExp.$3);
51
- if (year < 1900) {
52
- return false;
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
- if (month > 12) {
55
- return false;
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
- if (day > 31) {
58
- return false;
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
- if (month === 2) {
61
- if (new Date(year, 1, 29).getDate() === 29 && day > 29) {
62
- return false;
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
- if (new Date(year, 1, 29).getDate() !== 29 && day > 28) {
65
- return false;
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
- return true;
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) {
@@ -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 (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) !== 1) {
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 ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc) {
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 && ((_e = x === null || x === void 0 ? void 0 : x[c]) === null || _e === void 0 ? void 0 : _e.mc)) {
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
- (_f = cfg.borderInfo) === null || _f === void 0 ? void 0 : _f.push(bd_obj);
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 = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g[ctx.luckysheet_select_save.length - 1];
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.v = isUrl ? originalValueStr : value;
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
- originCell.m = (0, _format.update)(originCell.ct.fa, originCell.v);
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
- var mask = (0, _format.genarate)(value);
424
- _a = mask, cell.m = _a[0], cell.ct = _a[1], cell.v = _a[2];
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 = {
@@ -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 ((0, _validation.isdatetime)(value) && (value.toString().indexOf(".") > -1 || value.toString().indexOf(":") > -1 || value.toString().length < 16)) {
271
- v = datenum_local(parseDate(value.toString().replace(/-/g, "/")));
272
- if (v.toString().indexOf(".") > -1) {
273
- if (value.toString().length > 18) {
274
- ct.fa = "yyyy-MM-dd hh:mm:ss";
275
- } else if (value.toString().length > 11) {
276
- ct.fa = "yyyy-MM-dd hh:mm";
277
- } else {
278
- ct.fa = "yyyy-MM-dd";
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
- ct.fa = "yyyy-MM-dd";
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
  }
@@ -92,10 +92,10 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
92
92
  if (foucsStatus !== "@" && (0, _validation.isRealNum)(value)) {
93
93
  value = Number(value);
94
94
  } else if (type === "d" && typeof value === "string") {
95
- var dateMask = (0, _format.genarate)(value);
96
- if (dateMask && dateMask[1].t === "d") {
97
- var numericSerial = dateMask[2];
98
- value = numericSerial;
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
99
  }
100
100
  }
101
101
  if (foucsStatus === "General" || foucsStatus === 0) {
@@ -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
- function checkDateTime(str) {
60
- var reg1 = /^(\d{4})-(\d{1,2})-(\d{1,2})(\s(\d{1,2}):(\d{1,2})(:(\d{1,2}))?)?$/;
61
- var reg2 = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(\s(\d{1,2}):(\d{1,2})(:(\d{1,2}))?)?$/;
62
- if (!reg1.test(str) && !reg2.test(str)) {
63
- return false;
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
- var year = Number(RegExp.$1);
66
- var month = Number(RegExp.$2);
67
- var day = Number(RegExp.$3);
68
- if (year < 1900) {
69
- return false;
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
- if (month > 12) {
72
- return false;
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
- if (day > 31) {
75
- return false;
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
- if (month === 2) {
78
- if (new Date(year, 1, 29).getDate() === 29 && day > 29) {
79
- return false;
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
- if (new Date(year, 1, 29).getDate() !== 29 && day > 28) {
82
- return false;
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
- return true;
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.3.4-date-format-1",
3
+ "version": "1.3.4-date-format-2",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",