From: Tim Wood Date: Tue, 6 Nov 2012 21:45:26 +0000 (-0800) Subject: Passing isoWeek tests X-Git-Tag: 2.0.0~35^2~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a39bf29073c2afdbcf1d42b4f6e9116f36bfbf14;p=thirdparty%2Fmoment.git Passing isoWeek tests --- diff --git a/moment.js b/moment.js index 87123e3f6..9f706a5ce 100644 --- a/moment.js +++ b/moment.js @@ -847,6 +847,24 @@ } + /************************************ + Week of Year + ************************************/ + + + function weekOfYear(mom, firstDayOfWeek, firstDayOfYear) { + var start = mom.clone().date(1).month(0), + dayOfYear = mom.diff(start, 'days') + 1, + week = dayOfYear - (firstDayOfWeek + mom.day()) + start.day(); + + if (start.day() <= firstDayOfYear) { + week += 7; + } + + return week / 7 || 53; + } + + /************************************ Top Level Functions ************************************/ @@ -1164,6 +1182,10 @@ return moment.utc([this.year(), this.month() + 1, 0]).date(); }, + isoWeek : function () { + return weekOfYear(this, 1, 4); + }, + // If passed a language key, it will set the language for this // instance. Otherwise, it will return the language configuration // variables for this instance.