/*[deutsch]
Erzeugt eine {@code CalendarPeriod} f&uuml;r die angegebene Jahresspanne.

@param   y1  first calendar year
@param   y2  last calendar year (inclusive)
@return  CalendarPeriod
506490
public static CalendarPeriod<CalendarYear> between(
        CalendarYear y1,
        CalendarYear y2
    ) {

        return new FixedCalendarPeriod<>(y1, y2, FixedCalendarTimeLine.forYears());

    }
891942
public static Date substractMonthsFromDate(final Date date, final int substractMonths)
	{
		final Calendar dateOnCalendar = Calendar.getInstance();
		dateOnCalendar.setTime(date);
		dateOnCalendar.add(Calendar.MONTH, substractMonths * -1);
		return dateOnCalendar.getTime();
	}
935134
public static int getMonthFromDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.MONTH) + 1;
	}
661640
@Override
    public Date firstBetween(Date start, Date end)
    {
        return doFirstBetween(start, end);
    }
182469
public static long subDays(final Date date1, final Date date2) {

    return subTime(date1, date2, DatePeriod.DAY);
  }
576209
function d2j(jdn) {
    var gy = d2g(jdn).gy // Calculate Gregorian year (gy).
        , jy = gy - 621
        , r = jalCal(jy)
        , jdn1f = g2d(gy, 3, r.march)
        , jd
        , jm
        , k;

    // Find number of days that passed since 1 Farvardin.
    k = jdn - jdn1f;
    if (k >= 0) {
        if (k <= 185) {
            // The first 6 months.
            jm = 1 + div(k, 31);
            jd = mod(k, 31) + 1;
            return  { jy: jy
                , jm: jm
                , jd: jd
            };
        } else {
            // The remaining months.
            k -= 186;
        }
    } else {
        // Previous Jalali year.
        jy -= 1;
        k += 179;
        if (r.leap === 1)
            k += 1;
    }
    jm = 7 + div(k, 30);
    jd = mod(k, 30) + 1;
    return  { jy: jy
        , jm: jm
        , jd: jd
    };
}
1067524
public static boolean isSameWeek(final Date date1, final Date date2) {
        final Calendar cal1 = Calendar.getInstance();
        cal1.setFirstDayOfWeek(Calendar.MONDAY);
        cal1.setTime(date1);

        final Calendar cal2 = Calendar.getInstance();
        cal2.setFirstDayOfWeek(Calendar.MONDAY);
        cal2.setTime(date2);

        return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
                && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
                && cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR);
    }
1101664
public CalendarPeriod GetCalendarPeriod()
	{
		CalendarPeriod res = new CalendarPeriod();
		List<Period> periods = new ArrayList<Period>();
		for( int i = 0; i < this.periods.size(); i++ )
		{
			PeriodAssociative<T> p = this.periods.get( i );
			periods.add( new Period( p.getFrom(), p.getTo() ) );
		}
		// use merge to merge jointed periods...
		res.setPeriods( res._Merge( periods ) );

		return res;
	}
991424
public CalendarWeek minus(Years<Weekcycle> years) {

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

        int y = MathUtils.safeSubtract(this.year, years.getAmount());
        int effectiveWeek = this.week;

        if ((this.week == 53) && (maximumOfWeek(y) < 53)) {
            effectiveWeek = 52;
        }

        return CalendarWeek.of(y, effectiveWeek);

    }
1060435
public function twiceMonthly($first = 1, $second = 16)
    {
        $days = $first.','.$second;

        return $this->spliceIntoPosition(1, 0)
            ->spliceIntoPosition(2, 0)
            ->spliceIntoPosition(3, $days);
    }
968179
public static Date addMonth(Date date1, int addMonth) {
        Date resultDate = null;
        Calendar c = Calendar.getInstance();
        c.setTime(date1); // 设置当前日期
        c.add(Calendar.MONTH, addMonth); // 日期加1
        resultDate = c.getTime(); // 结果
        return resultDate;
    }
806143
public static long subYears(final Date date1, final Date date2) {

    return Math.abs(getYear(date1) - getYear(date2));
  }
459779
public static long subMonths(final Date date1, final Date date2) {

    Calendar calendar1 = buildCalendar(date1);
    int monthOfDate1 = calendar1.get(Calendar.MONTH);
    int yearOfDate1 = calendar1.get(Calendar.YEAR);
    Calendar calendar2 = buildCalendar(date2);
    int monthOfDate2 = calendar2.get(Calendar.MONTH);
    int yearOfDate2 = calendar2.get(Calendar.YEAR);
    int subMonth = Math.abs(monthOfDate1 - monthOfDate2);
    int subYear = Math.abs(yearOfDate1 - yearOfDate2);
    return subYear * 12 + subMonth;
  }
1223220
function (date1, date2) {
                return date1.getHours() === date2.getHours() &&
                    date1.getMinutes() === date2.getMinutes();
            }
941945
public static Date getDate(int year, int month, int day) {
        GregorianCalendar d = new GregorianCalendar(year, month - 1, day);
        return d.getTime();
    }
1206179
public static boolean isPeriodActive(final Date startDate, final Date endDate) {
		if (startDate == null && endDate == null) {
			return true;
		}
		if (startDate == null) {
			throw new JKException("START_DATE_CAN_NOT_BE_NULL");
		}
		if (endDate == null) {
			throw new JKException("END_DATE_CAN_NOT_BE_NULL");
		}
		if (compareTwoDates(startDate, endDate).equals(CompareDates.DATE1_GREATER_THAN_DATE2)) {
			throw new JKException("START_DATE_MUST_BE_BEFORE_END_DATE");
		}
		final boolean startLessThanCurrent = compareTwoDates(startDate, getSystemDate()).equals(CompareDates.DATE1_LESS_THAN_DATE2);
		final boolean endGreaterThanCurrent = compareTwoDates(endDate, getSystemDate()).equals(CompareDates.DATE1_GREATER_THAN_DATE2);
		return startLessThanCurrent && endGreaterThanCurrent;
	}
1173753
public CalendarMonth plus(Years<CalendarUnit> years) {

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

        return CalendarMonth.of(MathUtils.safeAdd(this.year, years.getAmount()), this.month);

    }