dtable-utils 5.0.18 → 5.0.20-beta.1

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.
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var LAT_DIRECTION_TYPE = {
6
+ N: 'N',
7
+ // North
8
+ S: 'S' // South
9
+ };
10
+ var LNG_DIRECTION_TYPE = {
11
+ E: 'E',
12
+ // East
13
+ W: 'W' // West
14
+ };
15
+ var DMS_SPLITTER_TYPE = {
16
+ DEG: '°',
17
+ MIN: '′',
18
+ SEC: '″'
19
+ };
20
+
21
+ exports.DMS_SPLITTER_TYPE = DMS_SPLITTER_TYPE;
22
+ exports.LAT_DIRECTION_TYPE = LAT_DIRECTION_TYPE;
23
+ exports.LNG_DIRECTION_TYPE = LNG_DIRECTION_TYPE;
package/lib/date.js CHANGED
@@ -17,6 +17,22 @@ var MATCH_1_2 = /\d\d?/; // 0 - 99
17
17
  var MATCH2 = /\d\d/; // 00 - 99
18
18
  var MATCH4 = /\d{4}/; // 0000 - 9999
19
19
 
20
+ var DATE_REG = /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/;
21
+ var DATE_WITH_TIME_REG = /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/;
22
+ var RU_DATE_REG = /^(0[1-9]|[1-2][0-9]|3[0-1])\.(0?[1-9]|1[012])\.\d{4}$/;
23
+ var RU_TIME_REG = /^(0[1-9]|[1-2][0-9]|3[0-1])\.(0?[1-9]|1[012])\.\d{4} (2[0-3]|[01][0-9]):[0-5][0-9]$/;
24
+
25
+ // month <=12 day <= 9
26
+ // month <=12 day >= 13
27
+ var US_DATE_REG = /^([1-9]|1[0-2])\/([1-9]|[1-2][3-9]|3[0-1])\/[0-9]{4}$/;
28
+ var US_TIME_REG = /^([1-9]|1[0-2])\/([1-9]|[1-2][3-9]|3[0-1])\/[0-9]{4} (2[0-3]|[01][0-9]):[0-5][0-9]$/;
29
+
30
+ // 9 < day <= 12
31
+ // 9 < month <= 12
32
+ var MID_DATE_REG = /^(1[0-2])\/(1[0-2])\/[0-9]{4}$/;
33
+ var MID_TIME_REG = /^(1[0-2])\/(1[0-2])\/[0-9]{4} (2[0-3]|[01][0-9]):[0-5][0-9]$/;
34
+ var EU_DATE_REG = /^(0[1-9]|[1-2][0-9]|3[0-1])[\/\.](0?[1-9]|1[012])[\/\.]\d{4}$/;
35
+ var EU_TIME_REG = /^(0[1-9]|[1-2][0-9]|3[0-1])[\/\.](0?[1-9]|1[012])[\/\.]\d{4} (2[0-3]|[01][0-9]):[0-5][0-9]$/;
20
36
  var MATCHER_EXPRESSIONS = {
21
37
  mm: [MATCH_1_2, column.DATE_UNIT.MINUTES],
22
38
  HH: [MATCH_1_2, column.DATE_UNIT.HOURS],
@@ -174,13 +190,32 @@ var DateUtils = /*#__PURE__*/function () {
174
190
  }, {
175
191
  key: "parseDateWithFormat",
176
192
  value: function parseDateWithFormat(dateString, format) {
193
+ var newFormat = format;
177
194
  if (dateString.includes('T')) {
178
195
  // ISO 8601 format with "T" separator directly using Date object
179
196
  var dateObj = new Date(dateString);
180
197
  return this.isValidDateObject(dateObj) ? dateObj : this.getValidDate(dateString);
181
198
  }
199
+ if (dateString.match(DATE_REG) || dateString.match(DATE_WITH_TIME_REG)) {
200
+ newFormat = format.indexOf('HH:mm') > -1 ? "".concat(column.DEFAULT_DATE_FORMAT, " HH:mm") : column.DEFAULT_DATE_FORMAT;
201
+ }
202
+ if (dateString.match(RU_DATE_REG) || dateString.match(RU_TIME_REG)) {
203
+ newFormat = format.indexOf('HH:mm') > -1 ? 'DD.MM.YYYY HH:mm' : 'DD.MM.YYYY';
204
+ }
205
+ var isUSDate = dateString.match(US_DATE_REG) || dateString.match(US_TIME_REG);
206
+ if (isUSDate) {
207
+ newFormat = format.indexOf('HH:mm') > -1 ? 'M/D/YYYY HH:mm' : 'M/D/YYYY';
208
+ }
209
+ var isEUDate = dateString.match(EU_DATE_REG) || dateString.match(EU_TIME_REG);
210
+ var isUsOrEuDate = dateString.match(MID_DATE_REG) || dateString.match(MID_TIME_REG);
211
+ var isUSFormat = ['M/D/YYYY HH:mm', 'M/D/YYYY'].includes(newFormat);
212
+ if (isUsOrEuDate && isUSFormat) {
213
+ newFormat = format.indexOf('HH:mm') > -1 ? 'M/D/YYYY HH:mm' : 'M/D/YYYY';
214
+ } else if (isEUDate) {
215
+ newFormat = format.indexOf('HH:mm') > -1 ? 'DD/MM/YYYY HH:mm' : 'DD/MM/YYYY';
216
+ }
182
217
  try {
183
- var parser = this.makeParser(format);
218
+ var parser = this.makeParser(newFormat);
184
219
  var _parser = parser(dateString),
185
220
  year = _parser.year,
186
221
  month = _parser.month,
@@ -19,6 +19,7 @@ require('../constants/filter/filter-is-within.js');
19
19
  require('../constants/sort.js');
20
20
  require('../constants/group.js');
21
21
  var number = require('../column/number.js');
22
+ require('@babel/runtime/helpers/slicedToArray');
22
23
  require('dayjs');
23
24
  var core$1 = require('../group/core.js');
24
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-utils",
3
- "version": "5.0.18",
3
+ "version": "5.0.20-beta.1",
4
4
  "description": "dtable common utils",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",