Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

FIO-8541: replaced moment dependency with dayjs #5943

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,8 @@ gulp.task('embed-css', () => gulp.src('./dist/formio.embed.min.css').pipe(rename
gulp.task('clean:embed-js', () => gulp.src('./dist/formio.embed.js', { read: false, allowEmpty: true }).pipe(clean()));
gulp.task('embed-js', () => gulp.src('./dist/formio.embed.min.js').pipe(rename('formio.embed.js')).pipe(gulp.dest('./dist')));

// Copy over the moment-timezones to the resource folder.
gulp.task('timezones', () => gulp.src('./node_modules/moment-timezone/data/packed/latest.json').pipe(gulp.dest('./resources')));

// Create a new build.
gulp.task('build', gulp.series(
gulp.parallel(
'timezones'
),
gulp.parallel(
'styles-embed',
'styles-form',
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"@formio/bootstrap": "v3.0.0-dev.121.085d187",
"@formio/choices.js": "^10.2.1",
"@formio/core": "v2.4.0-dev.2",
"@formio/core": "v2.4.0-dev.201.69b9c54",
"@formio/text-mask-addons": "3.8.0-formio.4",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
Expand All @@ -92,6 +92,7 @@
"browser-md5-file": "^1.1.1",
"compare-versions": "^6.1.1",
"core-js": "^3.37.1",
"dayjs": "^1.11.13",
"dialog-polyfill": "^0.5.6",
"dom-autoscroller": "^2.3.4",
"dompurify": "^3.1.6",
Expand All @@ -107,8 +108,6 @@
"jstimezonedetect": "^1.0.7",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"moment-timezone": "^0.5.44",
"quill": "^2.0.2",
"signature_pad": "^4.2.0",
"string-hash": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Formio } from './Formio';
import * as FormioUtils from './utils/utils';
import { I18n } from './utils/i18n';
import _ from 'lodash';
import moment from 'moment';
import moment from './utils/moment-wrapper';
import maskInput from '@formio/vanilla-text-mask';

/**
Expand Down
28 changes: 16 additions & 12 deletions src/Webform.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import _ from 'lodash';
import moment from 'moment';
import { compareVersions } from 'compare-versions';
import EventEmitter from './EventEmitter';
import i18nDefaults from './i18n';
import { Formio } from './Formio';
import Components from './components/Components';
import NestedDataComponent from './components/_classes/nesteddata/NestedDataComponent';

import _ from "lodash";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { compareVersions } from "compare-versions";
import EventEmitter from "./EventEmitter";
import i18nDefaults from "./i18n";
import { Formio } from "./Formio";
import Components from "./components/Components";
import NestedDataComponent from "./components/_classes/nesteddata/NestedDataComponent";
import {
fastCloneDeep,
currentTimezone,
unescapeHTML,
getStringFromComponentPath,
convertStringToHTMLElement,
getArrayFromComponentPath,
} from './utils/utils';
import { eachComponent } from './utils/formUtils';

} from "./utils/utils";
import { eachComponent } from "./utils/formUtils";
dayjs.extend(utc);

// We need this here because dragula pulls in CustomEvent class that requires global to exist.
if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
Expand Down Expand Up @@ -1509,8 +1513,8 @@ export default class Webform extends NestedDataComponent {
// Add in metadata about client submitting the form
submission.metadata = submission.metadata || {};
_.defaults(submission.metadata, {
timezone: _.get(this, '_submission.metadata.timezone', currentTimezone()),
offset: parseInt(_.get(this, '_submission.metadata.offset', moment().utcOffset()), 10),
timezone: _.get(this, "_submission.metadata.timezone", currentTimezone()),
offset: parseInt(_.get(this, "_submission.metadata.offset", dayjs().utcOffset()), 10),
origin: document.location.origin,
referrer: document.referrer,
browserName: navigator.appName,
Expand Down
15 changes: 12 additions & 3 deletions src/components/datetime/DateTime.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import _ from 'lodash';
import moment from 'moment';
import moment from '../../utils/moment-wrapper';
import dayjs from 'dayjs';
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import customParseFormat from "dayjs/plugin/customParseFormat";
import advancedFormat from 'dayjs/plugin/advancedFormat';
import FormioUtils from '../../utils';
import { componentValueTypes, fastCloneDeep, getComponentSavedTypes } from '../../utils/utils';
import Input from '../_classes/input/Input';
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);

export default class DateTimeComponent extends Input {
static schema(...extend) {
Expand Down Expand Up @@ -211,8 +220,8 @@ export default class DateTimeComponent extends Input {
}

if (Array.isArray(value) && this.component.multiple) {
return value.map(item => _.trim(moment(item).format(format))).join(', ');
return value.map(item => _.trim(dayjs(item).format(format))).join(', ');
}
return (value ? _.trim(moment(value).format(format)) : value) || '';
return (value ? _.trim(dayjs(value).format(format)) : value) || '';
}
}
11 changes: 6 additions & 5 deletions src/components/day/Day.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import moment from 'moment';
import dayjs from 'dayjs';
import Field from '../_classes/field/Field';
import { boolValue, componentValueTypes, getComponentSavedTypes, getLocaleDateFormatInfo } from '../../utils/utils';
import { getDayFormat } from '@formio/core';
Expand Down Expand Up @@ -61,11 +61,12 @@ export default class DayComponent extends Field {
constructor(component, options, data) {
if (!options.inFormBuilder && !options.building) {
if (component.maxDate && component.maxDate.indexOf('moment(') === -1) {
component.maxDate = moment(component.maxDate, 'YYYY-MM-DD').toISOString();
}
if (component.minDate && component.minDate.indexOf('moment(') === -1) {
component.minDate = moment(component.minDate, 'YYYY-MM-DD').toISOString();
component.maxDate = dayjs(component.maxDate, 'YYYY-MM-DD').toISOString();
}
if (component.minDate && component.minDate.indexOf('moment(') === -1) {
component.minDate = dayjs(component.minDate, 'YYYY-MM-DD').toISOString();
}

}

super(component, options, data);
Expand Down
2 changes: 1 addition & 1 deletion src/components/time/Time.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment';
import moment from '../../utils/moment-wrapper';
import TextFieldComponent from '../textfield/TextField';
import { getBrowserInfo } from '../../utils/utils';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/calendarUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment';
import moment from './moment-wrapper';
import _ from 'lodash';

export const CALENDAR_ERROR_MESSAGES = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/conditionOperators/DateGreaterThan.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ConditionOperator from './ConditionOperator';
import moment from 'moment';
import moment from '../moment-wrapper';
export default class DateGeaterThan extends ConditionOperator {
static get operatorKey() {
return 'dateGreaterThan';
Expand Down
36 changes: 36 additions & 0 deletions src/utils/moment-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone"
import customParseFormat from 'dayjs/plugin/customParseFormat';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import duration from 'dayjs/plugin/duration';
import isBetween from 'dayjs/plugin/isBetween';

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);
dayjs.extend(isBetween);
dayjs.extend(duration);

/**

Check warning on line 16 in src/utils/moment-wrapper.js

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc @returns declaration
*
* @param {...any} args

Check warning on line 18 in src/utils/moment-wrapper.js

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc @param "args" description
*/
function moment(...args) {
return dayjs(...args).isValid() ? dayjs(...args) : dayjs('Invalid date');
}

moment.utc = () => dayjs.utc();
moment.tz = (date, timezone) => dayjs.tz(date, timezone);


moment.toISOString = () => {
return dayjs.isValid() ? dayjs.toISOString() : "Invalid date";
}

moment.format = (formatStr) => {
return dayjs(this).format(formatStr);
};

export default moment;
Loading
Loading