From 3194c7130124100c397e44693ffefa308044dd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-F=C3=A9lix?= Date: Wed, 4 May 2022 09:20:45 -0400 Subject: [PATCH] JSUI-3393 Upgrade moment (#1873) https://coveord.atlassian.net/browse/JSUI-3393 --- package.json | 2 +- src/utils/DateUtils.ts | 7 ++----- unitTests/ui/DateUtilsTest.ts | 13 +++++-------- yarn.lock | 11 ++++------- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 36c678d7c2..311fe92fdd 100644 --- a/package.json +++ b/package.json @@ -161,7 +161,7 @@ "exponential-backoff": "^2.2.0", "jstimezonedetect": "^1.0.6", "modal-box": "^2.0.10", - "moment": "~2.22.2", + "moment": "^2.29.3", "pikaday": "^1.4.0", "popper.js": "^1.14.3", "underscore": "^1.13.1", diff --git a/src/utils/DateUtils.ts b/src/utils/DateUtils.ts index 8b96dd1c85..f06615f165 100644 --- a/src/utils/DateUtils.ts +++ b/src/utils/DateUtils.ts @@ -202,8 +202,7 @@ export class DateUtils { } else if (date !== null && !isNaN(Number(date))) { return moment(Number(date)).toDate(); } else if (_.isString(date)) { - const formats = ['YYYY/MM/DD@HH:mm:ssZ', moment.ISO_8601]; - const dateMoment = moment(date, formats); + const dateMoment = moment(date, 'YYYY/MM/DD@HH:mm:ssZ'); return dateMoment.toDate(); } } @@ -265,9 +264,7 @@ export class DateUtils { * @returns {Date} An offset Date object corresponding to the `date` argument value plus the `offset` value. */ static offsetDateByDays(date: Date, offset: number): Date { - return moment(date) - .add(offset, 'days') - .toDate(); + return moment(date).add(offset, 'days').toDate(); } private static isTodayYesterdayOrTomorrow(d: Date, options?: IDateToStringOptions): boolean { diff --git a/unitTests/ui/DateUtilsTest.ts b/unitTests/ui/DateUtilsTest.ts index 197edd884d..9a958f2e80 100644 --- a/unitTests/ui/DateUtilsTest.ts +++ b/unitTests/ui/DateUtilsTest.ts @@ -20,6 +20,7 @@ export function DateUtilsTest() { predefinedFormat: undefined }; String['locale'] = 'en'; + DateUtils.setLocale(); }); it('should use the correct locale if the locale is `no`', () => { @@ -113,18 +114,14 @@ export function DateUtilsTest() { }); it('dateTimeToString should respect includeTimeIfToday if the date is not today', () => { - const notToday = moment(new Date()) - .subtract(2, 'days') - .toDate(); + const notToday = moment(new Date()).subtract(2, 'days').toDate(); const result = DateUtils.dateTimeToString(notToday, { includeTimeIfToday: true, includeTimeIfThisWeek: false }); expect(containsTime(result)).toBe(false); }); it('dateTimeToString should respect includeTimeIfThisWeek if the date is not this week', () => { - const notThisWeek = moment(new Date()) - .subtract(2, 'week') - .toDate(); + const notThisWeek = moment(new Date()).subtract(2, 'week').toDate(); const result = DateUtils.dateTimeToString(notThisWeek, { includeTimeIfToday: false, includeTimeIfThisWeek: true }); expect(containsTime(result)).toBe(false); @@ -141,9 +138,9 @@ export function DateUtilsTest() { expect(DateUtils.dateTimeToString(testDate(), options)).toBe('80'); }); - it(`when the #predefinedFormat is 'yyy', it does not recognize the sequence`, () => { + it(`when the #predefinedFormat is 'yyy', it displays the four digits of the year`, () => { options.predefinedFormat = 'yyy'; - expect(DateUtils.dateTimeToString(testDate(), options)).toBe('yyy'); + expect(DateUtils.dateTimeToString(testDate(), options)).toBe('1980'); }); it(`when the #predefinedFormat is 'yyyy', it displays the four digits of the year`, () => { diff --git a/yarn.lock b/yarn.lock index 716ef530df..aa8491a1b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6165,13 +6165,10 @@ modal-box@^2.0.10: version "2.0.10" resolved "https://registry.yarnpkg.com/modal-box/-/modal-box-2.0.10.tgz#470ed6b579336f9a041c7e72d32342c10c78b881" -moment@2.x: - version "2.20.1" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd" - -moment@>=2.14.0, moment@~2.22.2: - version "2.22.2" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66" +moment@2.x, moment@>=2.14.0, moment@^2.29.3: + version "2.29.3" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.3.tgz#edd47411c322413999f7a5940d526de183c031f3" + integrity sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw== ms@2.0.0: version "2.0.0"