懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
71e81e 1 /*!
2 FullCalendar Luxon Plugin v4.3.0
3 Docs & License: https://fullcalendar.io/
4 (c) 2019 Adam Shaw
5 */
6
7 (function (global, factory) {
8     typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('luxon'), require('@fullcalendar/core')) :
9     typeof define === 'function' && define.amd ? define(['exports', 'luxon', '@fullcalendar/core'], factory) :
10     (global = global || self, factory(global.FullCalendarLuxon = {}, global.luxon, global.FullCalendar));
11 }(this, function (exports, luxon, core) { 'use strict';
12
13     /*! *****************************************************************************
14     Copyright (c) Microsoft Corporation. All rights reserved.
15     Licensed under the Apache License, Version 2.0 (the "License"); you may not use
16     this file except in compliance with the License. You may obtain a copy of the
17     License at http://www.apache.org/licenses/LICENSE-2.0
18
19     THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20     KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
21     WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
22     MERCHANTABLITY OR NON-INFRINGEMENT.
23
24     See the Apache Version 2.0 License for specific language governing permissions
25     and limitations under the License.
26     ***************************************************************************** */
27     /* global Reflect, Promise */
28
29     var extendStatics = function(d, b) {
30         extendStatics = Object.setPrototypeOf ||
31             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
33         return extendStatics(d, b);
34     };
35
36     function __extends(d, b) {
37         extendStatics(d, b);
38         function __() { this.constructor = d; }
39         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40     }
41
42     var __assign = function() {
43         __assign = Object.assign || function __assign(t) {
44             for (var s, i = 1, n = arguments.length; i < n; i++) {
45                 s = arguments[i];
46                 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47             }
48             return t;
49         };
50         return __assign.apply(this, arguments);
51     };
52
53     function toDateTime(date, calendar) {
54         if (!(calendar instanceof core.Calendar)) {
55             throw new Error('must supply a Calendar instance');
56         }
57         return luxon.DateTime.fromJSDate(date, {
58             zone: calendar.dateEnv.timeZone,
59             locale: calendar.dateEnv.locale.codes[0]
60         });
61     }
62     function toDuration(duration, calendar) {
63         if (!(calendar instanceof core.Calendar)) {
64             throw new Error('must supply a Calendar instance');
65         }
66         return luxon.Duration.fromObject(__assign({}, duration, { locale: calendar.dateEnv.locale.codes[0] }));
67     }
68     var LuxonNamedTimeZone = /** @class */ (function (_super) {
69         __extends(LuxonNamedTimeZone, _super);
70         function LuxonNamedTimeZone() {
71             return _super !== null && _super.apply(this, arguments) || this;
72         }
73         LuxonNamedTimeZone.prototype.offsetForArray = function (a) {
74             return arrayToLuxon(a, this.timeZoneName).offset;
75         };
76         LuxonNamedTimeZone.prototype.timestampToArray = function (ms) {
77             return luxonToArray(luxon.DateTime.fromMillis(ms, {
78                 zone: this.timeZoneName
79             }));
80         };
81         return LuxonNamedTimeZone;
82     }(core.NamedTimeZoneImpl));
83     function formatWithCmdStr(cmdStr, arg) {
84         var cmd = parseCmdStr(cmdStr);
85         if (arg.end) {
86             var start = arrayToLuxon(arg.start.array, arg.timeZone, arg.localeCodes[0]);
87             var end = arrayToLuxon(arg.end.array, arg.timeZone, arg.localeCodes[0]);
88             return formatRange(cmd, start.toFormat.bind(start), end.toFormat.bind(end), arg.separator);
89         }
90         return arrayToLuxon(arg.date.array, arg.timeZone, arg.localeCodes[0]).toFormat(cmd.whole);
91     }
92     var main = core.createPlugin({
93         cmdFormatter: formatWithCmdStr,
94         namedTimeZonedImpl: LuxonNamedTimeZone
95     });
96     function luxonToArray(datetime) {
97         return [
98             datetime.year,
99             datetime.month - 1,
100             datetime.day,
101             datetime.hour,
102             datetime.minute,
103             datetime.second,
104             datetime.millisecond
105         ];
106     }
107     function arrayToLuxon(arr, timeZone, locale) {
108         return luxon.DateTime.fromObject({
109             zone: timeZone,
110             locale: locale,
111             year: arr[0],
112             month: arr[1] + 1,
113             day: arr[2],
114             hour: arr[3],
115             minute: arr[4],
116             second: arr[5],
117             millisecond: arr[6]
118         });
119     }
120     function parseCmdStr(cmdStr) {
121         var parts = cmdStr.match(/^(.*?)\{(.*)\}(.*)$/); // TODO: lookbehinds for escape characters
122         if (parts) {
123             var middle = parseCmdStr(parts[2]);
124             return {
125                 head: parts[1],
126                 middle: middle,
127                 tail: parts[3],
128                 whole: parts[1] + middle.whole + parts[3]
129             };
130         }
131         else {
132             return {
133                 head: null,
134                 middle: null,
135                 tail: null,
136                 whole: cmdStr
137             };
138         }
139     }
140     function formatRange(cmd, formatStart, formatEnd, separator) {
141         if (cmd.middle) {
142             var startHead = formatStart(cmd.head);
143             var startMiddle = formatRange(cmd.middle, formatStart, formatEnd, separator);
144             var startTail = formatStart(cmd.tail);
145             var endHead = formatEnd(cmd.head);
146             var endMiddle = formatRange(cmd.middle, formatStart, formatEnd, separator);
147             var endTail = formatEnd(cmd.tail);
148             if (startHead === endHead && startTail === endTail) {
149                 return startHead +
150                     (startMiddle === endMiddle ? startMiddle : startMiddle + separator + endMiddle) +
151                     startTail;
152             }
153         }
154         var startWhole = formatStart(cmd.whole);
155         var endWhole = formatEnd(cmd.whole);
156         if (startWhole === endWhole) {
157             return startWhole;
158         }
159         else {
160             return startWhole + separator + endWhole;
161         }
162     }
163
164     exports.default = main;
165     exports.toDateTime = toDateTime;
166     exports.toDuration = toDuration;
167
168     Object.defineProperty(exports, '__esModule', { value: true });
169
170 }));