Return the Python week number of a date.
    The django \|date:"W" returns incompatible value
    with the view implementation.
433127
def week_number(date):
    
    week_number = date.strftime('%W')
    if int(week_number) < 10:
        week_number = week_number[-1]
    return week_number
1204904
function setISOWeekNumber(d, num) {
  if (isNumber(num)) {
    // Intentionally avoiding updateDate here to prevent circular dependencies.
    var isoWeek = cloneDate(d), dow = getWeekday(d);
    moveToFirstDayOfWeekYear(isoWeek, ISO_FIRST_DAY_OF_WEEK, ISO_FIRST_DAY_OF_WEEK_YEAR);
    setDate(isoWeek, getDate(isoWeek) + 7 * (num - 1));
    setYear(d, getYear(isoWeek));
    setMonth(d, getMonth(isoWeek));
    setDate(d, getDate(isoWeek));
    setWeekday(d, dow || 7);
  }
  return d.getTime();
}
765924
def week_date(self, start: int = 2017, end: int = 2018) -> str:
        
        year = self.year(start, end)
        week = self.random.randint(1, 52)
        return '{year}-W{week}'.format(
            year=year,
            week=week,
        )
472285
public static int getDayOfWeek(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.DAY_OF_WEEK);
	}
735818
static function num2week($num, $two = true)
    {
        if ($num == '6')
        {
            $num = '日';
        }
        else
        {
            $num = Tool::num2han($num + 1);
        }
        if ($two)
        {
            return self::WEEK_TWO . $num;
        }
        else
        {
            return self::WEEK_THREE . $num;
        }
    }
356181
function getWeekOfMonth(date) {
      var firstDayOfMonth = getFirstDateOfMonth(date);
      return Math.floor((firstDayOfMonth.getDay() + date.getDate() - 1) / 7);
    }
624890
private WeekDay readWeekDay(JSONValue val) throws IllegalArgumentException {

        String str = readOptionalString(val);
        if (null != str) {
            return WeekDay.valueOf(str);
        }
        throw new IllegalArgumentException();
    }
220877
def get_day_name(self) -> str:
        
        weekday = self.value.isoweekday() - 1
        return calendar.day_name[weekday]
640775
def next_weekday(date):
    '''
    
    '''
    n_days = 7 - date.weekday()
    if n_days > 3:
        n_days = 1
    return date + datetime.timedelta(days=n_days)
1095117
def byweekday(self):
        
        retval = []
        if self.rule._byweekday:
            retval += [Weekday(day) for day in self.rule._byweekday]
        if self.rule._bynweekday:
            retval += [Weekday(day, n) for day, n in self.rule._bynweekday]
        return retval
814531
def backdate(res, date=None, as_datetime=False, fmt='%Y-%m-%d'):
    
    if res is None:
        return None

    if date is None:
        date = datetime.datetime.now()
    else:
        try:
            date = parse_date(date)
        except Exception as e:
            pass

    new_date = date

    periods = int("".join([s for s in res if s.isdigit()]))

    if periods > 0:

        if "K" in res:
            new_date = date - datetime.timedelta(microseconds=periods)
        elif "S" in res:
            new_date = date - datetime.timedelta(seconds=periods)
        elif "T" in res:
            new_date = date - datetime.timedelta(minutes=periods)
        elif "H" in res or "V" in res:
            new_date = date - datetime.timedelta(hours=periods)
        elif "W" in res:
            new_date = date - datetime.timedelta(weeks=periods)
        else:  # days
            new_date = date - datetime.timedelta(days=periods)

        # not a week day:
        while new_date.weekday() > 4:  # Mon-Fri are 0-4
            new_date = backdate(res="1D", date=new_date, as_datetime=True)

    if as_datetime:
        return new_date

    return new_date.strftime(fmt)
779052
def previous_friday(dt):
    
    if dt.weekday() == 5:
        return dt - timedelta(1)
    elif dt.weekday() == 6:
        return dt - timedelta(2)
    return dt
865229
public int getWeek()
  {
    int dow4th = (int) ((_dayOfEpoch - _dayOfYear + 3) % 7 + 10) % 7;
    int ww1monday = 3 - dow4th;

    if (_dayOfYear < ww1monday)
      return 53;

    int week = (_dayOfYear - ww1monday) / 7 + 1;

    if (_dayOfYear >= 360) {
      int days = 365 + (_isLeapYear ? 1 : 0);
      long nextNewYear = (_dayOfEpoch - _dayOfYear + days);

      int dowNext4th = (int) ((nextNewYear + 3) % 7 + 10) % 7;
      int nextWw1Monday = 3 - dowNext4th;

      if (days <= _dayOfYear - nextWw1Monday)
        return 1;
    }

    return week;
  }
691276
public static String getXNextWeek(String date, Integer x, Language language) {
		NormalizationManager nm = NormalizationManager.getInstance(language, false);
		String date_no_W = date.replace("W", "");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-w");
		String newDate = "";
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(formatter.parse(date_no_W));
			c.add(Calendar.WEEK_OF_YEAR, x);
			c.getTime();
			newDate = formatter.format(c.getTime());
			newDate = newDate.substring(0,4)+"-W"+nm.getFromNormNumber(newDate.substring(5));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return newDate;
	}
434354
function getWeeks(dates) {
  const weeksLength = Math.ceil(dates.length / 7);
  const weeks = [];
  for (let i = 0; i < weeksLength; i++) {
    weeks[i] = [];
    for (let x = 0; x < 7; x++) {
      weeks[i].push(dates[i * 7 + x]);
    }
  }
  return weeks;
}
38812
def get_object_from_date_based_view(request, *args, **kwargs):  # noqa
    
    import time
    import datetime
    from django.http import Http404
    from django.db.models.fields import DateTimeField
    try:
        from django.utils import timezone
        datetime_now = timezone.now
    except ImportError:
        datetime_now = datetime.datetime.now
    year, month, day = kwargs['year'], kwargs['month'], kwargs['day']
    month_format = kwargs.get('month_format', '%b')
    day_format = kwargs.get('day_format', '%d')
    date_field = kwargs['date_field']
    queryset = kwargs['queryset']
    object_id = kwargs.get('object_id', None)
    slug = kwargs.get('slug', None)
    slug_field = kwargs.get('slug_field', 'slug')

    try:
        tt = time.strptime(
                '%s-%s-%s' % (year, month, day),
                '%s-%s-%s' % ('%Y', month_format, day_format)
            )
        date = datetime.date(*tt[:3])
    except ValueError:
        raise Http404

    model = queryset.model

    if isinstance(model._meta.get_field(date_field), DateTimeField):
        lookup_kwargs = {
                '%s__range' % date_field: (
                    datetime.datetime.combine(date, datetime.time.min),
                    datetime.datetime.combine(date, datetime.time.max),
                )}
    else:
        lookup_kwargs = {date_field: date}

    now = datetime_now()
    if date >= now.date() and not kwargs.get('allow_future', False):
        lookup_kwargs['%s__lte' % date_field] = now
    if object_id:
        lookup_kwargs['pk'] = object_id
    elif slug and slug_field:
        lookup_kwargs['%s__exact' % slug_field] = slug
    else:
        raise AttributeError(
                "Generic detail view must be called with either an "
                "object_id or a slug/slug_field."
            )
    return get_object_or_404(queryset, **lookup_kwargs)
186066
def date(self) -> Optional[DateHeader]:
        """"""
        try:
            return cast(DateHeader, self[b'date'][0])
        except (KeyError, IndexError):
            return None