@onehat/data 1.11.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.11.0",
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",
@@ -78,7 +78,7 @@ class Formatters {
78
78
  return moment(date).format(format);
79
79
  }
80
80
  }
81
- return '';
81
+ return null;
82
82
  }
83
83
 
84
84
  static FormatDateTime = (value, format = 'MMM DD, YYYY HH:mm:ss') => {
@@ -94,7 +94,7 @@ class Formatters {
94
94
  return moment(date).format(format);
95
95
  }
96
96
  }
97
- return '';
97
+ return null;
98
98
  }
99
99
 
100
100
  static FormatTime = (value) => {
@@ -111,7 +111,7 @@ class Formatters {
111
111
  return moment(date).format(format);
112
112
  }
113
113
  }
114
- return '';
114
+ return null;
115
115
  }
116
116
 
117
117
  static FormatHours = (value) => {
@@ -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