"use strict"; const { Temporal } = require("@js-temporal/polyfill"); const asExpression = require("as-expression"); const unreachable = require("@joepie91/unreachable")("zapdb"); module.exports = function fromTemporal(object, withTimezone) { let zoned = asExpression(() => { if (object.constructor.name === "Instant") { return object.toZonedDateTimeISO("UTC"); } else if (object.constructor.name === "ZonedDateTime") { return object; } else { unreachable("Invalid Temporal type"); } }); let normalized = (withTimezone) ? zoned : zoned.withTimeZone("UTC"); return { millisecond: normalized.millisecond, second: normalized.second, minute: normalized.minute, hour: normalized.hour, day: normalized.day, month: normalized.month, year: normalized.year, timezone: (withTimezone) ? normalized.timeZone.toString() : undefined }; };