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])) {
'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'
+ );
+ }
+});