Get the number of Sundaystarting-weeks in this year
163793
def _ssweek_num_weeks(ssweek_year):
    ""
    year_start = _ssweek_year_start(ssweek_year)
    next_year_start = _ssweek_year_start(ssweek_year+1)
    year_num_weeks = ((next_year_start - year_start).days) // 7
    return year_num_weeks
94881
def get_easter_saturday(self, year):
        ""
        sunday = self.get_easter_sunday(year)
        return sunday - timedelta(days=1)
1332688
function (year) {
			var daysCount = 0;
			for (var i = 1; i <= 12; i++) {
				daysCount += this.daysInMonth(year, i);
			}
			return daysCount;
		}
587555
def get(self, prefix, year, week):
        """"""
        filename = self._format_filename(prefix, year, week)
        return RawEvents(filename, prefix, year, week)
353652
function () {
        // days between midweek of this week and jan 4
        // (f.z() - f.N() + 1 + 3.5) - 3
        var midWeekDaysFromJan4 = f.z() - f.N() + 1.5;
        // 1 + number of weeks + rounded week
        return humanize.pad(1 + Math.floor(Math.abs(midWeekDaysFromJan4) / 7) + (midWeekDaysFromJan4 % 7 > 3.5 ? 1 : 0), 2, '0');
      }
61478
def locale_first_weekday():
    """"""
    first_weekday = 6 #by default settle on monday

    try:
        process = os.popen("locale first_weekday week-1stday")
        week_offset, week_start = process.read().split('\n')[:2]
        process.close()
        week_start = dt.date(*time.strptime(week_start, "%Y%m%d")[:3])
        week_offset = dt.timedelta(int(week_offset) - 1)
        beginning = week_start + week_offset
        first_weekday = int(beginning.strftime("%w"))
    except:
        logger.warn("WARNING - Failed to get first weekday from locale")

    return first_weekday
605859
public static Weeks between(CalendarWeek w1, CalendarWeek w2) {

        PlainDate d1 = w1.at(Weekday.MONDAY);
        PlainDate d2 = w2.at(Weekday.MONDAY);
        return Weeks.between(d1, d2);

    }
1330501
def weeks_per_year(year):
    ''''''
    # 53 weeks: any year starting on Thursday and any leap year starting on Wednesday
    jan1 = jwday(gregorian.to_jd(year, 1, 1))

    if jan1 == THU or (jan1 == WED and isleap(year)):
        return 53
    else:
        return 52
1065808
function (d, range) {
		"use strict";

		var weekStart;

		if (this.options.weekStartOnMonday === false) {
			weekStart = new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay());
		} else {
			if (d.getDay() === 1) {
				weekStart = new Date(d.getFullYear(), d.getMonth(), d.getDate());
			} else if (d.getDay() === 0) {
				weekStart = new Date(d.getFullYear(), d.getMonth(), d.getDate());
				weekStart.setDate(weekStart.getDate() - 6);
			} else {
				weekStart = new Date(d.getFullYear(), d.getMonth(), d.getDate()-d.getDay()+1);
			}
		}

		var endDate = new Date(weekStart);

		var stop = range;
		if (typeof range !== "object") {
			stop = new Date(endDate.setDate(endDate.getDate() + range * 7));
		}

		return (this.options.weekStartOnMonday === true) ?
			d3.time.mondays(Math.min(weekStart, stop), Math.max(weekStart, stop)):
			d3.time.sundays(Math.min(weekStart, stop), Math.max(weekStart, stop))
		;
	}
714728
def delay_1(year):
    ''''''
    # Sunday, Wednesday, and Friday as start of the new year.
    months = trunc(((235 * year) - 234) / 19)
    parts = 12084 + (13753 * months)
    day = trunc((months * 29) + parts / 25920)

    if ((3 * (day + 1)) % 7) < 3:
        day += 1

    return day
