@formio/js 5.1.0-dev.6086.0b0957a → 5.1.0-dev.6094.90c04d1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,4 +43,4 @@
43
43
 
44
44
  //! moment.js
45
45
 
46
- //! version : 0.5.46
46
+ //! version : 0.5.48
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
- const moment_1 = __importDefault(require("moment"));
8
7
  const compare_versions_1 = require("compare-versions");
9
8
  const EventEmitter_1 = __importDefault(require("./EventEmitter"));
10
9
  const i18n_1 = __importDefault(require("./i18n"));
@@ -13,6 +12,7 @@ const Components_1 = __importDefault(require("./components/Components"));
13
12
  const NestedDataComponent_1 = __importDefault(require("./components/_classes/nesteddata/NestedDataComponent"));
14
13
  const utils_1 = require("./utils/utils");
15
14
  const formUtils_1 = require("./utils/formUtils");
15
+ const dayjs_1 = __importDefault(require("dayjs"));
16
16
  // We need this here because dragula pulls in CustomEvent class that requires global to exist.
17
17
  if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
18
18
  window.global = window;
@@ -661,7 +661,9 @@ class Webform extends NestedDataComponent_1.default {
661
661
  const rebuild = this.rebuild() || Promise.resolve();
662
662
  return rebuild.then(() => {
663
663
  this.emit('formLoad', form);
664
- this.triggerCaptcha();
664
+ if (!this.options.server) {
665
+ this.triggerCaptcha();
666
+ }
665
667
  // Make sure to trigger onChange after a render event occurs to speed up form rendering.
666
668
  setTimeout(() => {
667
669
  this.onChange(flags);
@@ -1312,7 +1314,7 @@ class Webform extends NestedDataComponent_1.default {
1312
1314
  submission.metadata = submission.metadata || {};
1313
1315
  lodash_1.default.defaults(submission.metadata, {
1314
1316
  timezone: lodash_1.default.get(this, '_submission.metadata.timezone', (0, utils_1.currentTimezone)()),
1315
- offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, moment_1.default)().utcOffset()), 10),
1317
+ offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, dayjs_1.default)().utcOffset()), 10),
1316
1318
  origin: document.location.origin,
1317
1319
  referrer: document.referrer,
1318
1320
  browserName: navigator.appName,
@@ -17,7 +17,7 @@ export default class DateTimeComponent extends Input {
17
17
  };
18
18
  static savedValueTypes(schema: any): string[];
19
19
  get emptyValue(): string;
20
- get momentFormat(): string;
20
+ get dayjsFormat(): string;
21
21
  createWrapper(): boolean;
22
22
  checkValidity(data: any, dirty: any, rowData: any): boolean;
23
23
  getValueAsString(value: any, options: any): any;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
- const moment_1 = __importDefault(require("moment"));
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
8
  const utils_1 = __importDefault(require("../../utils"));
9
9
  const utils_2 = require("../../utils/utils");
10
10
  const Input_1 = __importDefault(require("../_classes/input/Input"));
@@ -123,8 +123,8 @@ class DateTimeComponent extends Input_1.default {
123
123
  get emptyValue() {
124
124
  return '';
125
125
  }
126
- get momentFormat() {
127
- return utils_1.default.convertFormatToMoment(this.component.format);
126
+ get dayjsFormat() {
127
+ return utils_1.default.convertFormatToDayjs(this.component.format);
128
128
  }
129
129
  isEmpty(value = this.dataValue) {
130
130
  if (value && (value.toString() === 'Invalid Date')) {
@@ -133,12 +133,14 @@ class DateTimeComponent extends Input_1.default {
133
133
  return super.isEmpty(value);
134
134
  }
135
135
  formatValue(input) {
136
- const result = moment_1.default.utc(input).toISOString();
137
- return result === 'Invalid date' ? input : result;
136
+ if ((0, dayjs_1.default)(input).isValid()) {
137
+ return dayjs_1.default.utc(input).toISOString();
138
+ }
139
+ return input;
138
140
  }
139
141
  isEqual(valueA, valueB = this.dataValue) {
140
142
  return (this.isEmpty(valueA) && this.isEmpty(valueB))
141
- || moment_1.default.utc(valueA).format(this.momentFormat) === moment_1.default.utc(valueB).format(this.momentFormat);
143
+ || dayjs_1.default.utc(valueA).format(this.dayjsFormat) === dayjs_1.default.utc(valueB).format(this.dayjsFormat);
142
144
  }
143
145
  createWrapper() {
144
146
  return false;
@@ -154,19 +156,19 @@ class DateTimeComponent extends Input_1.default {
154
156
  return super.checkValidity(data, dirty, rowData);
155
157
  }
156
158
  getValueAsString(value, options) {
157
- let format = utils_1.default.convertFormatToMoment(this.component.format);
158
- format += format.match(/z$/) ? '' : ' z';
159
+ let format = utils_1.default.convertFormatToDayjs(this.component.format);
159
160
  const timezone = this.timezone;
160
161
  if (value && !this.attached && timezone) {
162
+ format += format.match(/z$/) ? '' : ' z';
161
163
  if (Array.isArray(value) && this.component.multiple) {
162
- return value.map(item => lodash_1.default.trim(utils_1.default.momentDate(item, format, timezone, options).format(format))).join(', ');
164
+ return value.map(item => lodash_1.default.trim(utils_1.default.dayjsDate(item, format, timezone, options).format(format))).join(', ');
163
165
  }
164
- return lodash_1.default.trim(utils_1.default.momentDate(value, format, timezone, options).format(format));
166
+ return lodash_1.default.trim(utils_1.default.dayjsDate(value, format, timezone, options).format(format));
165
167
  }
166
168
  if (Array.isArray(value) && this.component.multiple) {
167
- return value.map(item => lodash_1.default.trim((0, moment_1.default)(item).format(format))).join(', ');
169
+ return value.map(item => lodash_1.default.trim((0, dayjs_1.default)(item).format(format))).join(', ');
168
170
  }
169
- return (value ? lodash_1.default.trim((0, moment_1.default)(value).format(format)) : value) || '';
171
+ return (value ? lodash_1.default.trim((0, dayjs_1.default)(value).format(format)) : value) || '';
170
172
  }
171
173
  }
172
174
  exports.default = DateTimeComponent;
@@ -150,6 +150,9 @@ class SelectBoxesComponent extends Radio_1.default {
150
150
  }
151
151
  }
152
152
  }
153
+ else if (lodash_1.default.isEmpty(this.loadedOptions) && !checkedValues.length) {
154
+ value = {};
155
+ }
153
156
  return value;
154
157
  }
155
158
  /**
@@ -102,8 +102,8 @@ class TextFieldComponent extends Input_1.default {
102
102
  if (((_c = this.component.widget) === null || _c === void 0 ? void 0 : _c.type) === 'calendar') {
103
103
  this.component.widget = Object.assign(Object.assign({}, this.component.widget), { readOnly: this.options.readOnly, timezone,
104
104
  displayInTimezone, locale: this.component.widget.locale || this.options.language, saveAs: 'text' });
105
- // update originalComponent to include widget settings after component initialization
106
- // originalComponent is used to restore the component (and widget) after evaluating field logic
105
+ // update originalComponent to include widget settings after component initialization
106
+ // originalComponent is used to restore the component (and widget) after evaluating field logic
107
107
  this.originalComponent = FormioUtils.fastCloneDeep(this.component);
108
108
  }
109
109
  }
@@ -164,9 +164,9 @@ export function guid(): string;
164
164
  /**
165
165
  * Return a translated date setting.
166
166
  * @param {string|Date} date - The date to translate.
167
- * @returns {(null|Date)} - The translated date.
167
+ * @returns {(null|dayjs.Dayjs)} - The translated date.
168
168
  */
169
- export function getDateSetting(date: string | Date): (null | Date);
169
+ export function getDateSetting(date: string | Date): (null | dayjs.Dayjs);
170
170
  /**
171
171
  * Returns true if the date is a valid date. False otherwise.
172
172
  * @param {Date|string} date - The date to check for validity.
@@ -182,56 +182,45 @@ export function currentTimezone(): string;
182
182
  * Get an offset date provided a date object and timezone object.
183
183
  * @param {Date} date - The date to offset.
184
184
  * @param {string} timezone - The timezone to offset the date to.
185
- * @returns {Date} - The offset date.
185
+ * @returns {{date: Date, abbr: string}} - The offset date.
186
186
  */
187
- export function offsetDate(date: Date, timezone: string): Date;
188
- /**
189
- * Returns if the zones are loaded.
190
- * @returns {boolean} - TRUE if the zones are loaded; FALSE otherwise.
191
- */
192
- export function zonesLoaded(): boolean;
187
+ export function offsetDate(date: Date, timezone: string): {
188
+ date: Date;
189
+ abbr: string;
190
+ };
193
191
  /**
194
- * Returns if we should load the zones.
192
+ * Returns if we should handle a timezone difference.
195
193
  * @param {string} timezone - The timezone to check if we should load the zones.
196
- * @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
194
+ * @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
197
195
  */
198
- export function shouldLoadZones(timezone: string): boolean;
196
+ export function shouldHandleTimezone(timezone: string): boolean;
199
197
  /**
200
- * Externally load the timezone data.
201
- * @param {string} url - The URL to load the timezone data from.
202
- * @param {string} timezone - The timezone to load.
203
- * @returns {Promise<any> | *} - Resolves when the zones for this timezone are loaded.
204
- */
205
- export function loadZones(url: string, timezone: string): Promise<any> | any;
206
- /**
207
- * Get the moment date object for translating dates with timezones.
208
- * @param {string|Date} value - The value to convert into a moment date.
198
+ * Get the Dayjs date object for translating dates with timezones.
199
+ * @param {string|Date} value - The value to convert into a dayjs date.
209
200
  * @param {string} format - The format to convert the date to.
210
201
  * @param {string} timezone - The timezone to convert the date to.
211
202
  * @param {object} options - The options object
212
- * @returns {Date} - The moment date object.
203
+ * @returns {dayjs.Dayjs} - The dayjs date object.
213
204
  */
214
- export function momentDate(value: string | Date, format: string, timezone: string, options: object): Date;
205
+ export function dayjsDate(value: string | Date, format: string, timezone: string, options: object): dayjs.Dayjs;
215
206
  /**
216
207
  * Format a date provided a value, format, and timezone object.
217
- * @param {string} timezonesUrl - The URL to load the timezone data from.
218
208
  * @param {string|Date} value - The value to format.
219
209
  * @param {string} format - The format to format the date to.
220
210
  * @param {string} timezone - The timezone to format the date to.
221
211
  * @param {string} flatPickrInputFormat - The format to use for flatpickr input.
222
212
  * @returns {string} - The formatted date.
223
213
  */
224
- export function formatDate(timezonesUrl: string, value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
214
+ export function formatDate(value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
225
215
  /**
226
216
  * Pass a format function to format within a timezone.
227
- * @param {string} timezonesUrl - The URL to load the timezone data from.
228
217
  * @param {Function} formatFn - The format function to use.
229
218
  * @param {Date|string} date - The date to format.
230
219
  * @param {string} format - The format to format the date to.
231
220
  * @param {string} timezone - The timezone to format the date to.
232
221
  * @returns {string} - The formatted date.
233
222
  */
234
- export function formatOffset(timezonesUrl: string, formatFn: Function, date: Date | string, format: string, timezone: string): string;
223
+ export function formatOffset(formatFn: Function, date: Date | string, format: string, timezone: string): string;
235
224
  /**
236
225
  * Returns the local date format information.
237
226
  * @param {Intl.LocalesArgument} locale - The locale to get the date format for.
@@ -249,7 +238,7 @@ export function convertFormatToFlatpickr(format: string): string;
249
238
  * @param {string} format - The format to convert.
250
239
  * @returns {string} - The converted format.
251
240
  */
252
- export function convertFormatToMoment(format: string): string;
241
+ export function convertFormatToDayjs(format: string): string;
253
242
  /**
254
243
  * Convert the format from the angular-datepicker module to mask format.
255
244
  * @param {string} format - The format to convert.
@@ -490,6 +479,15 @@ export function getFocusableElements(element: HTMLElement): NodeList<HTMLElement
490
479
  * @returns {Array<string>|null} - The saved types for the component
491
480
  */
492
481
  export function getComponentSavedTypes(fullSchema: import('@formio/core').Component): Array<string> | null;
482
+ /**
483
+ * Checks if a string has timezone information encoded in it
484
+ * Example: 2024-01-01T00:00:00Z -> true
485
+ * Example: 2024-01-01T00:00:00+03:00 -> true
486
+ * Example: 2011-05-03T00:00:00 -> false
487
+ * @param {string} value the string value to check
488
+ * @returns {boolean} if value has encoded timezone
489
+ */
490
+ export function hasEncodedTimezone(value: string): boolean;
493
491
  export * from "./formUtils";
494
492
  /**
495
493
  * Map values through unfold and return first non-nil value.
@@ -507,6 +505,7 @@ export namespace componentValueTypes {
507
505
  let any: string;
508
506
  }
509
507
  export function interpolateErrors(component: Component, errors: FieldError[], interpolateFn: Function): [];
508
+ import dayjs from "dayjs";
510
509
  import ConditionOperators from './conditionOperators';
511
510
  import { Evaluator } from './Evaluator';
512
511
  export const interpolate: typeof Evaluator.interpolate;
@@ -18,8 +18,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.firstNonNil = exports.unfold = exports.bootstrapVersion = exports.uniqueKey = exports.iterateKey = exports.delay = exports.fieldData = exports.getCurrencyAffixes = exports.getNumberDecimalLimit = exports.getNumberSeparators = exports.matchInputMask = exports.unmaskValue = exports.getInputMask = exports.convertFormatToMask = exports.convertFormatToMoment = exports.convertFormatToFlatpickr = exports.getLocaleDateFormatInfo = exports.formatOffset = exports.formatDate = exports.momentDate = exports.loadZones = exports.shouldLoadZones = exports.zonesLoaded = exports.offsetDate = exports.currentTimezone = exports.isValidDate = exports.getDateSetting = exports.guid = exports.uniqueName = exports.convertStringToHTMLElement = exports.unescapeHTML = exports.removeHTML = exports.setActionProperty = exports.checkTrigger = exports.checkCondition = exports.checkJsonConditional = exports.checkCustomConditional = exports.getComponentActualValue = exports.checkSimpleConditional = exports.checkCalculated = exports.isMongoId = exports.boolValue = exports.getScriptPlugin = exports.getElementRect = exports.getPropertyValue = exports.getRandomComponentId = exports.evaluate = exports.moment = exports.ConditionOperators = exports.jsonLogic = void 0;
22
- exports.interpolateErrors = exports.getComponentSavedTypes = exports.componentValueTypes = exports._ = exports.getFocusableElements = exports.isPromise = exports.getDataParentComponent = exports.getComponentPath = exports.getComponentPathWithoutIndicies = exports.getBrowserInfo = exports.getIEBrowserVersion = exports.round = exports.getStringFromComponentPath = exports.isChildOf = exports.getArrayFromComponentPath = exports.isInputComponent = exports.interpolate = exports.Evaluator = exports.fastCloneDeep = exports.sanitize = exports.translateHTMLTemplate = exports.getContextButtons = exports.getContextComponents = exports.observeOverload = exports.withSwitch = void 0;
21
+ exports.observeOverload = exports.withSwitch = exports.firstNonNil = exports.unfold = exports.bootstrapVersion = exports.uniqueKey = exports.iterateKey = exports.delay = exports.fieldData = exports.getCurrencyAffixes = exports.getNumberDecimalLimit = exports.getNumberSeparators = exports.matchInputMask = exports.unmaskValue = exports.getInputMask = exports.convertFormatToMask = exports.convertFormatToDayjs = exports.convertFormatToFlatpickr = exports.getLocaleDateFormatInfo = exports.formatOffset = exports.formatDate = exports.dayjsDate = exports.shouldHandleTimezone = exports.offsetDate = exports.currentTimezone = exports.isValidDate = exports.getDateSetting = exports.guid = exports.uniqueName = exports.convertStringToHTMLElement = exports.unescapeHTML = exports.removeHTML = exports.setActionProperty = exports.checkTrigger = exports.checkCondition = exports.checkJsonConditional = exports.checkCustomConditional = exports.getComponentActualValue = exports.checkSimpleConditional = exports.checkCalculated = exports.isMongoId = exports.boolValue = exports.getScriptPlugin = exports.getElementRect = exports.getPropertyValue = exports.getRandomComponentId = exports.evaluate = exports.moment = exports.ConditionOperators = exports.jsonLogic = void 0;
22
+ exports.hasEncodedTimezone = exports.interpolateErrors = exports.getComponentSavedTypes = exports.componentValueTypes = exports._ = exports.getFocusableElements = exports.isPromise = exports.getDataParentComponent = exports.getComponentPath = exports.getComponentPathWithoutIndicies = exports.getBrowserInfo = exports.getIEBrowserVersion = exports.round = exports.getStringFromComponentPath = exports.isChildOf = exports.getArrayFromComponentPath = exports.isInputComponent = exports.interpolate = exports.Evaluator = exports.fastCloneDeep = exports.sanitize = exports.translateHTMLTemplate = exports.getContextButtons = exports.getContextComponents = void 0;
23
23
  const lodash_1 = __importDefault(require("lodash"));
24
24
  exports._ = lodash_1.default;
25
25
  const json_logic_js_1 = __importDefault(require("json-logic-js"));
@@ -35,6 +35,13 @@ Object.defineProperty(exports, "Evaluator", { enumerable: true, get: function ()
35
35
  const conditionOperators_1 = __importDefault(require("./conditionOperators"));
36
36
  exports.ConditionOperators = conditionOperators_1.default;
37
37
  const core_1 = require("@formio/core");
38
+ const dayjs_1 = __importDefault(require("dayjs"));
39
+ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
40
+ const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
41
+ const advancedFormat_1 = __importDefault(require("dayjs/plugin/advancedFormat"));
42
+ dayjs_1.default.extend(timezone_1.default);
43
+ dayjs_1.default.extend(advancedFormat_1.default);
44
+ dayjs_1.default.extend(utc_1.default);
38
45
  const interpolate = Evaluator_1.Evaluator.interpolate;
39
46
  exports.interpolate = interpolate;
40
47
  __exportStar(require("./formUtils"), exports);
@@ -553,7 +560,7 @@ exports.guid = guid;
553
560
  /**
554
561
  * Return a translated date setting.
555
562
  * @param {string|Date} date - The date to translate.
556
- * @returns {(null|Date)} - The translated date.
563
+ * @returns {(null|dayjs.Dayjs)} - The translated date.
557
564
  */
558
565
  function getDateSetting(date) {
559
566
  if (lodash_1.default.isNil(date) || lodash_1.default.isNaN(date) || date === '') {
@@ -573,13 +580,13 @@ function getDateSetting(date) {
573
580
  try {
574
581
  const value = Evaluator_1.Evaluator.evaluator(`return ${date};`, 'moment')(moment_timezone_1.default);
575
582
  if (typeof value === 'string') {
576
- dateSetting = (0, moment_timezone_1.default)(value);
583
+ dateSetting = (0, dayjs_1.default)(value);
577
584
  }
578
585
  else if (typeof value.toDate === 'function') {
579
- dateSetting = (0, moment_timezone_1.default)(value.toDate().toUTCString());
586
+ dateSetting = (0, dayjs_1.default)(value.toDate().toUTCString());
580
587
  }
581
588
  else if (value instanceof Date) {
582
- dateSetting = (0, moment_timezone_1.default)(value);
589
+ dateSetting = (0, dayjs_1.default)(value);
583
590
  }
584
591
  }
585
592
  catch (e) {
@@ -609,18 +616,18 @@ exports.isValidDate = isValidDate;
609
616
  * @returns {string} - The current timezone.
610
617
  */
611
618
  function currentTimezone() {
612
- if (moment_timezone_1.default.currentTimezone) {
613
- return moment_timezone_1.default.currentTimezone;
619
+ if (dayjs_1.default.currentTimezone) {
620
+ return dayjs_1.default.currentTimezone;
614
621
  }
615
- moment_timezone_1.default.currentTimezone = jstimezonedetect_1.default.determine().name();
616
- return moment_timezone_1.default.currentTimezone;
622
+ dayjs_1.default.currentTimezone = jstimezonedetect_1.default.determine().name();
623
+ return dayjs_1.default.currentTimezone;
617
624
  }
618
625
  exports.currentTimezone = currentTimezone;
619
626
  /**
620
627
  * Get an offset date provided a date object and timezone object.
621
628
  * @param {Date} date - The date to offset.
622
629
  * @param {string} timezone - The timezone to offset the date to.
623
- * @returns {Date} - The offset date.
630
+ * @returns {{date: Date, abbr: string}} - The offset date.
624
631
  */
625
632
  function offsetDate(date, timezone) {
626
633
  if (timezone === 'UTC') {
@@ -629,7 +636,7 @@ function offsetDate(date, timezone) {
629
636
  abbr: 'UTC'
630
637
  };
631
638
  }
632
- const dateMoment = (0, moment_timezone_1.default)(date).tz(timezone);
639
+ const dateMoment = (0, dayjs_1.default)(date).tz(timezone);
633
640
  return {
634
641
  date: new Date(date.getTime() + ((dateMoment.utcOffset() + date.getTimezoneOffset()) * 60000)),
635
642
  abbr: dateMoment.format('z')
@@ -637,132 +644,85 @@ function offsetDate(date, timezone) {
637
644
  }
638
645
  exports.offsetDate = offsetDate;
639
646
  /**
640
- * Returns if the zones are loaded.
641
- * @returns {boolean} - TRUE if the zones are loaded; FALSE otherwise.
642
- */
643
- function zonesLoaded() {
644
- return moment_timezone_1.default.zonesLoaded;
645
- }
646
- exports.zonesLoaded = zonesLoaded;
647
- /**
648
- * Returns if we should load the zones.
647
+ * Returns if we should handle a timezone difference.
649
648
  * @param {string} timezone - The timezone to check if we should load the zones.
650
- * @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
649
+ * @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
651
650
  */
652
- function shouldLoadZones(timezone) {
653
- if (timezone === currentTimezone() || timezone === 'UTC') {
654
- return false;
655
- }
656
- return true;
657
- }
658
- exports.shouldLoadZones = shouldLoadZones;
659
- /**
660
- * Externally load the timezone data.
661
- * @param {string} url - The URL to load the timezone data from.
662
- * @param {string} timezone - The timezone to load.
663
- * @returns {Promise<any> | *} - Resolves when the zones for this timezone are loaded.
664
- */
665
- function loadZones(url, timezone) {
666
- if (timezone && !shouldLoadZones(timezone)) {
667
- // Return non-resolving promise.
668
- return new Promise(lodash_1.default.noop);
669
- }
670
- if (moment_timezone_1.default.zonesPromise) {
671
- return moment_timezone_1.default.zonesPromise;
672
- }
673
- return moment_timezone_1.default.zonesPromise = fetch(url)
674
- .then(resp => resp.json().then(zones => {
675
- moment_timezone_1.default.tz.load(zones);
676
- moment_timezone_1.default.zonesLoaded = true;
677
- // Trigger a global event that the timezones have finished loading.
678
- if (document && document.createEvent && document.body && document.body.dispatchEvent) {
679
- var event = document.createEvent('Event');
680
- event.initEvent('zonesLoaded', true, true);
681
- document.body.dispatchEvent(event);
682
- }
683
- }));
651
+ function shouldHandleTimezone(timezone) {
652
+ return !(timezone === currentTimezone() || timezone === 'UTC');
684
653
  }
685
- exports.loadZones = loadZones;
654
+ exports.shouldHandleTimezone = shouldHandleTimezone;
686
655
  /**
687
- * Get the moment date object for translating dates with timezones.
688
- * @param {string|Date} value - The value to convert into a moment date.
656
+ * Get the Dayjs date object for translating dates with timezones.
657
+ * @param {string|Date} value - The value to convert into a dayjs date.
689
658
  * @param {string} format - The format to convert the date to.
690
659
  * @param {string} timezone - The timezone to convert the date to.
691
660
  * @param {object} options - The options object
692
- * @returns {Date} - The moment date object.
661
+ * @returns {dayjs.Dayjs} - The dayjs date object.
693
662
  */
694
- function momentDate(value, format, timezone, options) {
695
- const momentDate = (0, moment_timezone_1.default)(value);
663
+ function dayjsDate(value, format, timezone, options) {
664
+ const dayjsDate = (0, dayjs_1.default)(value);
696
665
  if (!timezone) {
697
- return momentDate;
666
+ return dayjsDate;
698
667
  }
699
668
  if (timezone === 'UTC') {
700
669
  timezone = 'Etc/UTC';
701
670
  }
702
- if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (moment_timezone_1.default.zonesLoaded || (options === null || options === void 0 ? void 0 : options.email))) {
703
- return momentDate.tz(timezone);
671
+ if ((timezone !== currentTimezone() || (format && format.match(/\s(z$|z\s)/))) && (shouldHandleTimezone(timezone) || (options === null || options === void 0 ? void 0 : options.email))) {
672
+ return dayjsDate.tz(timezone);
704
673
  }
705
- return momentDate;
674
+ return dayjsDate;
706
675
  }
707
- exports.momentDate = momentDate;
676
+ exports.dayjsDate = dayjsDate;
708
677
  /**
709
678
  * Format a date provided a value, format, and timezone object.
710
- * @param {string} timezonesUrl - The URL to load the timezone data from.
711
679
  * @param {string|Date} value - The value to format.
712
680
  * @param {string} format - The format to format the date to.
713
681
  * @param {string} timezone - The timezone to format the date to.
714
682
  * @param {string} flatPickrInputFormat - The format to use for flatpickr input.
715
683
  * @returns {string} - The formatted date.
716
684
  */
717
- function formatDate(timezonesUrl, value, format, timezone, flatPickrInputFormat) {
718
- const momentDate = (0, moment_timezone_1.default)(value, flatPickrInputFormat || undefined);
685
+ function formatDate(value, format, timezone, flatPickrInputFormat) {
686
+ const dayjsDate = (0, dayjs_1.default)(value, flatPickrInputFormat || undefined);
719
687
  if (timezone === currentTimezone()) {
720
688
  // See if our format contains a "z" timezone character.
721
689
  if (format.match(/\s(z$|z\s)/)) {
722
- loadZones(timezonesUrl);
723
- if (moment_timezone_1.default.zonesLoaded) {
724
- return momentDate.tz(timezone).format(convertFormatToMoment(format));
690
+ if (shouldHandleTimezone(timezone)) {
691
+ return dayjsDate.tz(timezone).format(convertFormatToDayjs(format));
725
692
  }
726
693
  else {
727
- return momentDate.format(convertFormatToMoment(format.replace(/\s(z$|z\s)/, '')));
694
+ return dayjsDate.format(convertFormatToDayjs(format.replace(/\s(z$|z\s)/, '')));
728
695
  }
729
696
  }
730
697
  // Return the standard format.
731
- return momentDate.format(convertFormatToMoment(format));
698
+ return dayjsDate.format(convertFormatToDayjs(format));
732
699
  }
733
700
  if (timezone === 'UTC') {
734
- const offset = offsetDate(momentDate.toDate(), 'UTC');
735
- return `${(0, moment_timezone_1.default)(offset.date).format(convertFormatToMoment(format))} UTC`;
701
+ const offset = offsetDate(dayjsDate.toDate(), 'UTC');
702
+ return `${(0, dayjs_1.default)(offset.date).format(convertFormatToDayjs(format))} UTC`;
736
703
  }
737
- // Load the zones since we need timezone information.
738
- loadZones(timezonesUrl);
739
- if (moment_timezone_1.default.zonesLoaded && timezone) {
740
- return momentDate.tz(timezone).format(`${convertFormatToMoment(format)} z`);
741
- }
742
- else {
743
- return momentDate.format(convertFormatToMoment(format));
704
+ if (shouldHandleTimezone(timezone)) {
705
+ return dayjsDate.tz(timezone).format(`${convertFormatToDayjs(format)} z`);
744
706
  }
707
+ return dayjsDate.format(convertFormatToDayjs(format));
745
708
  }
746
709
  exports.formatDate = formatDate;
747
710
  /**
748
711
  * Pass a format function to format within a timezone.
749
- * @param {string} timezonesUrl - The URL to load the timezone data from.
750
712
  * @param {Function} formatFn - The format function to use.
751
713
  * @param {Date|string} date - The date to format.
752
714
  * @param {string} format - The format to format the date to.
753
715
  * @param {string} timezone - The timezone to format the date to.
754
716
  * @returns {string} - The formatted date.
755
717
  */
756
- function formatOffset(timezonesUrl, formatFn, date, format, timezone) {
718
+ function formatOffset(formatFn, date, format, timezone) {
757
719
  if (timezone === currentTimezone()) {
758
720
  return formatFn(date, format);
759
721
  }
760
722
  if (timezone === 'UTC') {
761
723
  return `${formatFn(offsetDate(date, 'UTC').date, format)} UTC`;
762
724
  }
763
- // Load the zones since we need timezone information.
764
- loadZones(timezonesUrl);
765
- if (moment_timezone_1.default.zonesLoaded) {
725
+ if (shouldHandleTimezone(timezone)) {
766
726
  const offset = offsetDate(date, timezone);
767
727
  return `${formatFn(offset.date, format)} ${offset.abbr}`;
768
728
  }
@@ -822,7 +782,7 @@ exports.convertFormatToFlatpickr = convertFormatToFlatpickr;
822
782
  * @param {string} format - The format to convert.
823
783
  * @returns {string} - The converted format.
824
784
  */
825
- function convertFormatToMoment(format) {
785
+ function convertFormatToDayjs(format) {
826
786
  return format
827
787
  // Year conversion.
828
788
  .replace(/y/g, 'Y')
@@ -835,7 +795,7 @@ function convertFormatToMoment(format) {
835
795
  // Unix Timestamp
836
796
  .replace(/U/g, 'X');
837
797
  }
838
- exports.convertFormatToMoment = convertFormatToMoment;
798
+ exports.convertFormatToDayjs = convertFormatToDayjs;
839
799
  /**
840
800
  * Convert the format from the angular-datepicker module to mask format.
841
801
  * @param {string} format - The format to convert.
@@ -1646,3 +1606,18 @@ const interpolateErrors = (component, errors, interpolateFn) => {
1646
1606
  });
1647
1607
  };
1648
1608
  exports.interpolateErrors = interpolateErrors;
1609
+ /**
1610
+ * Checks if a string has timezone information encoded in it
1611
+ * Example: 2024-01-01T00:00:00Z -> true
1612
+ * Example: 2024-01-01T00:00:00+03:00 -> true
1613
+ * Example: 2011-05-03T00:00:00 -> false
1614
+ * @param {string} value the string value to check
1615
+ * @returns {boolean} if value has encoded timezone
1616
+ */
1617
+ function hasEncodedTimezone(value) {
1618
+ if (typeof value !== 'string') {
1619
+ return false;
1620
+ }
1621
+ return (value.substring(value.length - 1) === 'z' || value.substring(value.length - 1) === 'Z' || value.match(/[+|-][0-9]{2}:[0-9]{2}$/));
1622
+ }
1623
+ exports.hasEncodedTimezone = hasEncodedTimezone;
@@ -22,13 +22,6 @@ export default class CalendarWidget extends InputWidget {
22
22
  minDate: string;
23
23
  maxDate: string;
24
24
  };
25
- zoneLoading: boolean;
26
- timezonesUrl: string;
27
- /**
28
- * Load the timezones.
29
- * @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
30
- */
31
- loadZones(): boolean;
32
25
  attach(input: any): Promise<any>;
33
26
  defaultFormat: {
34
27
  date: string;