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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*!
FullCalendar Luxon 2 Plugin v6.0.3
Docs & License: https://fullcalendar.io/docs/luxon2
(c) 2022 Adam Shaw
*/
FullCalendar.Luxon2 = (function (exports, core, luxon, internal) {
'use strict';
function toLuxonDateTime(date, calendar) {
if (!(calendar instanceof internal.CalendarImpl)) {
throw new Error('must supply a CalendarApi instance');
}
let { dateEnv } = calendar.getCurrentData();
return luxon.DateTime.fromJSDate(date, {
zone: dateEnv.timeZone,
locale: dateEnv.locale.codes[0],
});
}
function toLuxonDuration(duration, calendar) {
if (!(calendar instanceof internal.CalendarImpl)) {
throw new Error('must supply a CalendarApi instance');
}
let { dateEnv } = calendar.getCurrentData();
return luxon.Duration.fromObject(duration, {
locale: dateEnv.locale.codes[0],
});
}
// Internal Utils
function luxonToArray(datetime) {
return [
datetime.year,
datetime.month - 1,
datetime.day,
datetime.hour,
datetime.minute,
datetime.second,
datetime.millisecond,
];
}
function arrayToLuxon(arr, timeZone, locale) {
return luxon.DateTime.fromObject({
year: arr[0],
month: arr[1] + 1,
day: arr[2],
hour: arr[3],
minute: arr[4],
second: arr[5],
millisecond: arr[6],
}, {
locale,
zone: timeZone,
});
}
class LuxonNamedTimeZone extends internal.NamedTimeZoneImpl {
offsetForArray(a) {
return arrayToLuxon(a, this.timeZoneName).offset;
}
timestampToArray(ms) {
return luxonToArray(luxon.DateTime.fromMillis(ms, {
zone: this.timeZoneName,
}));
}
}
function formatWithCmdStr(cmdStr, arg) {
let cmd = parseCmdStr(cmdStr);
if (arg.end) {
let start = arrayToLuxon(arg.start.array, arg.timeZone, arg.localeCodes[0]);
let end = arrayToLuxon(arg.end.array, arg.timeZone, arg.localeCodes[0]);
return formatRange(cmd, start.toFormat.bind(start), end.toFormat.bind(end), arg.defaultSeparator);
}
return arrayToLuxon(arg.date.array, arg.timeZone, arg.localeCodes[0]).toFormat(cmd.whole);
}
function parseCmdStr(cmdStr) {
let parts = cmdStr.match(/^(.*?)\{(.*)\}(.*)$/); // TODO: lookbehinds for escape characters
if (parts) {
let middle = parseCmdStr(parts[2]);
return {
head: parts[1],
middle,
tail: parts[3],
whole: parts[1] + middle.whole + parts[3],
};
}
return {
head: null,
middle: null,
tail: null,
whole: cmdStr,
};
}
function formatRange(cmd, formatStart, formatEnd, separator) {
if (cmd.middle) {
let startHead = formatStart(cmd.head);
let startMiddle = formatRange(cmd.middle, formatStart, formatEnd, separator);
let startTail = formatStart(cmd.tail);
let endHead = formatEnd(cmd.head);
let endMiddle = formatRange(cmd.middle, formatStart, formatEnd, separator);
let endTail = formatEnd(cmd.tail);
if (startHead === endHead && startTail === endTail) {
return startHead +
(startMiddle === endMiddle ? startMiddle : startMiddle + separator + endMiddle) +
startTail;
}
}
let startWhole = formatStart(cmd.whole);
let endWhole = formatEnd(cmd.whole);
if (startWhole === endWhole) {
return startWhole;
}
return startWhole + separator + endWhole;
}
var plugin = core.createPlugin({
name: '@fullcalendar/luxon2',
cmdFormatter: formatWithCmdStr,
namedTimeZonedImpl: LuxonNamedTimeZone,
});
core.globalPlugins.push(plugin);
exports["default"] = plugin;
exports.toLuxonDateTime = toLuxonDateTime;
exports.toLuxonDuration = toLuxonDuration;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
})({}, FullCalendar, luxon, FullCalendar.Internal);
|