From: Iskren Chernev Date: Mon, 22 Apr 2013 09:35:50 +0000 (-0700) Subject: Added weekday and isoWeekday with format tokens e/E X-Git-Tag: 2.1.0~28^2~3^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5299947409b64003fcab8e59279a42628658e672;p=thirdparty%2Fmoment.git Added weekday and isoWeekday with format tokens e/E --- diff --git a/moment.js b/moment.js index c3e2857a0..76f8e9321 100644 --- 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 @@ -148,6 +148,12 @@ 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); }, @@ -1349,17 +1355,12 @@ 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)); }, @@ -1369,6 +1370,23 @@ 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.