]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Issue no. 3658 adding overload for single parameter to calendar function
authorjoseph janiga <josephjaniga@gmail.com>
Sat, 17 Dec 2016 00:32:03 +0000 (19:32 -0500)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 2 Mar 2017 09:16:03 +0000 (11:16 +0200)
Corrected the formatting on calendarjs unit test file

Corrected autoformatting

src/lib/moment/calendar.js
src/test/moment/calendar.js

index 4b5725c58b0c17010d99f893995b4f067e80e467..1e4264a2e14cf425c4cefdc04d21ae8e3cea8483 100644 (file)
@@ -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(),
index 36af6848fa7ca2c1689eabaa73aaf021cdd73f0c..cb0e4a17fb57f88a63218f42aec189739faa7447 100644 (file)
@@ -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');
+
+});