Skip to content

Commit

Permalink
JSUI-3393 Upgrade moment (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibodeauJF authored May 4, 2022
1 parent c8cc3f4 commit 3194c71
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions src/utils/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 5 additions & 8 deletions unitTests/ui/DateUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`', () => {
Expand Down Expand Up @@ -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);
Expand All @@ -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`, () => {
Expand Down
11 changes: 4 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected]:
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"
[email protected], 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==

[email protected]:
version "2.0.0"
Expand Down

0 comments on commit 3194c71

Please sign in to comment.