Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

FIO-8541: replaced moment dependency with dayjs #5943

Draft
wants to merge 1 commit 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 @@ -81,14 +81,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
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"@formio/bootstrap": "3.0.0-dev.98.17ba6ea",
"@formio/choices.js": "^10.2.1",
"@formio/core": "2.1.0-dev.191.8c609ab",
"@formio/core": "2.1.0-dev.201.2792d73",
"@formio/text-mask-addons": "^3.8.0-formio.3",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
Expand All @@ -107,8 +107,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
6 changes: 4 additions & 2 deletions src/Webform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from "lodash";
import moment from "moment";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { compareVersions } from "compare-versions";
import EventEmitter from "./EventEmitter";
import i18nDefaults from "./i18n";
Expand All @@ -15,6 +16,7 @@ import {
getArrayFromComponentPath,
} 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 @@ -1511,7 +1513,7 @@ export default class Webform extends NestedDataComponent {
submission.metadata = submission.metadata || {};
_.defaults(submission.metadata, {
timezone: _.get(this, "_submission.metadata.timezone", currentTimezone()),
offset: parseInt(_.get(this, "_submission.metadata.offset", moment().utcOffset()), 10),
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, 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 @@ -207,8 +216,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) || '';
}
}
6 changes: 3 additions & 3 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';

Expand Down Expand Up @@ -59,10 +59,10 @@ export default class DayComponent extends Field {

constructor(component, options, data) {
if (component.maxDate && component.maxDate.indexOf('moment(') === -1) {
component.maxDate = moment(component.maxDate, 'YYYY-MM-DD').toISOString();
component.maxDate = dayjs(component.maxDate, 'YYYY-MM-DD').toISOString();
}
if (component.minDate && component.minDate.indexOf('moment(') === -1) {
component.minDate = moment(component.minDate, 'YYYY-MM-DD').toISOString();
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
30 changes: 30 additions & 0 deletions src/utils/moment-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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';

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

function moment(...args) {

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

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc @returns declaration
return dayjs(...args);
}

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

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc @param "args" description

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;
52 changes: 7 additions & 45 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@
fuse.js "^6.6.2"
redux "^4.2.0"

"@formio/[email protected].191.8c609ab":
version "2.1.0-dev.191.8c609ab"
resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.1.0-dev.191.8c609ab.tgz#2e442888c60786268ca16edc7cd26c38cbd4b773"
integrity sha512-lVj8hqddIwUJiWI6/yWF0NFl/f8QPS3ek4l6h0U1SFMPmeEdWQtcBTMLKi02gHx09kDgXhYocJIbBVVpYyqFnw==
"@formio/[email protected].201.2792d73":
version "2.1.0-dev.201.2792d73"
resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.1.0-dev.201.2792d73.tgz#2cfaabe219a823ee7687b2ec2c7ffc355a1c5301"
integrity sha512-sGrWflkplGOb+y4JPQe1KtiQ9RYNvd1pClQbz0C1o9Gu7k1fjCXxIB2Y5dfpPKA2Xh39GHaDegbjPUrYHn9jew==
dependencies:
browser-cookies "^1.2.0"
core-js "^3.38.0"
Expand All @@ -396,7 +396,6 @@
inputmask "5.0.9"
json-logic-js "^2.0.5"
lodash "^4.17.21"
moment "^2.29.4"

"@formio/text-mask-addons@^3.8.0-formio.3":
version "3.8.0-formio.3"
Expand Down Expand Up @@ -5524,18 +5523,6 @@ mock-local-storage@^1.1.24:
core-js "^3.30.2"
global "^4.3.2"

moment-timezone@^0.5.44:
version "0.5.45"
resolved "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.45.tgz#cb685acd56bac10e69d93c536366eb65aa6bcf5c"
integrity sha512-HIWmqA86KcmCAhnMAN0wuDOARV/525R2+lOLotuGFzn4HO+FH+/645z2wx0Dt3iDv6/p61SIvKnDstISainhLQ==
dependencies:
moment "^2.29.4"

moment@^2.29.4:
version "2.30.1"
resolved "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==

mrmime@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/mrmime/-/mrmime-2.0.0.tgz#151082a6e06e59a9a39b46b3e14d5cfe92b3abb4"
Expand Down Expand Up @@ -7324,7 +7311,7 @@ string-replace-loader@^3.1.0:
loader-utils "^2.0.0"
schema-utils "^3.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -7342,15 +7329,6 @@ string-width@^1.0.1, string-width@^1.0.2:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"

string-width@^4.1.0, string-width@^4.2.0:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -7411,7 +7389,7 @@ stringifier@^1.3.0:
traverse "^0.6.6"
type-name "^2.0.1"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -7432,13 +7410,6 @@ strip-ansi@^4.0.0:
dependencies:
ansi-regex "^3.0.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -8501,7 +8472,7 @@ [email protected]:
resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -8527,15 +8498,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down
Loading