]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Call calendar format function with moment context
authorgeneralov <e.generalov@gmail.com>
Tue, 26 Apr 2016 14:46:42 +0000 (19:46 +0500)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 14 Jun 2016 09:07:31 +0000 (02:07 -0700)
What: the code:
```
moment().days(-1000).calendar(null, {
   sameElse: function() {
       return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT';
   }
});
```
Where: on http://momentjs.com/docs/#/displaying/calendar-time/ in the Chrome console.
What I got: It raises `Uncaught TypeError: this.hours is not a function`

I expected use callback like in the example on http://momentjs.com/docs/#/customization/calendar/ .

This PR makes the compatible call with https://github.com/moment/moment/blob/develop/src/lib/locale/calendar.js#L14

src/lib/moment/calendar.js

index bc5092ca88ed9780b5f6bd661f36596311efaa6b..4f4a9a72ff1f1b769a79e419e4158ab6bdac2edd 100644 (file)
@@ -15,7 +15,7 @@ export function calendar (time, formats) {
             diff < 2 ? 'nextDay' :
             diff < 7 ? 'nextWeek' : 'sameElse';
 
-    var output = formats && (isFunction(formats[format]) ? formats[format]() : formats[format]);
+    var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
 
     return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
 }