From: Jakka Prihatna Date: Tue, 15 Sep 2020 02:23:02 +0000 (+0700) Subject: [bugfix] allow calendar with falsy input (#5647) X-Git-Tag: 2.29.0~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=503219eb470ce0339a53572fb6e5f920591f77d7;p=thirdparty%2Fmoment.git [bugfix] allow calendar with falsy input (#5647) --- diff --git a/src/lib/moment/calendar.js b/src/lib/moment/calendar.js index 5d2998fac..fdd53dcb3 100644 --- a/src/lib/moment/calendar.js +++ b/src/lib/moment/calendar.js @@ -25,7 +25,10 @@ export function getCalendarFormat(myMoment, now) { export function calendar(time, formats) { // Support for single parameter, formats only overload to the calendar function if (arguments.length === 1) { - if (isMomentInput(arguments[0])) { + if (!arguments[0]) { + time = undefined; + formats = undefined; + } else if (isMomentInput(arguments[0])) { time = arguments[0]; formats = undefined; } else if (isCalendarSpec(arguments[0])) { diff --git a/src/test/moment/calendar.js b/src/test/moment/calendar.js index 47ee29d7d..b1e472879 100644 --- a/src/test/moment/calendar.js +++ b/src/test/moment/calendar.js @@ -184,3 +184,31 @@ test('calendar overload format - passing one parameter - object w/ sameDay as fu 'should equate' ); }); + +test('defaulting to current date', function (assert) { + var a = moment().hours(13).minutes(23).seconds(45); + assert.equal(moment(a).calendar(), 'Today at 1:23 PM', 'should equate'); +}); + +test('calendar overload time - passing one parameter - a falsy value', function (assert) { + var a = moment().hours(13).minutes(23).seconds(45), + tests = [ + '', + 0, + -0, + // 0n, + false, + NaN, + null, + undefined, + ], + i; + + for (i = 0; i < tests.length; ++i) { + assert.equal( + moment(a).calendar(tests[i]), + 'Today at 1:23 PM', + 'should equate' + ); + } +});