]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Added support for isFuture argument for the relativeTime and thus to translations
authorTarmo Aidantausta <bleadof@holvi.com>
Fri, 23 Mar 2012 11:38:49 +0000 (13:38 +0200)
committerTarmo Aidantausta <bleadof@holvi.com>
Fri, 23 Mar 2012 11:38:49 +0000 (13:38 +0200)
moment.js

index 5392e30a636e6aeca8c3757e5ce77c5656feeebc..537d9b5d9a9ba229d5a15a6f216c221988c84fdd 100644 (file)
--- a/moment.js
+++ b/moment.js
     }
 
     // helper function for _date.from() and _date.fromNow()
-    function substituteTimeAgo(string, number, withoutSuffix) {
+    function substituteTimeAgo(string, number, withoutSuffix, isFuture) {
         var rt = moment.relativeTime[string];
         return (typeof rt === 'function') ?
-            rt(number || 1, !!withoutSuffix, string) :
+            rt(number || 1, !!withoutSuffix, string, isFuture) :
             rt.replace(/%d/i, number || 1);
     }
 
-    function relativeTime(milliseconds, withoutSuffix) {
+    function relativeTime(milliseconds, withoutSuffix, isFuture) {
         var seconds = round(Math.abs(milliseconds) / 1000),
             minutes = round(seconds / 60),
             hours = round(minutes / 60),
                 days < 345 && ['MM', round(days / 30)] ||
                 years === 1 && ['y'] || ['yy', years];
         args[2] = withoutSuffix;
+        args[3] = isFuture;
         return substituteTimeAgo.apply({}, args);
     }
 
             withSuffix = !!type;
             break;
         }
-        output = relativeTime(difference, !withSuffix);
-        return withSuffix ? (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output) : output;
+        var isFuture = difference <= 0 ? false : true;
+        output = relativeTime(difference, !withSuffix, isFuture);
+        return withSuffix ? (!isFuture ? rel.past : rel.future).replace(/%s/i, output) : output;
     };
 
     // version number
         },
 
         isDST : function () {
-            return (this.zone() < moment([this.year()]).zone() || 
+            return (this.zone() < moment([this.year()]).zone() ||
                 this.zone() < moment([this.year(), 5]).zone());
         },