@onehat/data 1.11.1 → 1.11.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Util/Parsers.js +14 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,7 +1,7 @@
1
1
  import moment from 'moment';
2
2
  import momentAlt from 'relative-time-parser'; // Notice this version of moment is imported from 'relative-time-parser', and may be out of sync with our general 'moment' package
3
3
  import accounting from 'accounting-js';
4
- // import * as chrono from 'chrono-node';
4
+ import * as chrono from 'chrono-node';
5
5
  import _ from 'lodash';
6
6
 
7
7
  class Parsers {
@@ -85,21 +85,24 @@ class Parsers {
85
85
  * @return {object} moment - A moment object
86
86
  */
87
87
  static ParseDate = (value, format = null) => {
88
+ if (moment.isMoment(value)) {
89
+ return value;
90
+ }
88
91
  let result;
89
92
  try {
90
93
  result = moment(value, format);
91
94
  } catch(err) {}
92
95
 
93
- // if ((!result || !result.isValid() && chrono)) {
94
- // // try using chrono
95
- // const parsed = chrono.parse(value);
96
- // if (parsed && parsed[0] && parsed[0].date) {
97
- // const dateString = parsed[0].date();
98
- // try {
99
- // result = moment(dateString);
100
- // } catch(err) {}
101
- // }
102
- // }
96
+ if ((!result || !result.isValid() && chrono)) {
97
+ // try using chrono
98
+ const parsed = chrono.parse(value);
99
+ if (parsed && parsed[0] && parsed[0].date) {
100
+ const dateString = parsed[0].date();
101
+ try {
102
+ result = moment(dateString);
103
+ } catch(err) {}
104
+ }
105
+ }
103
106
  return result;
104
107
  }
105
108