From: generalov Date: Tue, 26 Apr 2016 14:46:42 +0000 (+0500) Subject: Call calendar format function with moment context X-Git-Tag: 2.14.0~30^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2c17e02b53b3bda932d969ccf41ba8fb9588c31;p=thirdparty%2Fmoment.git Call calendar format function with moment context 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 --- diff --git a/src/lib/moment/calendar.js b/src/lib/moment/calendar.js index bc5092ca8..4f4a9a72f 100644 --- a/src/lib/moment/calendar.js +++ b/src/lib/moment/calendar.js @@ -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))); }