MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / toTuple

Function toTuple

host/time/src/main/fmt.js:14–18  ·  view source on GitHub ↗
(dt, utc)

Source from the content-addressed store, hash-verified

12
13// Date -> struct_time JSON, CPython order (Y, m, d, H, M, S, wday, yday, isdst).
14const toTuple = (dt, utc) => {
15 const g = (m) => (utc ? dt["getUTC" + m]() : dt["get" + m]());
16 const yday = Math.floor((Date.UTC(g("FullYear"), g("Month"), g("Date")) - Date.UTC(g("FullYear"), 0, 1)) / 86400000) + 1;
17 return JSON.stringify([g("FullYear"), g("Month") + 1, g("Date"), g("Hours"), g("Minutes"), g("Seconds"), cpyWday(g("Day")), yday, -1]);
18};
19
20// A JSON tuple string, or localtime(now) when the arg is omitted.
21const resolve = (t) => (t !== undefined ? JSON.parse(t) : JSON.parse(toTuple(new Date(), false)));

Callers 3

resolveFunction · 0.85
strptimeFunction · 0.85
fmt.jsFile · 0.85

Calls 2

gFunction · 0.85
cpyWdayFunction · 0.85

Tested by

no test coverage detected