MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / valToDate

Function valToDate

lib/src/value.ts:36–47  ·  view source on GitHub ↗
(val: JSONValue)

Source from the content-addressed store, hash-verified

34 * when fails.
35 */
36export function valToDate(val: JSONValue): Date {
37 // If it's a unix epoch timestamp...
38 if (typeof val == 'number') {
39 const date = new Date(0); // The 0 there is the key, which sets the date to the epoch
40 date.setUTCMilliseconds(val);
41 return date;
42 }
43 if (typeof val == 'string') {
44 return new Date(val.toString());
45 }
46 throw new Error(`Cannot be converted into Date: ${val}, is a ${typeof val}`);
47}
48
49/** Returns a number of the value, or throws an error */
50export function valToNumber(val: JSONValue): number {

Callers 3

propertyLineFunction · 0.90
useDateFunction · 0.90
ValueCompFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected