@formio/js 5.1.0-dev.6094.c49181e → 5.1.0-dev.6101.0682abe

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.
@@ -4,6 +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
8
  const compare_versions_1 = require("compare-versions");
8
9
  const EventEmitter_1 = __importDefault(require("./EventEmitter"));
9
10
  const i18n_1 = __importDefault(require("./i18n"));
@@ -12,7 +13,6 @@ const Components_1 = __importDefault(require("./components/Components"));
12
13
  const NestedDataComponent_1 = __importDefault(require("./components/_classes/nesteddata/NestedDataComponent"));
13
14
  const utils_1 = require("./utils/utils");
14
15
  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;
@@ -1314,7 +1314,7 @@ class Webform extends NestedDataComponent_1.default {
1314
1314
  submission.metadata = submission.metadata || {};
1315
1315
  lodash_1.default.defaults(submission.metadata, {
1316
1316
  timezone: lodash_1.default.get(this, '_submission.metadata.timezone', (0, utils_1.currentTimezone)()),
1317
- offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, dayjs_1.default)().utcOffset()), 10),
1317
+ offset: parseInt(lodash_1.default.get(this, '_submission.metadata.offset', (0, moment_1.default)().utcOffset()), 10),
1318
1318
  origin: document.location.origin,
1319
1319
  referrer: document.referrer,
1320
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 dayjsFormat(): string;
20
+ get momentFormat(): 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 dayjs_1 = __importDefault(require("dayjs"));
7
+ const moment_1 = __importDefault(require("moment"));
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 dayjsFormat() {
127
- return utils_1.default.convertFormatToDayjs(this.component.format);
126
+ get momentFormat() {
127
+ return utils_1.default.convertFormatToMoment(this.component.format);
128
128
  }
129
129
  isEmpty(value = this.dataValue) {
130
130
  if (value && (value.toString() === 'Invalid Date')) {
@@ -133,14 +133,12 @@ class DateTimeComponent extends Input_1.default {
133
133
  return super.isEmpty(value);
134
134
  }
135
135
  formatValue(input) {
136
- if ((0, dayjs_1.default)(input).isValid()) {
137
- return dayjs_1.default.utc(input).toISOString();
138
- }
139
- return input;
136
+ const result = moment_1.default.utc(input).toISOString();
137
+ return result === 'Invalid date' ? input : result;
140
138
  }
141
139
  isEqual(valueA, valueB = this.dataValue) {
142
140
  return (this.isEmpty(valueA) && this.isEmpty(valueB))
143
- || dayjs_1.default.utc(valueA).format(this.dayjsFormat) === dayjs_1.default.utc(valueB).format(this.dayjsFormat);
141
+ || moment_1.default.utc(valueA).format(this.momentFormat) === moment_1.default.utc(valueB).format(this.momentFormat);
144
142
  }
145
143
  createWrapper() {
146
144
  return false;
@@ -156,19 +154,19 @@ class DateTimeComponent extends Input_1.default {
156
154
  return super.checkValidity(data, dirty, rowData);
157
155
  }
158
156
  getValueAsString(value, options) {
159
- let format = utils_1.default.convertFormatToDayjs(this.component.format);
157
+ let format = utils_1.default.convertFormatToMoment(this.component.format);
158
+ format += format.match(/z$/) ? '' : ' z';
160
159
  const timezone = this.timezone;
161
160
  if (value && !this.attached && timezone) {
162
- format += format.match(/z$/) ? '' : ' z';
163
161
  if (Array.isArray(value) && this.component.multiple) {
164
- return value.map(item => lodash_1.default.trim(utils_1.default.dayjsDate(item, format, timezone, options).format(format))).join(', ');
162
+ return value.map(item => lodash_1.default.trim(utils_1.default.momentDate(item, format, timezone, options).format(format))).join(', ');
165
163
  }
166
- return lodash_1.default.trim(utils_1.default.dayjsDate(value, format, timezone, options).format(format));
164
+ return lodash_1.default.trim(utils_1.default.momentDate(value, format, timezone, options).format(format));
167
165
  }
168
166
  if (Array.isArray(value) && this.component.multiple) {
169
- return value.map(item => lodash_1.default.trim((0, dayjs_1.default)(item).format(format))).join(', ');
167
+ return value.map(item => lodash_1.default.trim((0, moment_1.default)(item).format(format))).join(', ');
170
168
  }
171
- return (value ? lodash_1.default.trim((0, dayjs_1.default)(value).format(format)) : value) || '';
169
+ return (value ? lodash_1.default.trim((0, moment_1.default)(value).format(format)) : value) || '';
172
170
  }
173
171
  }
174
172
  exports.default = DateTimeComponent;
@@ -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|dayjs.Dayjs)} - The translated date.
167
+ * @returns {(null|Date)} - The translated date.
168
168
  */
169
- export function getDateSetting(date: string | Date): (null | dayjs.Dayjs);
169
+ export function getDateSetting(date: string | Date): (null | Date);
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,45 +182,56 @@ 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: Date, abbr: string}} - The offset date.
185
+ * @returns {Date} - The offset date.
186
186
  */
187
- export function offsetDate(date: Date, timezone: string): {
188
- date: Date;
189
- abbr: string;
190
- };
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;
191
193
  /**
192
- * Returns if we should handle a timezone difference.
194
+ * Returns if we should load the zones.
193
195
  * @param {string} timezone - The timezone to check if we should load the zones.
194
- * @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
196
+ * @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
197
+ */
198
+ export function shouldLoadZones(timezone: string): boolean;
199
+ /**
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.
195
204
  */
196
- export function shouldHandleTimezone(timezone: string): boolean;
205
+ export function loadZones(url: string, timezone: string): Promise<any> | any;
197
206
  /**
198
- * Get the Dayjs date object for translating dates with timezones.
199
- * @param {string|Date} value - The value to convert into a dayjs date.
207
+ * Get the moment date object for translating dates with timezones.
208
+ * @param {string|Date} value - The value to convert into a moment date.
200
209
  * @param {string} format - The format to convert the date to.
201
210
  * @param {string} timezone - The timezone to convert the date to.
202
211
  * @param {object} options - The options object
203
- * @returns {dayjs.Dayjs} - The dayjs date object.
212
+ * @returns {Date} - The moment date object.
204
213
  */
205
- export function dayjsDate(value: string | Date, format: string, timezone: string, options: object): dayjs.Dayjs;
214
+ export function momentDate(value: string | Date, format: string, timezone: string, options: object): Date;
206
215
  /**
207
216
  * Format a date provided a value, format, and timezone object.
217
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
208
218
  * @param {string|Date} value - The value to format.
209
219
  * @param {string} format - The format to format the date to.
210
220
  * @param {string} timezone - The timezone to format the date to.
211
221
  * @param {string} flatPickrInputFormat - The format to use for flatpickr input.
212
222
  * @returns {string} - The formatted date.
213
223
  */
214
- export function formatDate(value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
224
+ export function formatDate(timezonesUrl: string, value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
215
225
  /**
216
226
  * Pass a format function to format within a timezone.
227
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
217
228
  * @param {Function} formatFn - The format function to use.
218
229
  * @param {Date|string} date - The date to format.
219
230
  * @param {string} format - The format to format the date to.
220
231
  * @param {string} timezone - The timezone to format the date to.
221
232
  * @returns {string} - The formatted date.
222
233
  */
223
- export function formatOffset(formatFn: Function, date: Date | string, format: string, timezone: string): string;
234
+ export function formatOffset(timezonesUrl: string, formatFn: Function, date: Date | string, format: string, timezone: string): string;
224
235
  /**
225
236
  * Returns the local date format information.
226
237
  * @param {Intl.LocalesArgument} locale - The locale to get the date format for.
@@ -238,7 +249,7 @@ export function convertFormatToFlatpickr(format: string): string;
238
249
  * @param {string} format - The format to convert.
239
250
  * @returns {string} - The converted format.
240
251
  */
241
- export function convertFormatToDayjs(format: string): string;
252
+ export function convertFormatToMoment(format: string): string;
242
253
  /**
243
254
  * Convert the format from the angular-datepicker module to mask format.
244
255
  * @param {string} format - The format to convert.
@@ -505,7 +516,6 @@ export namespace componentValueTypes {
505
516
  let any: string;
506
517
  }
507
518
  export function interpolateErrors(component: Component, errors: FieldError[], interpolateFn: Function): [];
508
- import dayjs from "dayjs";
509
519
  import ConditionOperators from './conditionOperators';
510
520
  import { Evaluator } from './Evaluator';
511
521
  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.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;
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.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 = exports.observeOverload = exports.withSwitch = 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,13 +35,6 @@ 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);
45
38
  const interpolate = Evaluator_1.Evaluator.interpolate;
46
39
  exports.interpolate = interpolate;
47
40
  __exportStar(require("./formUtils"), exports);
@@ -560,7 +553,7 @@ exports.guid = guid;
560
553
  /**
561
554
  * Return a translated date setting.
562
555
  * @param {string|Date} date - The date to translate.
563
- * @returns {(null|dayjs.Dayjs)} - The translated date.
556
+ * @returns {(null|Date)} - The translated date.
564
557
  */
565
558
  function getDateSetting(date) {
566
559
  if (lodash_1.default.isNil(date) || lodash_1.default.isNaN(date) || date === '') {
@@ -580,13 +573,13 @@ function getDateSetting(date) {
580
573
  try {
581
574
  const value = Evaluator_1.Evaluator.evaluator(`return ${date};`, 'moment')(moment_timezone_1.default);
582
575
  if (typeof value === 'string') {
583
- dateSetting = (0, dayjs_1.default)(value);
576
+ dateSetting = (0, moment_timezone_1.default)(value);
584
577
  }
585
578
  else if (typeof value.toDate === 'function') {
586
- dateSetting = (0, dayjs_1.default)(value.toDate().toUTCString());
579
+ dateSetting = (0, moment_timezone_1.default)(value.toDate().toUTCString());
587
580
  }
588
581
  else if (value instanceof Date) {
589
- dateSetting = (0, dayjs_1.default)(value);
582
+ dateSetting = (0, moment_timezone_1.default)(value);
590
583
  }
591
584
  }
592
585
  catch (e) {
@@ -616,18 +609,18 @@ exports.isValidDate = isValidDate;
616
609
  * @returns {string} - The current timezone.
617
610
  */
618
611
  function currentTimezone() {
619
- if (dayjs_1.default.currentTimezone) {
620
- return dayjs_1.default.currentTimezone;
612
+ if (moment_timezone_1.default.currentTimezone) {
613
+ return moment_timezone_1.default.currentTimezone;
621
614
  }
622
- dayjs_1.default.currentTimezone = jstimezonedetect_1.default.determine().name();
623
- return dayjs_1.default.currentTimezone;
615
+ moment_timezone_1.default.currentTimezone = jstimezonedetect_1.default.determine().name();
616
+ return moment_timezone_1.default.currentTimezone;
624
617
  }
625
618
  exports.currentTimezone = currentTimezone;
626
619
  /**
627
620
  * Get an offset date provided a date object and timezone object.
628
621
  * @param {Date} date - The date to offset.
629
622
  * @param {string} timezone - The timezone to offset the date to.
630
- * @returns {{date: Date, abbr: string}} - The offset date.
623
+ * @returns {Date} - The offset date.
631
624
  */
632
625
  function offsetDate(date, timezone) {
633
626
  if (timezone === 'UTC') {
@@ -636,7 +629,7 @@ function offsetDate(date, timezone) {
636
629
  abbr: 'UTC'
637
630
  };
638
631
  }
639
- const dateMoment = (0, dayjs_1.default)(date).tz(timezone);
632
+ const dateMoment = (0, moment_timezone_1.default)(date).tz(timezone);
640
633
  return {
641
634
  date: new Date(date.getTime() + ((dateMoment.utcOffset() + date.getTimezoneOffset()) * 60000)),
642
635
  abbr: dateMoment.format('z')
@@ -644,85 +637,132 @@ function offsetDate(date, timezone) {
644
637
  }
645
638
  exports.offsetDate = offsetDate;
646
639
  /**
647
- * Returns if we should handle a timezone difference.
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.
648
649
  * @param {string} timezone - The timezone to check if we should load the zones.
649
- * @returns {boolean} - TRUE if we should handle timezones; FALSE otherwise.
650
+ * @returns {boolean} - TRUE if we should load the zones; FALSE otherwise.
650
651
  */
651
- function shouldHandleTimezone(timezone) {
652
- return !(timezone === currentTimezone() || timezone === 'UTC');
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
+ }));
653
684
  }
654
- exports.shouldHandleTimezone = shouldHandleTimezone;
685
+ exports.loadZones = loadZones;
655
686
  /**
656
- * Get the Dayjs date object for translating dates with timezones.
657
- * @param {string|Date} value - The value to convert into a dayjs date.
687
+ * Get the moment date object for translating dates with timezones.
688
+ * @param {string|Date} value - The value to convert into a moment date.
658
689
  * @param {string} format - The format to convert the date to.
659
690
  * @param {string} timezone - The timezone to convert the date to.
660
691
  * @param {object} options - The options object
661
- * @returns {dayjs.Dayjs} - The dayjs date object.
692
+ * @returns {Date} - The moment date object.
662
693
  */
663
- function dayjsDate(value, format, timezone, options) {
664
- const dayjsDate = (0, dayjs_1.default)(value);
694
+ function momentDate(value, format, timezone, options) {
695
+ const momentDate = (0, moment_timezone_1.default)(value);
665
696
  if (!timezone) {
666
- return dayjsDate;
697
+ return momentDate;
667
698
  }
668
699
  if (timezone === 'UTC') {
669
700
  timezone = 'Etc/UTC';
670
701
  }
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);
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);
673
704
  }
674
- return dayjsDate;
705
+ return momentDate;
675
706
  }
676
- exports.dayjsDate = dayjsDate;
707
+ exports.momentDate = momentDate;
677
708
  /**
678
709
  * Format a date provided a value, format, and timezone object.
710
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
679
711
  * @param {string|Date} value - The value to format.
680
712
  * @param {string} format - The format to format the date to.
681
713
  * @param {string} timezone - The timezone to format the date to.
682
714
  * @param {string} flatPickrInputFormat - The format to use for flatpickr input.
683
715
  * @returns {string} - The formatted date.
684
716
  */
685
- function formatDate(value, format, timezone, flatPickrInputFormat) {
686
- const dayjsDate = (0, dayjs_1.default)(value, flatPickrInputFormat || undefined);
717
+ function formatDate(timezonesUrl, value, format, timezone, flatPickrInputFormat) {
718
+ const momentDate = (0, moment_timezone_1.default)(value, flatPickrInputFormat || undefined);
687
719
  if (timezone === currentTimezone()) {
688
720
  // See if our format contains a "z" timezone character.
689
721
  if (format.match(/\s(z$|z\s)/)) {
690
- if (shouldHandleTimezone(timezone)) {
691
- return dayjsDate.tz(timezone).format(convertFormatToDayjs(format));
722
+ loadZones(timezonesUrl);
723
+ if (moment_timezone_1.default.zonesLoaded) {
724
+ return momentDate.tz(timezone).format(convertFormatToMoment(format));
692
725
  }
693
726
  else {
694
- return dayjsDate.format(convertFormatToDayjs(format.replace(/\s(z$|z\s)/, '')));
727
+ return momentDate.format(convertFormatToMoment(format.replace(/\s(z$|z\s)/, '')));
695
728
  }
696
729
  }
697
730
  // Return the standard format.
698
- return dayjsDate.format(convertFormatToDayjs(format));
731
+ return momentDate.format(convertFormatToMoment(format));
699
732
  }
700
733
  if (timezone === 'UTC') {
701
- const offset = offsetDate(dayjsDate.toDate(), 'UTC');
702
- return `${(0, dayjs_1.default)(offset.date).format(convertFormatToDayjs(format))} UTC`;
734
+ const offset = offsetDate(momentDate.toDate(), 'UTC');
735
+ return `${(0, moment_timezone_1.default)(offset.date).format(convertFormatToMoment(format))} UTC`;
703
736
  }
704
- if (shouldHandleTimezone(timezone)) {
705
- return dayjsDate.tz(timezone).format(`${convertFormatToDayjs(format)} z`);
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));
706
744
  }
707
- return dayjsDate.format(convertFormatToDayjs(format));
708
745
  }
709
746
  exports.formatDate = formatDate;
710
747
  /**
711
748
  * Pass a format function to format within a timezone.
749
+ * @param {string} timezonesUrl - The URL to load the timezone data from.
712
750
  * @param {Function} formatFn - The format function to use.
713
751
  * @param {Date|string} date - The date to format.
714
752
  * @param {string} format - The format to format the date to.
715
753
  * @param {string} timezone - The timezone to format the date to.
716
754
  * @returns {string} - The formatted date.
717
755
  */
718
- function formatOffset(formatFn, date, format, timezone) {
756
+ function formatOffset(timezonesUrl, formatFn, date, format, timezone) {
719
757
  if (timezone === currentTimezone()) {
720
758
  return formatFn(date, format);
721
759
  }
722
760
  if (timezone === 'UTC') {
723
761
  return `${formatFn(offsetDate(date, 'UTC').date, format)} UTC`;
724
762
  }
725
- if (shouldHandleTimezone(timezone)) {
763
+ // Load the zones since we need timezone information.
764
+ loadZones(timezonesUrl);
765
+ if (moment_timezone_1.default.zonesLoaded) {
726
766
  const offset = offsetDate(date, timezone);
727
767
  return `${formatFn(offset.date, format)} ${offset.abbr}`;
728
768
  }
@@ -782,7 +822,7 @@ exports.convertFormatToFlatpickr = convertFormatToFlatpickr;
782
822
  * @param {string} format - The format to convert.
783
823
  * @returns {string} - The converted format.
784
824
  */
785
- function convertFormatToDayjs(format) {
825
+ function convertFormatToMoment(format) {
786
826
  return format
787
827
  // Year conversion.
788
828
  .replace(/y/g, 'Y')
@@ -795,7 +835,7 @@ function convertFormatToDayjs(format) {
795
835
  // Unix Timestamp
796
836
  .replace(/U/g, 'X');
797
837
  }
798
- exports.convertFormatToDayjs = convertFormatToDayjs;
838
+ exports.convertFormatToMoment = convertFormatToMoment;
799
839
  /**
800
840
  * Convert the format from the angular-datepicker module to mask format.
801
841
  * @param {string} format - The format to convert.
@@ -22,6 +22,13 @@ 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;
25
32
  attach(input: any): Promise<any>;
26
33
  defaultFormat: {
27
34
  date: string;
@@ -51,6 +51,29 @@ class CalendarWidget extends InputWidget_1.default {
51
51
  else if (this.settings.time_24hr) {
52
52
  this.settings.format = this.settings.format.replace(/hh:mm a$/g, 'HH:mm');
53
53
  }
54
+ this.zoneLoading = false;
55
+ this.timezonesUrl = `${Formio_1.Formio.cdn['moment-timezone']}/data/packed/latest.json`;
56
+ }
57
+ /**
58
+ * Load the timezones.
59
+ * @returns {boolean} TRUE if the zones are loading, FALSE otherwise.
60
+ */
61
+ loadZones() {
62
+ const timezone = this.timezone;
63
+ if (this.zoneLoading) {
64
+ return true;
65
+ }
66
+ if (!(0, utils_1.zonesLoaded)() && (0, utils_1.shouldLoadZones)(timezone)) {
67
+ this.zoneLoading = true;
68
+ (0, utils_1.loadZones)(this.timezonesUrl, timezone).then(() => {
69
+ this.zoneLoading = false;
70
+ this.emit('redraw');
71
+ });
72
+ // Return zones are loading.
73
+ return true;
74
+ }
75
+ // Zones are already loaded.
76
+ return false;
54
77
  }
55
78
  attach(input) {
56
79
  var _a;
@@ -62,7 +85,7 @@ class CalendarWidget extends InputWidget_1.default {
62
85
  };
63
86
  this.closedOn = 0;
64
87
  this.valueFormat = (this.settings.saveAs === 'date') ? ISO_8601_FORMAT : this.settings.dateFormat || ISO_8601_FORMAT;
65
- this.valueMomentFormat = (0, utils_1.convertFormatToDayjs)(this.valueFormat);
88
+ this.valueMomentFormat = (0, utils_1.convertFormatToMoment)(this.valueFormat);
66
89
  const isReadOnly = this.settings.readOnly;
67
90
  this.settings.minDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.minDate);
68
91
  this.settings.maxDate = isReadOnly ? null : (0, utils_1.getDateSetting)(this.settings.maxDate);
@@ -226,9 +249,9 @@ class CalendarWidget extends InputWidget_1.default {
226
249
  */
227
250
  getDateValue(date, format, useTimezone) {
228
251
  if (useTimezone) {
229
- return (0, utils_1.dayjsDate)(date, this.valueFormat, this.timezone).format((0, utils_1.convertFormatToDayjs)(format));
252
+ return (0, utils_1.momentDate)(date, this.valueFormat, this.timezone).format((0, utils_1.convertFormatToMoment)(format));
230
253
  }
231
- return (0, moment_1.default)(date).format((0, utils_1.convertFormatToDayjs)(format));
254
+ return (0, moment_1.default)(date).format((0, utils_1.convertFormatToMoment)(format));
232
255
  }
233
256
  /**
234
257
  * Return the value of the selected date.
@@ -260,7 +283,7 @@ class CalendarWidget extends InputWidget_1.default {
260
283
  setValue(value) {
261
284
  const saveAsText = (this.settings.saveAs === 'text');
262
285
  if (!this.calendar) {
263
- value = value ? (0, utils_1.formatDate)(value, (0, utils_1.convertFormatToDayjs)(this.settings.format), this.timezone, (0, utils_1.convertFormatToDayjs)(this.valueMomentFormat)) : value;
286
+ value = value ? (0, utils_1.formatDate)(this.timezonesUrl, value, (0, utils_1.convertFormatToMoment)(this.settings.format), this.timezone, (0, utils_1.convertFormatToMoment)(this.valueMomentFormat)) : value;
264
287
  return super.setValue(value);
265
288
  }
266
289
  // If the component is a textfield that does not have timezone information included in the string value then skip
@@ -268,9 +291,10 @@ class CalendarWidget extends InputWidget_1.default {
268
291
  if (this.component.type === 'textfield' && !(0, utils_1.hasEncodedTimezone)(value)) {
269
292
  this.settings.skipOffset = true;
270
293
  }
294
+ const zonesLoading = this.loadZones();
271
295
  if (value) {
272
- if (!saveAsText && this.settings.readOnly) {
273
- this.calendar.setDate((0, utils_1.dayjsDate)(value, this.valueFormat, this.timezone).format(), false);
296
+ if (!saveAsText && this.settings.readOnly && !zonesLoading) {
297
+ this.calendar.setDate((0, utils_1.momentDate)(value, this.valueFormat, this.timezone).format(), false);
274
298
  }
275
299
  else if (this.isValueISO8601(value)) {
276
300
  this.calendar.setDate(value, false);
@@ -287,9 +311,9 @@ class CalendarWidget extends InputWidget_1.default {
287
311
  const inputFormat = format || this.dateFormat;
288
312
  const valueFormat = this.calendar ? this.valueFormat : this.settings.dateFormat;
289
313
  if (this.settings.saveAs === 'text' && this.componentInstance.parent && !this.settings.readOnly) {
290
- return (0, moment_1.default)(value, (0, utils_1.convertFormatToDayjs)(valueFormat)).format((0, utils_1.convertFormatToDayjs)(valueFormat));
314
+ return (0, moment_1.default)(value, (0, utils_1.convertFormatToMoment)(valueFormat)).format((0, utils_1.convertFormatToMoment)(valueFormat));
291
315
  }
292
- return (0, utils_1.formatDate)(value, inputFormat, this.timezone, (0, utils_1.convertFormatToDayjs)(valueFormat));
316
+ return (0, utils_1.formatDate)(this.timezonesUrl, value, inputFormat, this.timezone, (0, utils_1.convertFormatToMoment)(valueFormat));
293
317
  }
294
318
  setErrorClasses(hasErrors) {
295
319
  if (!this.input) {
@@ -382,7 +406,7 @@ class CalendarWidget extends InputWidget_1.default {
382
406
  const relatedTarget = event.relatedTarget ? event.relatedTarget : activeElement;
383
407
  if (!(isIEBrowser && !relatedTarget) && !this.isCalendarElement(relatedTarget)) {
384
408
  const inputValue = this.calendar.input.value;
385
- const dateValue = inputValue ? (0, moment_1.default)(this.calendar.input.value, (0, utils_1.convertFormatToDayjs)(this.valueFormat)).toDate() : inputValue;
409
+ const dateValue = inputValue ? (0, moment_1.default)(this.calendar.input.value, (0, utils_1.convertFormatToMoment)(this.valueFormat)).toDate() : inputValue;
386
410
  this.calendar.setDate(dateValue, true, this.settings.altFormat);
387
411
  }
388
412
  else if (!this.calendar.input.value && this.calendar.config.noCalendar) {
@@ -434,14 +458,14 @@ class CalendarWidget extends InputWidget_1.default {
434
458
  return (date, format) => {
435
459
  // Only format this if this is the altFormat and the form is readOnly.
436
460
  if (this.settings.readOnly && (format === this.settings.altFormat)) {
437
- if (!this.settings.enableTime || this.settings.skipOffset) {
461
+ if (!this.settings.enableTime || this.loadZones() || this.settings.skipOffset) {
438
462
  return Flatpickr.formatDate(date, format);
439
463
  }
440
464
  const currentValue = new Date(this.getValue());
441
465
  if (currentValue.toString() === date.toString()) {
442
- return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
466
+ return (0, utils_1.formatOffset)(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), new Date(this.componentValue), format, this.timezone);
443
467
  }
444
- return (0, utils_1.formatOffset)(Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
468
+ return (0, utils_1.formatOffset)(this.timezonesUrl, Flatpickr.formatDate.bind(Flatpickr), date, format, this.timezone);
445
469
  }
446
470
  return Flatpickr.formatDate(date, format);
447
471
  };
@@ -1,4 +1,5 @@
1
1
  import _ from 'lodash';
2
+ import moment from 'moment';
2
3
  import { compareVersions } from 'compare-versions';
3
4
  import EventEmitter from './EventEmitter';
4
5
  import i18nDefaults from './i18n';
@@ -7,7 +8,6 @@ import Components from './components/Components';
7
8
  import NestedDataComponent from './components/_classes/nesteddata/NestedDataComponent';
8
9
  import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, } from './utils/utils';
9
10
  import { eachComponent } from './utils/formUtils';
10
- import dayjs from "dayjs";
11
11
  // We need this here because dragula pulls in CustomEvent class that requires global to exist.
12
12
  if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
13
13
  window.global = window;
@@ -1317,7 +1317,7 @@ export default class Webform extends NestedDataComponent {
1317
1317
  submission.metadata = submission.metadata || {};
1318
1318
  _.defaults(submission.metadata, {
1319
1319
  timezone: _.get(this, '_submission.metadata.timezone', currentTimezone()),
1320
- offset: parseInt(_.get(this, '_submission.metadata.offset', dayjs().utcOffset()), 10),
1320
+ offset: parseInt(_.get(this, '_submission.metadata.offset', moment().utcOffset()), 10),
1321
1321
  origin: document.location.origin,
1322
1322
  referrer: document.referrer,
1323
1323
  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 dayjsFormat(): string;
20
+ get momentFormat(): string;
21
21
  createWrapper(): boolean;
22
22
  checkValidity(data: any, dirty: any, rowData: any): boolean;
23
23
  getValueAsString(value: any, options: any): any;