@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.
- package/package.json +1 -1
- package/src/Util/Parsers.js +14 -11
package/package.json
CHANGED
package/src/Util/Parsers.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|