/*[deutsch]
<p>Subtrahiert die angegebenen Wochen von dieser Kalenderwoche. </p>

@param   weeks       the count of weeks to be subtracted
@return  result of subtraction
11705
public CalendarWeek minus(Weeks weeks) {

        if (weeks.isEmpty()) {
            return this;
        }

        PlainDate date = this.start.getTemporal().minus(weeks.getAmount(), CalendarUnit.WEEKS);
        int y = date.getInt(YEAR_OF_WEEKDATE);
        int w = date.getInt(WEEK_OF_YEAR);
        return CalendarWeek.of(y, w);

    }
253529
public final Dur add(final Dur duration) {
        if ((!isNegative() && duration.isNegative())
                || (isNegative() && !duration.isNegative())) {

            throw new IllegalArgumentException(
                    "Cannot add a negative and a positive duration");
        }

        Dur sum;
        if (weeks > 0 && duration.weeks > 0) {
            sum = new Dur(weeks + duration.weeks);
        }
        else {
            int daySum = (weeks > 0) ? weeks * DAYS_PER_WEEK + days : days;
            int hourSum = hours;
            int minuteSum = minutes;
            int secondSum = seconds;

            if ((secondSum + duration.seconds) / SECONDS_PER_MINUTE > 0) {
                minuteSum += (secondSum + duration.seconds) / SECONDS_PER_MINUTE;
                secondSum = (secondSum + duration.seconds) % SECONDS_PER_MINUTE;
            }
            else {
                secondSum += duration.seconds;
            }

            if ((minuteSum + duration.minutes) / MINUTES_PER_HOUR > 0) {
                hourSum += (minuteSum + duration.minutes) / MINUTES_PER_HOUR;
                minuteSum = (minuteSum + duration.minutes) % MINUTES_PER_HOUR;
            }
            else {
                minuteSum += duration.minutes;
            }

            if ((hourSum + duration.hours) / HOURS_PER_DAY > 0) {
                daySum += (hourSum + duration.hours) / HOURS_PER_DAY;
                hourSum = (hourSum + duration.hours) % HOURS_PER_DAY;
            }
            else {
                hourSum += duration.hours;
            }

            daySum += (duration.weeks > 0) ? duration.weeks * DAYS_PER_WEEK
                    + duration.days : duration.days;

            sum = new Dur(daySum, hourSum, minuteSum, secondSum);
        }
        sum.negative = negative;
        return sum;
    }
1193418
def to_s
      @to_s ||= begin
        wks = @weeks.map { |w|
          w.map { |d|
            if d.nil?
              '  '
            elsif d.day < 10
              " #{d.day}"
            else
              "#{d.day}"
            end
          }.join(' ')
        }.join("\n")
        "Su Mo Tu We Th Fr Sa\n#{wks}\n"
      end
    end
839045
public final void setWeekOfMonth(WeekOfMonth weekOfMonth) {

        SortedSet<WeekOfMonth> woms = new TreeSet<>();
        if (null != weekOfMonth) {
            woms.add(weekOfMonth);
        }
        setWeeksOfMonth(woms);
    }
1057652
public static int dayOfWeek(){
		setTime();
		int dayofweek = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (dayofweek == 0) {
			dayofweek = 7;
		}
		return dayofweek;
	}
1183781
public static int getDayOfWeekInMonth(int year, int month, int dayOfMonth) {
        int weekInMonth = (dayOfMonth + 6)/7;
        if (weekInMonth == 4) {
            if (dayOfMonth + 7 > monthLength(year, month)) {
                weekInMonth = -1;
            }
        } else if (weekInMonth == 5) {
            weekInMonth = -1;
        }
        return weekInMonth;
    }
594071
def weeks_of_year(cls, year):
        """"""
        w = cls(year, 1)
        while w.year == year:
            yield w
            w += 1
881157
public static Date getEndOfWeek(Date date) {

        if (date == null)
            return null;

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);

        return calendar.getTime();
    }
116730
function week(date) {
  var d = new Date(+date);
  var y, w;

  d.setHours(0, 0, 0);
  d.setDate(d.getDate() + 4 - (d.getDay()||7));

  y = new Date(d.getFullYear(), 0, 1);
  w = Math.ceil((((d - y) / DAY_M) + 1) / 7);
  return d.getFullYear() + '-W' + zeroFill(w);
}
916123
function getWeekNumber(date) {
  date = this.toDate(date);
  var week = this._startWeek;
  return date ? getWeekNumberFn(date, week, this.startMonth): null;
}
1021003
public static Date substractDaysFromDate(final Date date, final int substractDays)
	{
		final Calendar dateOnCalendar = Calendar.getInstance();
		dateOnCalendar.setTime(date);
		dateOnCalendar.add(Calendar.DATE, substractDays * -1);
		return dateOnCalendar.getTime();
	}
75517
public static <D extends Comparable> DateExpression<D> addWeeks(DateExpression<D> date, int weeks) {
        return Expressions.dateOperation(date.getType(), Ops.DateTimeOps.ADD_WEEKS, date, ConstantImpl.create(weeks));
    }
1218338
static Predicate<DateValue> byDayFilter(
            final WeekdayNum[] days, final boolean weeksInYear, final Weekday wkst) {
        return new Predicate<DateValue>() {
            public boolean apply(DateValue date) {
                Weekday dow = Weekday.valueOf(date);

                int nDays;
                // first day of the week in the given year or month
                Weekday dow0;
                // where does date appear in the year or month?
                // in [0, lengthOfMonthOrYear - 1]
                int instance;
                if (weeksInYear) {
                    nDays = TimeUtils.yearLength(date.year());
                    dow0 = Weekday.firstDayOfWeekInMonth(date.year(), 1);
                    instance = TimeUtils.dayOfYear(
                            date.year(), date.month(), date.day());
                } else {
                    nDays = TimeUtils.monthLength(date.year(), date.month());
                    dow0 = Weekday.firstDayOfWeekInMonth(date.year(), date.month());
                    instance = date.day() - 1;
                }

                // which week of the year or month does this date fall on?
                // one-indexed
                int dateWeekNo;
                if (wkst.javaDayNum <= dow.javaDayNum) {
                    dateWeekNo = 1 + (instance / 7);
                } else {
                    dateWeekNo = (instance / 7);
                }

                // TODO(msamuel): according to section 4.3.10
                //     Week number one of the calendar year is the first week which
                //     contains at least four (4) days in that calendar year. This
                //     rule part is only valid for YEARLY rules.
                // That's mentioned under the BYWEEKNO rule, and there's no mention
                // of it in the earlier discussion of the BYDAY rule.
                // Does it apply to yearly week numbers calculated for BYDAY rules in
                // a FREQ=YEARLY rule?

                for (int i = days.length; --i >= 0; ) {
                    WeekdayNum day = days[i];

                    if (day.wday == dow) {
                        int weekNo = day.num;
                        if (0 == weekNo) {
                            return true;
                        }

                        if (weekNo < 0) {
                            weekNo = Util.invertWeekdayNum(day, dow0, nDays);
                        }

                        if (dateWeekNo == weekNo) {
                            return true;
                        }
                    }
                }
                return false;
            }
        };
    }
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
1157830
public static int getCalendarDay(final WeekDay weekday) {
        int calendarDay = -1;
        if (SU.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.SUNDAY;
        }
        else if (MO.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.MONDAY;
        }
        else if (TU.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.TUESDAY;
        }
        else if (WE.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.WEDNESDAY;
        }
        else if (TH.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.THURSDAY;
        }
        else if (FR.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.FRIDAY;
        }
        else if (SA.getDay().equals(weekday.getDay())) {
            calendarDay = Calendar.SATURDAY;
        }
        return calendarDay;
    }
103480
public final Dur negate() {
        final Dur negated = new Dur(days, hours, minutes, seconds);
        negated.weeks = weeks;
        negated.negative = !negative;
        return negated;
    }
679727
public static WeekFields of(Locale locale) {
        Objects.requireNonNull(locale, "locale");
        // Android-changed: get Week data from ICU4J
        ULocale ulocale = ULocale.forLocale(locale);
        String region = ULocale.getRegionForSupplementalData(ulocale, /* inferRegion */ true);
        Calendar.WeekData weekData = Calendar.getWeekDataForRegion(region);
        DayOfWeek dow = DayOfWeek.SUNDAY.plus(weekData.firstDayOfWeek - 1);
        return WeekFields.of(dow, weekData.minimalDaysInFirstWeek);
    }