]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Added weekday and isoWeekday with format tokens e/E
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 22 Apr 2013 09:35:50 +0000 (02:35 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 24 Apr 2013 09:11:54 +0000 (02:11 -0700)
moment.js

index c3e2857a04b6e5ef3dccc7afd901cdf06d4c95cf..76f8e9321e3ecbe065ef3a3c59c16f89b86da6ec 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -24,7 +24,7 @@
         aspNetTimeSpanJsonRegex = /(\-)?(\d*)?\.?(\d+)\:(\d+)\:(\d+)\.?(\d{3})?/,
 
         // format tokens
-        formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,
+        formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,
         localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
 
         // parsing tokens
             GGGGG : function () {
                 return leftZeroFill(this.isoWeekYear(), 5);
             },
+            e : function () {
+                return this.weekday();
+            },
+            E : function () {
+                return this.isoWeekday();
+            },
             a    : function () {
                 return this.lang().meridiem(this.hours(), this.minutes(), true);
             },
             return input == null ? dayOfYear : this.add("d", (input - dayOfYear));
         },
 
-        isoWeek : function (input) {
-            var week = weekOfYear(this, 1, 4).week;
-            return input == null ? week : this.add("d", (input - week) * 7);
-        },
-
-        weekYear: function(input) {
+        weekYear : function(input) {
             var year = weekOfYear(this, this.lang()._week.dow, this.lang()._week.doy).year;
             return input == null ? year : this.add("y", (input - year));
         },
 
-        isoWeekYear: function (input) {
+        isoWeekYear : function (input) {
             var year = weekOfYear(this, 1, 4).year;
             return input == null ? year : this.add("y", (input - year));
         },
             return input == null ? week : this.add("d", (input - week) * 7);
         },
 
+        isoWeek : function (input) {
+            var week = weekOfYear(this, 1, 4).week;
+            return input == null ? week : this.add("d", (input - week) * 7);
+        },
+
+        weekday : function(input) {
+            var weekday = (this._d.getDay() + 7 - this.lang()._week.dow) % 7;
+            return input == null ? weekday : this.add("d", input - weekday);
+        },
+
+        isoWeekday : function(input) {
+            // iso weeks start on monday, which is 1, so we subtract 1 (and add
+            // 7 for negative mod to work).
+            var weekday = (this._d.getDay() + 6) % 7;
+            return input == null ? weekday : this.add("d", input - weekday);
+        },
+
         // If passed a language key, it will set the language for this
         // instance.  Otherwise, it will return the language configuration
         // variables for this instance.