From: joseph janiga Date: Sat, 17 Dec 2016 00:32:03 +0000 (-0500) Subject: Issue no. 3658 adding overload for single parameter to calendar function X-Git-Tag: 2.18.0~39^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48dac46ca1eeddee546d19d8116a6427a7e28045;p=thirdparty%2Fmoment.git Issue no. 3658 adding overload for single parameter to calendar function Corrected the formatting on calendarjs unit test file Corrected autoformatting --- diff --git a/src/lib/moment/calendar.js b/src/lib/moment/calendar.js index 4b5725c58..1e4264a2e 100644 --- a/src/lib/moment/calendar.js +++ b/src/lib/moment/calendar.js @@ -1,3 +1,4 @@ +import { isMoment } from './constructor'; import { createLocal } from '../create/local'; import { cloneWithOffset } from '../units/offset'; import isFunction from '../utils/is-function'; @@ -14,6 +15,12 @@ export function getCalendarFormat(myMoment, now) { } export function calendar (time, formats) { + // #3658 - Adding overload to the calendar function in order to allow: + // calendar(FORMATS) a single parameter, formats only function call + if (arguments.length === 1 && typeof time === 'object' && !isMoment(time)) { + formats = arguments[0]; + time = undefined; + } // We want to compare the start of today, vs this. // Getting start-of-today depends on whether we're local/utc/offset or not. var now = time || createLocal(), diff --git a/src/test/moment/calendar.js b/src/test/moment/calendar.js index 36af6848f..cb0e4a17f 100644 --- a/src/test/moment/calendar.js +++ b/src/test/moment/calendar.js @@ -55,3 +55,13 @@ test('extending calendar options', function (assert) { moment.updateLocale('en', null); } }); + +test('calendar overload - passing one parameter formats', function (assert) { + var a = moment().hours(13).minutes(23).seconds(45); + assert.equal(moment(a).calendar({ + 'sameDay': function () { + return 'h:mm:ssA'; + } + }), '1:23:45PM', 'should equate'); + +});