UNPKG

dayjs-tz-helper

Version:

Day.js 時區輔助套件,提供安全解析時區日期字串與時間戳轉換功能 (Day.js timezone helper for safe timezone date string parsing and timestamp conversion)

46 lines (45 loc) 2.59 kB
!function(e, s) { "object" == typeof exports && "undefined" != typeof module ? s(exports, require("dayjs"), require("dayjs/plugin/utc"), require("dayjs/plugin/timezone"), require("@lazy-num/parse-number-string")) : "function" == typeof define && define.amd ? define([ "exports", "dayjs", "dayjs/plugin/utc", "dayjs/plugin/timezone", "@lazy-num/parse-number-string" ], s) : s((e = "undefined" != typeof globalThis ? globalThis : e || self).DayjsTzHelper = {}, e.dayjs, e.utc, e.timezone, e.parseNumberString); }(this, function(e, s, t, n, a) { "use strict"; function _isUnsafeOffsetDateString(e) { return /(?:\dZ|\+\d{2}:?\d{2})$/.test(e); } function _isUnsafeUTCDateString(e) { return /(?:GMT|UTC)/.test(e); } function tzDayjsSafeParse(e, t) { var n; return null !== t && "object" == typeof t || (t = { timezone: t }), "number" == typeof e || a.isFloatString(e) ? (e = Number(e), "number" == typeof t.minValidTimestamp ? e = Math.max(e, t.minValidTimestamp) : t.minValidTimestamp && (e = Math.max(e, 0)), e = (t.isUnixTimestampSeconds ? s.unix : s)(e)) : "string" == typeof e && (_isUnsafeOffsetDateString(e) ? e = s.utc(e) : "GMT" !== t.timezone || _isUnsafeUTCDateString(e) ? e = s(e) : e += " GMT"), s.tz(null != e ? e : void 0, null !== (n = t.timezone) && void 0 !== n ? n : void 0); } function secondsToMilliseconds(e) { return 1000 * e; } function millisecondsToSeconds(e) { return e / 1000; } s.extend(t), s.extend(n), Object.defineProperty(tzDayjsSafeParse, "__esModule", { value: !0 }), Object.defineProperty(tzDayjsSafeParse, "tzDayjsSafeParse", { value: tzDayjsSafeParse }), Object.defineProperty(tzDayjsSafeParse, "default", { value: tzDayjsSafeParse }), Object.defineProperty(tzDayjsSafeParse, "_isUnsafeOffsetDateString", { value: _isUnsafeOffsetDateString }), Object.defineProperty(tzDayjsSafeParse, "_isUnsafeUTCDateString", { value: _isUnsafeUTCDateString }), Object.defineProperty(tzDayjsSafeParse, "secondsToMilliseconds", { value: secondsToMilliseconds }), Object.defineProperty(tzDayjsSafeParse, "millisecondsToSeconds", { value: millisecondsToSeconds }), e._isUnsafeOffsetDateString = _isUnsafeOffsetDateString, e._isUnsafeUTCDateString = _isUnsafeUTCDateString, e.default = tzDayjsSafeParse, e.millisecondsToSeconds = millisecondsToSeconds, e.secondsToMilliseconds = secondsToMilliseconds, e.tzDayjsSafeParse = tzDayjsSafeParse, Object.defineProperty(e, "__esModule", { value: !0 }); }); //# sourceMappingURL=index.umd.production.min.cjs.map