public/javascripts/yui/calendar/calendar.js
function(date, firstDayOfWeek, janDate) {

        // Setup Defaults
        firstDayOfWeek = firstDayOfWeek || 0;
        janDate = janDate || this.WEEK_ONE_JAN_DATE;

        var targetDate = this.clearTime(date),
            startOfWeek,
            endOfWeek;

        if (targetDate.getDay() === firstDayOfWeek) { 
            startOfWeek = targetDate;
        } else {
            startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek);
        }

        var startYear = startOfWeek.getFullYear();

        // DST shouldn't be a problem here, math is quicker than setDate();
        endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS);

        var weekNum;
        if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) {
            // If years don't match, endOfWeek is in Jan. and if the 
            // week has WEEK_ONE_JAN_DATE in it, it's week one by definition.
            weekNum = 1;
        } else {
            // Get the 1st day of the 1st week, and 
            // find how many days away we are from it.
            var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)),
                weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek);

            // Round days to smoothen out 1 hr DST diff
            var daysDiff  = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS);

            // Calc. Full Weeks
            var rem = daysDiff % 7;
            var weeksDiff = (daysDiff - rem)/7;
            weekNum = weeksDiff + 1;
        }
        return weekNum;
    }
function(date, firstDayOfWeek, janDate) {

        // Setup Defaults
        firstDayOfWeek = firstDayOfWeek || 0;
        janDate = janDate || this.WEEK_ONE_JAN_DATE;

        var targetDate = this.clearTime(date),
            startOfWeek,
            endOfWeek;

        if (targetDate.getDay() === firstDayOfWeek) { 
            startOfWeek = targetDate;
        } else {
            startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek);
        }

        var startYear = startOfWeek.getFullYear();

        // DST shouldn't be a problem here, math is quicker than setDate();
        endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS);

        var weekNum;
        if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) {
            // If years don't match, endOfWeek is in Jan. and if the 
            // week has WEEK_ONE_JAN_DATE in it, it's week one by definition.
            weekNum = 1;
        } else {
            // Get the 1st day of the 1st week, and 
            // find how many days away we are from it.
            var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)),
                weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek);

            // Round days to smoothen out 1 hr DST diff
            var daysDiff  = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS);

            // Calc. Full Weeks
            var rem = daysDiff % 7;
            var weeksDiff = (daysDiff - rem)/7;
            weekNum = weeksDiff + 1;
        }
        return weekNum;
    }
function ( date , firstDayOfWeek , janDate ) { // Setup Defaults firstDayOfWeek = firstDayOfWeek || 0 ; janDate = janDate || this . WEEK_ONE_JAN_DATE ; var targetDate = this . clearTime ( date ) , startOfWeek , endOfWeek ; if ( targetDate . getDay ( ) === firstDayOfWeek ) { startOfWeek = targetDate ; } else { startOfWeek = this . getFirstDayOfWeek ( targetDate , firstDayOfWeek ) ; } var startYear = startOfWeek . getFullYear ( ) ; // DST shouldn't be a problem here, math is quicker than setDate(); endOfWeek = new Date ( startOfWeek . getTime ( ) + 6 * this . ONE_DAY_MS ) ; var weekNum ; if ( startYear !== endOfWeek . getFullYear ( ) && endOfWeek . getDate ( ) >= janDate ) { // If years don't match, endOfWeek is in Jan. and if the  // week has WEEK_ONE_JAN_DATE in it, it's week one by definition. weekNum = 1 ; } else { // Get the 1st day of the 1st week, and  // find how many days away we are from it. var weekOne = this . clearTime ( this . getDate ( startYear , 0 , janDate ) ) , weekOneDayOne = this . getFirstDayOfWeek ( weekOne , firstDayOfWeek ) ; // Round days to smoothen out 1 hr DST diff var daysDiff = Math . round ( ( targetDate . getTime ( ) - weekOneDayOne . getTime ( ) ) / this . ONE_DAY_MS ) ; // Calc. Full Weeks var rem = daysDiff % 7 ; var weeksDiff = ( daysDiff - rem ) / 7 ; weekNum = weeksDiff + 1 ; } return weekNum ; }
Calculates the week number for the given date. Can currently support standard
U.S. week numbers, based on Jan 1st defining the 1st week of the year, and
ISO8601 week numbers, based on Jan 4th defining the 1st week of the year.

@method getWeekNumber
@param {Date} date The JavaScript date for which to find the week number
@param {Number} firstDayOfWeek The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat).
Defaults to 0
@param {Number} janDate The date in the first week of January which defines week one for the year
Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st).
For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year.

@return {Number} The number of the week containing the given date.
Calculates the week number for the given date . Can currently support standard U . S . week numbers based on Jan 1st defining the 1st week of the year and ISO8601 week numbers based on Jan 4th defining the 1st week of the year .