]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
introduces the relativeDate
authorPierre Spring <pierre@nelm.io>
Fri, 2 Dec 2011 00:37:03 +0000 (01:37 +0100)
committerPierre Spring <pierre@nelm.io>
Fri, 2 Dec 2011 00:37:03 +0000 (01:37 +0100)
moment.js

index f5954b742e613fccdf601e04aec15f6739712a77..cd27161f2f58eecc1f5c93d2ed6579d712e4d78a 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -11,7 +11,7 @@
         round = Math.round,
         languages = {},
         hasModule = (typeof module !== 'undefined'),
-        paramsToParse = 'months|monthsShort|weekdays|weekdaysShort|longDateFormat|relativeTime|ordinal|meridiem'.split('|'),
+        paramsToParse = 'months|monthsShort|weekdays|weekdaysShort|longDateFormat|relativeDate|relativeTime|ordinal|meridiem'.split('|'),
         i,
         VERSION = "1.1.2",
         shortcuts = 'Month|Date|Hours|Minutes|Seconds'.split('|');
             PM : 'PM',
             pm : 'pm'
         },
+        relativeDate : {
+            today: 'Today at %time',
+            tomorrow: 'Tomorrow at %time',
+            next: 'next %weekday at %time', // e.g. next Friday
+            yesterday: 'Yesterday at %time',
+            last: 'last %weekday at %time' // e.g. last Sunday
+        },
         relativeTime : {
             future : "in %s",
             past : "%s ago",
             return this.from(moment(), withoutSuffix);
         },
 
+        xxx : function () {
+            var format = 'YYYY DDDD',
+                unixTimestamp = this.valueOf(),
+                yyy, nextWeek, lastWeek;
+
+            switch (this.format(format)) {
+            case moment().format(format):
+                yyy = 'today';
+                break;
+            case moment().add('days', 1).format(format):
+                yyy = 'tomorrow';
+                break;
+            case moment().subtract('days', 1).format(format):
+                yyy = 'yesterday';
+                break;
+            }
+
+            if ('undefined' === typeof yyy) {
+                nextWeek = moment().add('weeks', 1).hours(23).minutes(59).seconds(59);
+                lastWeek = moment().subtract('weeks', 1).hours(0).minutes(0).seconds(0);
+
+                if (nextWeek.valueOf() > unixTimestamp && lastWeek.valueOf() < unixTimestamp) {
+                    if (moment().valueOf() < unixTimestamp) {
+                        yyy = 'next';
+                    } else {
+                        yyy = 'last';
+                    }
+                }
+            }
+
+            if (yyy) {
+                return moment.relativeDate[yyy].replace('%weekday', this.format('dddd')).replace('%time', this.format('HH:MM'));
+            }
+
+            return this.format('L');
+        },
+
         isLeapYear : function () {
             var year = this.year();
             return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;