]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
adds the possibility to return a function as a relativeDate format
authorPierre Spring <pierre@nelm.io>
Tue, 13 Dec 2011 08:25:35 +0000 (09:25 +0100)
committerPierre Spring <pierre@nelm.io>
Tue, 13 Dec 2011 08:25:35 +0000 (09:25 +0100)
moment.js

index 9d313ae1df2626da1d9cb0b99fe5accfe1301a01..f635a5f533660832d6730d2e8e8594bea8973af8 100644 (file)
--- a/moment.js
+++ b/moment.js
         relativeDate : function () {
             var format = 'YYYY DDDD',
                 unixTimestamp = this.valueOf(),
-                arrayKey, nextWeek, lastWeek;
+                arrayKey, nextWeek, lastWeek,
+                relativeDateFormat;
 
             switch (this.format(format)) {
             case moment().format(format):
                 }
             }
 
-            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');