summaryrefslogtreecommitdiffstats
path: root/server/modules/dayjs/plugin/timezone.js
blob: de709ae4bd14282117436cc31b40ffb833a727ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * Copy from node_modules/dayjs/plugin/timezone.js
 * Try to fix https://github.com/louislam/uptime-kuma/issues/2318
 * Source: https://github.com/iamkun/dayjs/tree/dev/src/plugin/utc
 * License: MIT
 */
!function (t, e) {
    // eslint-disable-next-line no-undef
    typeof exports == "object" && typeof module != "undefined" ? module.exports = e() : typeof define == "function" && define.amd ? define(e) : (t = typeof globalThis != "undefined" ? globalThis : t || self).dayjs_plugin_timezone = e();
}(this, (function () {
    "use strict";
    let t = {
        year: 0,
        month: 1,
        day: 2,
        hour: 3,
        minute: 4,
        second: 5
    };
    let e = {};
    return function (n, i, o) {
        let r;
        let a = function (t, n, i) {
            void 0 === i && (i = {});
            let o = new Date(t);
            let r = function (t, n) {
                void 0 === n && (n = {});
                let i = n.timeZoneName || "short";
                let o = t + "|" + i;
                let r = e[o];
                return r || (r = new Intl.DateTimeFormat("en-US", {
                    hour12: !1,
                    timeZone: t,
                    year: "numeric",
                    month: "2-digit",
                    day: "2-digit",
                    hour: "2-digit",
                    minute: "2-digit",
                    second: "2-digit",
                    timeZoneName: i
                }), e[o] = r), r;
            }(n, i);
            return r.formatToParts(o);
        };
        let u = function (e, n) {
            let i = a(e, n);
            let r = [];
            let u = 0;
            for (; u < i.length; u += 1) {
                let f = i[u];
                let s = f.type;
                let m = f.value;
                let c = t[s];
                c >= 0 && (r[c] = parseInt(m, 10));
            }
            let d = r[3];
            let l = d === 24 ? 0 : d;
            let v = r[0] + "-" + r[1] + "-" + r[2] + " " + l + ":" + r[4] + ":" + r[5] + ":000";
            let h = +e;
            return (o.utc(v).valueOf() - (h -= h % 1e3)) / 6e4;
        };
        let f = i.prototype;
        f.tz = function (t, e) {
            void 0 === t && (t = r);
            let n = this.utcOffset();
            let i = this.toDate();
            let a = i.toLocaleString("en-US", { timeZone: t }).replace("\u202f", " ");
            let u = Math.round((i - new Date(a)) / 1e3 / 60);
            let f = o(a).$set("millisecond", this.$ms).utcOffset(15 * -Math.round(i.getTimezoneOffset() / 15) - u, !0);
            if (e) {
                let s = f.utcOffset();
                f = f.add(n - s, "minute");
            }
            return f.$x.$timezone = t, f;
        }, f.offsetName = function (t) {
            let e = this.$x.$timezone || o.tz.guess();
            let n = a(this.valueOf(), e, { timeZoneName: t }).find((function (t) {
                return t.type.toLowerCase() === "timezonename";
            }));
            return n && n.value;
        };
        let s = f.startOf;
        f.startOf = function (t, e) {
            if (!this.$x || !this.$x.$timezone) {
                return s.call(this, t, e);
            }
            let n = o(this.format("YYYY-MM-DD HH:mm:ss:SSS"));
            return s.call(n, t, e).tz(this.$x.$timezone, !0);
        }, o.tz = function (t, e, n) {
            let i = n && e;
            let a = n || e || r;
            let f = u(+o(), a);
            if (typeof t != "string") {
                return o(t).tz(a);
            }
            let s = function (t, e, n) {
                let i = t - 60 * e * 1e3;
                let o = u(i, n);
                if (e === o) {
                    return [ i, e ];
                }
                let r = u(i -= 60 * (o - e) * 1e3, n);
                return o === r ? [ i, o ] : [ t - 60 * Math.min(o, r) * 1e3, Math.max(o, r) ];
            }(o.utc(t, i).valueOf(), f, a);
            let m = s[0];
            let c = s[1];
            let d = o(m).utcOffset(c);
            return d.$x.$timezone = a, d;
        }, o.tz.guess = function () {
            return Intl.DateTimeFormat().resolvedOptions().timeZone;
        }, o.tz.setDefault = function (t) {
            r = t;
        };
    };
}));