We calculate the number of days between :week_start (inclusive) and :week_end (inclusive)
 DAYS_INTO_WEEK = { monday: 0, tuesday: 1, wednesday: 2, thursday: 3, friday: 4, saturday: 5, sunday: 6 }
774417
def number_of_days_per_week
        ws = Date::DAYS_INTO_WEEK[@options[:week_start]]
        we = Date::DAYS_INTO_WEEK[@options[:week_end]]
        we += 7 if we <= ws
        we - ws + 1
      end
861959
def dates_in_range(start_date, end_date):
    
    return [
        start_date + timedelta(n)
        for n in range(int((end_date - start_date).days))
    ]
647443
def find_following_working_day(self, day):
        
        day = cleaned_date(day)

        while day.weekday() in self.get_weekend_days():
            day = day + timedelta(days=1)
        return day
962923
def n_weekends(self) -> int:
        
        startdate = self.start.date()
        enddate = self.end.date()
        ndays = (enddate - startdate).days + 1
        in_weekend = False
        n_weekends = 0
        for i in range(ndays):
            date = startdate + datetime.timedelta(days=i)
            if not in_weekend and is_weekend(date):
                in_weekend = True
                n_weekends += 1
            elif in_weekend and not is_weekend(date):
                in_weekend = False
        return n_weekends
1053452
def next_weekday_in(weekday_abbreviation, direction, count, distance)
      count = direction.downcase == 'b' ? -count.to_i : count.to_i
      weekday = WEEKDAYS[weekday_abbreviation.downcase]

      case distance.downcase
      when "d"
      when "w"
        (@now + count * 7) + weekday[0] - @now.wday  
      when "m"
        future = @now >> count
        future + weekday[0] - future.wday
      when "y"
        future = @now >> count * 12
        future + weekday[0] - future.wday
      end
    end
634415
def prev_weekday(weekday):
    """"""
    ix = WEEKDAYS.index(weekday)
    if ix == 0:
        return WEEKDAYS[len(WEEKDAYS)-1]
    return WEEKDAYS[ix-1]
655738
def days_range(first=None, second=None, wipe=False):
    
    _first, _second = parse(first), parse(second)
    (_start, _end) = (_second, _first) if _first > _second else (_first, _second)
    days_between = (_end - _start).days
    date_list = [_end - datetime.timedelta(days=x) for x in range(0, days_between + 1)]
    if wipe and len(date_list) >= 2:
        date_list = date_list[1:-1]
    return date_list
520770
def previous_weekday(date):
    '''
    
    '''
    weekday = date.weekday()
    if weekday == 0:
        n_days = 3
    elif weekday == 6:
        n_days = 2
    else:
        n_days = 1
    return date - datetime.timedelta(days=n_days)
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;
	}
1104864
def next_monday(dt):
    
    if dt.weekday() == 5:
        return dt + timedelta(2)
    elif dt.weekday() == 6:
        return dt + timedelta(1)
    return dt
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)];
}
660126
function(d) {
		"use strict";

		if (this.options.weekStartOnMonday === false) {
			return d.getDay();
		}
		return d.getDay() === 0 ? 6 : (d.getDay()-1);
	}
872674
def working_tomorrow(self, date_from=None, date_format=None):
		
		# date de demain que sur les jours de week-end
		return self.delta(days=1, date_from=date_from, date_format=date_format, days_range=[1, 2, 3, 4, 5, 6])
898011
def row_to_day(i, j)
        starting_wday = @day_start.wday - 1
        starting_wday = 6 if starting_wday < 0

        # day without taking into account the :week_start so every 1st
        # of the month is on a :monday on case [0, 0]
        base = (i * 7) + j

        # we add the :week_start
        base += Date::DAYS_INTO_WEEK[@options[:week_start]]

        # we adjust with the starting day of the month
        base -= starting_wday
        base += 1

        return nil if base < 1 || base > days_in_month(@day_start)

        base
      end
367584
def working_cycletime(start, end, workday_start=datetime.timedelta(hours=0), workday_end=datetime.timedelta(hours=24)):
    
    def clamp(t, start, end):
        "Return 't' clamped to the range ['start', 'end']"
        return max(start, min(end, t))

    def day_part(t):
        "Return timedelta between midnight and 't'."
        return t - t.replace(hour=0, minute=0, second=0)

    if not start:
        return None
    if not end:
        end = datetime.datetime.now()

    zero = datetime.timedelta(0)
    # Make sure that the work day is valid
    assert(zero <= workday_start <= workday_end <= datetime.timedelta(1))
    # Get the workday delta
    workday = workday_end - workday_start
    # Get the number of days it took
    days = (end - start).days + 1
    # Number of weeks
    weeks = days // 7
    # Get the number of days in addition to weeks
    extra = (max(0, 5 - start.weekday()) + min(5, 1 + end.weekday())) % 5
    # Get the number of working days
    weekdays = weeks * 5 + extra
    # Get the total time spent accounting for the workday
    total = workday * weekdays
    if start.weekday() < 5:
        # Figuring out how much time it wasn't being worked on and subtracting
        total -= clamp(day_part(start) - workday_start, zero, workday)
    if end.weekday() < 5:
        # Figuring out how much time it wasn't being worked on and subtracting
        total -= clamp(workday_end - day_part(end), zero, workday)

    cycle_time = timedelta_total_seconds(total) / timedelta_total_seconds(workday)
    return cycle_time
1140111
function calculateDatePos(startDayOfMonth, day) {
	const start = startDayOfMonth - 1;
	day = day - 1;
	const weekDayIndex = (start + day) % WEEKDAYS;
	const weekIndex = Math.ceil((start + day + 1) / WEEKDAYS) - 1;
	return {
		weekIndex,
		weekDayIndex
	};
}
67893
def weekdays(self):
        
        if self.itemStyle() == self.ItemStyle.Group:
            out = 0
            for i in range(self.childCount()):
                out += self.child(i).weekdays()
            return out
        else:
            dstart = self.dateStart().toPyDate()
            dend   = self.dateEnd().toPyDate()
            
            return projex.dates.weekdays(dstart, dend)