MCPcopy Index your code
hub / github.com/Lobos/react-ui / convert

Function convert

src/utils/datetime.js:153–183  ·  view source on GitHub ↗
(obj, def)

Source from the content-addressed store, hash-verified

151
152// string, unixtimestamp convert to Date
153export function convert (obj, def) {
154 if (def === undefined) {
155 def = new Date();
156 }
157
158 if (!obj) {
159 return def;
160 }
161
162 if (obj instanceof Date) {
163 return obj;
164 }
165
166 if (/^[-+]?[0-9]+$/.test(obj)) {
167 obj = parseInt(obj);
168 } else {
169 obj = obj.replace(/-/g, '/');
170 }
171
172 if (/^\d?\d:\d?\d/.test(obj)) {
173 obj = getDate(new Date()) + ' ' + obj;
174 }
175
176 obj = new Date(obj);
177 // Invalid Date
178 if (isNaN(obj.getTime())) {
179 obj = def;
180 }
181
182 return obj;
183}

Callers 1

formatFunction · 0.85

Calls 2

getDateFunction · 0.85
getTimeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…