From: Pierre Spring Date: Tue, 13 Dec 2011 08:25:35 +0000 (+0100) Subject: adds the possibility to return a function as a relativeDate format X-Git-Tag: 1.3.0~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3ba62f6adefd961047a8eef09b499b7d282d296;p=thirdparty%2Fmoment.git adds the possibility to return a function as a relativeDate format --- diff --git a/moment.js b/moment.js index 9d313ae1d..f635a5f53 100644 --- a/moment.js +++ b/moment.js @@ -539,7 +539,8 @@ relativeDate : function () { var format = 'YYYY DDDD', unixTimestamp = this.valueOf(), - arrayKey, nextWeek, lastWeek; + arrayKey, nextWeek, lastWeek, + relativeDateFormat; switch (this.format(format)) { case moment().format(format): @@ -566,8 +567,13 @@ } } - if (arrayKey) { - return moment.relativeDate[arrayKey].replace('%weekday', this.format('dddd')).replace('%time', this.format('LT')); + if (arrayKey && moment.relativeDate[arrayKey]) { + relativeDateFormat = moment.relativeDate[arrayKey]; + + if ('function' === typeof relativeDateFormat) { + relativeDateFormat = relativeDateFormat.call(this); + } + return relativeDateFormat.replace('%weekday', this.format('dddd')).replace('%time', this.format('LT')); } return this.format(moment.relativeDate.else || 'L');