| 12 | |
| 13 | // Date -> struct_time JSON, CPython order (Y, m, d, H, M, S, wday, yday, isdst). |
| 14 | const 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. |
| 21 | const resolve = (t) => (t !== undefined ? JSON.parse(t) : JSON.parse(toTuple(new Date(), false))); |