dependencies: Replace moment.js with date-fns.

Replaced methods/functions of moment.js with date-fns library.
The motive was to replace it with a smaller frontend timezone library.

Date-fns ~ 11.51 kb
moment.js ~ 217.87 kb

Some of the format strings change because date-fns encodes them
differently from how moment did.

Fixes #16373.
This commit is contained in:
aryanshridhar
2020-09-30 01:50:46 +05:30
committed by Tim Abbott
parent 26a81ab3aa
commit f92f99d92d
19 changed files with 112 additions and 77 deletions

View File

@@ -2,7 +2,7 @@
const {strict: assert} = require("assert");
const moment = require("moment");
const {getTime} = require("date-fns");
const XDate = require("xdate");
const {set_global, zrequire} = require("../zjsunit/namespace");
@@ -150,10 +150,10 @@ run_test("get_timestamp_for_flatpickr", () => {
Date.now = () => new Date("2020-07-07T10:00:00Z").getTime();
// Invalid timestamps should show current time.
assert.equal(func("random str").valueOf(), moment().valueOf());
assert.equal(func("random str").valueOf(), getTime(new Date()));
// Valid ISO timestamps should return Date objects.
assert.equal(func(iso_timestamp).valueOf(), moment(unix_timestamp).valueOf());
assert.equal(func(iso_timestamp).valueOf(), getTime(new Date(unix_timestamp)));
// Restore the Date object.
Date.now = date_now;