1212246
function nthWeekDay(countDays, weekDay, year, month, day) {
  let countedDays = 0
  if (countDays >= 0) {
    month = month || 1
    let monthStr = String(month)
    if (monthStr.length === 1) { monthStr = "0" + monthStr }
    day = day || 1
    let dayStr = String(day)
    if (dayStr.length === 1) { dayStr = "0" + dayStr }
    // We stay a minute off midnight to avoid dealing with leap seconds.
    let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
    let time
    for (let i = 0; i < 366; i++) {
      time = new Date(timestamp)
      if (time.getDay() === weekDay) {countedDays++}
      if (countedDays === countDays) {break}
      timestamp += 24 * 3600 * 1000
    }
    return time
  } else if (countDays < 0) {
    countDays = -countDays
    month = month || 12
    let monthStr = String(month)
    if (monthStr.length === 1) { monthStr = "0" + monthStr }
    day = day || 31
    let dayStr = String(day)
    if (dayStr.length === 1) { dayStr = "0" + dayStr }
    // Starting moment, ms.
    let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
    let time
    for (let i = 366; i >= 0; i--) {
      time = new Date(timestamp)
      if (time.getDay() === weekDay) {countedDays++}
      if (countedDays === countDays) {break}
      timestamp -= 24 * 3600 * 1000
    }
    return time
  }
}
539524
def W(self):
    ""
    # Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
    week_number = None
    jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
    weekday = self.data.weekday() + 1
    day_of_year = self.z()
    if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
      if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year-1)):
        week_number = 53
      else:
        week_number = 52
    else:
      if calendar.isleap(self.data.year):
        i = 366
      else:
        i = 365
      if (i - day_of_year) < (4 - weekday):
        week_number = 1
      else:
        j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
        week_number = j // 7
        if jan1_weekday > 4:
          week_number -= 1
    return week_number
711118
function yearWeek (y, yd) {
    const dow = isoDow(y, 1, 1);
    const start = dow > 4 ? 9 - dow : 2 - dow;
    if ((Math.abs(yd - start) % 7) !== 0) {
        // y yd is not the start of any week
        return [];
    }
    if (yd < start) {
        // The week starts before the first week of the year => go back one year
        yd += Math.round((Date.UTC(y, 0, 1) - Date.UTC(y - 1, 0, 1)) / MS_PER_DAY);
        return yearWeek(y - 1, yd);
    } else if (Date.UTC(y, 0, 1) + (yd - 1 + 3) * MS_PER_DAY >= Date.UTC(y + 1, 0, 1)) {
        // The Wednesday (start of week + 3) lies in the next year => advance one year
        yd -= Math.round((Date.UTC(y + 1, 0, 1) - Date.UTC(y, 0, 1)) / MS_PER_DAY);
        return yearWeek(y + 1, yd);
    }
    return [y, 1 + Math.round((yd - start) / 7)];
}
35306
private static int getWeekIndex(final Calendar cal) {
        final int val = cal.get(Calendar.DAY_OF_WEEK);
        switch(val) {
            case Calendar.SUNDAY:
                return 0;
            case Calendar.MONDAY:
                return 1;
            case Calendar.TUESDAY:
                return 2;
            case Calendar.WEDNESDAY:
                return 3;
            case Calendar.THURSDAY:
                return 4;
            case Calendar.FRIDAY:
                return 5;
            case Calendar.SATURDAY:
                return 6;
        }

        return 0;
    }
739817
Counter getWeekCounter() {
		final Counter weekCounter = createPeriodCounter("yyyyWW", currentDayCounter.getStartDate());
		addRequestsAndErrorsForRange(weekCounter, Period.SEMAINE.getRange());
		return weekCounter;
	}
433127
def week_number(date):
    
    week_number = date.strftime('%W')
    if int(week_number) < 10:
        week_number = week_number[-1]
    return week_number
1345904
def _ssweek_info(ssweek_year, ssweek_week):
    ""
    prev_year_start = _ssweek_year_start(ssweek_year-1)
    year_start = _ssweek_year_start(ssweek_year)
    next_year_start = _ssweek_year_start(ssweek_year+1)
    first_day = year_start + dt.timedelta(weeks=ssweek_week-1)
    last_day = first_day + dt.timedelta(days=6)
    prev_year_num_weeks = ((year_start - prev_year_start).days) // 7
    year_num_weeks = ((next_year_start - year_start).days) // 7
    return (first_day, last_day, prev_year_num_weeks, year_num_weeks)