firstDayOfWeek       0 = sun, 6 = sat the day of the week that starts the week (usually sunday or monday) firstDayOfWeekOfYear 0 = sun, 6 = sat the first week is the week that contains the first of this day of the week (eg. ISO weeks use thursday (4))
543022
function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
        var end = firstDayOfWeekOfYear - firstDayOfWeek,
            daysToDayOfWeek = firstDayOfWeekOfYear - mom.day();


        if (daysToDayOfWeek > end) {
            daysToDayOfWeek -= 7;
        }

        if (daysToDayOfWeek < end - 7) {
            daysToDayOfWeek += 7;
        }

        return Math.ceil(moment(mom).add('d', daysToDayOfWeek).dayOfYear() / 7);
    }
198779
def _ssweek_year_start(ssweek_year):
    ""
    fifth_jan = dt.date(ssweek_year, 1, 5)
    delta = dt.timedelta(fifth_jan.weekday()+1)
    return fifth_jan - delta
1183555
function weekNumber(d, firstWeekday) {
		firstWeekday = firstWeekday || 'sunday';
		// This works by shifting the weekday back by one day if we
		// are treating Monday as the first day of the week.
		var wday = d.getDay();
		if (firstWeekday == 'monday') {
			if (wday == 0) // Sunday
				wday = 6;
			else
				wday--;
		}
		var firstDayOfYear = new Date(d.getFullYear(), 0, 1)
			, yday = (d - firstDayOfYear) / 86400000
			, weekNum = (yday + 7 - wday) / 7
			;
		//    return Math.floor(weekNum);
		return weekNum | 0;
	}
683242
public static Date getFirstDayOfLastWeek(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime() - 604800000L);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        Date lastWeekDate = c.getTime();

        c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        c.setTime(new Date(lastWeekDate.getTime()));
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday
        return c.getTime();
    }
953728
public static Date toDateDayOfWeek(int dayOfWeek)
   {
	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
	
	return cal.getTime();
   }
126854
public static int getWeek(Date date) {
        CALENDAR.setTime(date);
        return CALENDAR.get(Calendar.DAY_OF_WEEK);
    }
514933
def workdays(first_day=None):
    
    if first_day is None:
        first_day = 'Monday'
    ix = _lower_weekdays().index(first_day.lower())
    return _double_weekdays()[ix:ix+5]
1169114
public static int getDayOfWeek(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_WEEK);
    }
673797
public Weekday getDayOfWeek() {

        long utcDays = CALSYS.transform(this);
        return Weekday.valueOf(MathUtils.floorModulo(utcDays + 5, 7) + 1);

    }
634415
def prev_weekday(weekday):
    """"""
    ix = WEEKDAYS.index(weekday)
    if ix == 0:
        return WEEKDAYS[len(WEEKDAYS)-1]
    return WEEKDAYS[ix-1]
892057
public Weekday getDayOfWeek() {

        long utcDays = getCalendarSystem(this.variant).transform(this);
        return Weekday.valueOf(MathUtils.floorModulo(utcDays + 5, 7) + 1);

    }
638023
def _ssweek_of_month(date_value):
    ""
    weekday_of_first = (date_value.replace(day=1).weekday() + 1) % 7
    return (date_value.day + weekday_of_first - 1) // 7
274604
public static function firstWeekOfYear($year = null)
    {
        $year = $year ? (int) $year : Date('Y');
        return Carbon::parse($year . '-01-01')->startOfWeek(Carbon::SUNDAY);
    }
786047
function getWeeks (date) {

                    var weeks = [];
                    var date = moment.utc(date);
                    var firstDayOfMonth = moment(date).date(1);
                    var lastDayOfMonth  = moment(date).date(date.daysInMonth());

                    var startDay = moment(firstDayOfMonth);
                    var endDay   = moment(lastDayOfMonth);
                    // NB: We use weekday() to get a locale aware weekday
                    startDay = firstDayOfMonth.weekday() === 0 ? startDay : startDay.weekday(0);
                    endDay   = lastDayOfMonth.weekday()  === 6 ? endDay   : endDay.weekday(6);

                    var currentWeek = [];

                    for (var start = moment(startDay); start.isBefore(moment(endDay).add(1, 'days')); start.add(1, 'days')) {

                        var afterMinDate  = !scope.config.minDate || start.isAfter(scope.config.minDate, 'day');
                        var beforeMaxDate = !scope.config.maxDate || start.isBefore(scope.config.maxDate, 'day');
                        var isFuture      = start.isAfter(today);
                        var beforeFuture  = scope.config.allowFuture || !isFuture;

                        var day = {
                            date: moment(start).toDate(),
                            isToday: start.isSame(today, 'day'),
                            isInMonth: start.isSame(firstDayOfMonth, 'month'),
                            isSelected: start.isSame(dateSelected, 'day'),
                            isSelectable: afterMinDate && beforeMaxDate && beforeFuture
                        };

                        currentWeek.push(day);

                        if (start.weekday() === 6 || start === endDay) {
                            weeks.push(currentWeek);
                            currentWeek = [];
                        }
                    }

                    return weeks;
                }
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
  }
}
505281
def weekdays(first_day=None):
    
    if first_day is None:
        first_day = 'Monday'
    ix = _lower_weekdays().index(first_day.lower())
    return _double_weekdays()[ix:ix+7]
891209
public function getFirstLetter()
    {
        switch ($this->day_of_week_number)
        {
            case self::MON: return 'M';
            case self::TUE: return 'T';
            case self::WED: return 'W';
            case self::THU: return 'T';
            case self::FRI: return 'F';
            case self::SAT: return 'S';
            case self::SUN: return 'S';
        }
    }