aboutsummaryrefslogtreecommitdiffstats
path: root/library/fullcalendar/packages/luxon2
diff options
context:
space:
mode:
Diffstat (limited to 'library/fullcalendar/packages/luxon2')
-rw-r--r--library/fullcalendar/packages/luxon2/index.global.js131
-rw-r--r--library/fullcalendar/packages/luxon2/index.global.min.js6
2 files changed, 137 insertions, 0 deletions
diff --git a/library/fullcalendar/packages/luxon2/index.global.js b/library/fullcalendar/packages/luxon2/index.global.js
new file mode 100644
index 000000000..01b55f85a
--- /dev/null
+++ b/library/fullcalendar/packages/luxon2/index.global.js
@@ -0,0 +1,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);
diff --git a/library/fullcalendar/packages/luxon2/index.global.min.js b/library/fullcalendar/packages/luxon2/index.global.min.js
new file mode 100644
index 000000000..c639271a8
--- /dev/null
+++ b/library/fullcalendar/packages/luxon2/index.global.min.js
@@ -0,0 +1,6 @@
+/*!
+FullCalendar Luxon 2 Plugin v6.0.3
+Docs & License: https://fullcalendar.io/docs/luxon2
+(c) 2022 Adam Shaw
+*/
+FullCalendar.Luxon2=function(e,t,n,a){"use strict";function l(e,t,a){return n.DateTime.fromObject({year:e[0],month:e[1]+1,day:e[2],hour:e[3],minute:e[4],second:e[5],millisecond:e[6]},{locale:a,zone:t})}class r extends a.NamedTimeZoneImpl{offsetForArray(e){return l(e,this.timeZoneName).offset}timestampToArray(e){return[(t=n.DateTime.fromMillis(e,{zone:this.timeZoneName})).year,t.month-1,t.day,t.hour,t.minute,t.second,t.millisecond];var t}}var o=t.createPlugin({name:"@fullcalendar/luxon2",cmdFormatter:function(e,t){let n=function e(t){let n=t.match(/^(.*?)\{(.*)\}(.*)$/);if(n){let t=e(n[2]);return{head:n[1],middle:t,tail:n[3],whole:n[1]+t.whole+n[3]}}return{head:null,middle:null,tail:null,whole:t}}(e);if(t.end){let e=l(t.start.array,t.timeZone,t.localeCodes[0]),a=l(t.end.array,t.timeZone,t.localeCodes[0]);return function e(t,n,a,l){if(t.middle){let r=n(t.head),o=e(t.middle,n,a,l),i=n(t.tail),u=a(t.head),d=e(t.middle,n,a,l),m=a(t.tail);if(r===u&&i===m)return r+(o===d?o:o+l+d)+i}let r=n(t.whole),o=a(t.whole);if(r===o)return r;return r+l+o}(n,e.toFormat.bind(e),a.toFormat.bind(a),t.defaultSeparator)}return l(t.date.array,t.timeZone,t.localeCodes[0]).toFormat(n.whole)},namedTimeZonedImpl:r});return t.globalPlugins.push(o),e.default=o,e.toLuxonDateTime=function(e,t){if(!(t instanceof a.CalendarImpl))throw new Error("must supply a CalendarApi instance");let{dateEnv:l}=t.getCurrentData();return n.DateTime.fromJSDate(e,{zone:l.timeZone,locale:l.locale.codes[0]})},e.toLuxonDuration=function(e,t){if(!(t instanceof a.CalendarImpl))throw new Error("must supply a CalendarApi instance");let{dateEnv:l}=t.getCurrentData();return n.Duration.fromObject(e,{locale:l.locale.codes[0]})},Object.defineProperty(e,"__esModule",{value:!0}),e}({},FullCalendar,luxon,FullCalendar.Internal); \ No newline at end of file