/* Define one-century window into which to disambiguate dates using
two-digit years.
321411
private void parseAmbiguousDatesAsAfter(Date startDate) {
        defaultCenturyStart = startDate;
        calendar.setTime(startDate);
        defaultCenturyStartYear = calendar.get(Calendar.YEAR);
    }
1143014
protected static int yearFrom2Digits(int shortYear, int currentYear) {
        if (shortYear < 100) {
            shortYear += currentYear - (currentYear % 100);
            if (Math.abs(shortYear - currentYear) >= 50) {
                if (shortYear < currentYear) {
                    return shortYear + 100;
                } else {
                    return shortYear - 100;
                }
            }
        }
        return shortYear;
    }
936744
def date_this_century(self, before_today=True, after_today=False):
        
        today = date.today()
        this_century_start = date(today.year - (today.year % 100), 1, 1)
        next_century_start = date(this_century_start.year + 100, 1, 1)

        if before_today and after_today:
            return self.date_between_dates(
                this_century_start, next_century_start)
        elif not before_today and after_today:
            return self.date_between_dates(today, next_century_start)
        elif not after_today and before_today:
            return self.date_between_dates(this_century_start, today)
        else:
            return today
410596
def _year_expand(s):
        
        regex = r"^((?:19|20)\d{2})?(\s*-\s*)?((?:19|20)\d{2})?$"
        try:
            start, dash, end = match(regex, ustr(s)).groups()
            start = start or 1900
            end = end or 2099
        except AttributeError:
            return 1900, 2099
        return (int(start), int(end)) if dash else (int(start), int(start))
303589
def datetime2yeardoy(time: Union[str, datetime.datetime]) -> Tuple[int, float]:
    
    T = np.atleast_1d(time)

    utsec = np.empty_like(T, float)
    yd = np.empty_like(T, int)
    for i, t in enumerate(T):
        if isinstance(t, np.datetime64):
            t = t.astype(datetime.datetime)
        elif isinstance(t, str):
            t = parse(t)

        utsec[i] = datetime2utsec(t)
        yd[i] = t.year*1000 + int(t.strftime('%j'))

    return yd.squeeze()[()], utsec.squeeze()[()]
77333
@SuppressWarnings("unchecked")
    @Override
    public ChronoDateImpl<D> plus(long amountToAdd, TemporalUnit unit) {
        if (unit instanceof ChronoUnit) {
            ChronoUnit f = (ChronoUnit) unit;
            switch (f) {
                case DAYS: return plusDays(amountToAdd);
                case WEEKS: return plusDays(Jdk8Methods.safeMultiply(amountToAdd, 7));
                case MONTHS: return plusMonths(amountToAdd);
                case YEARS: return plusYears(amountToAdd);
                case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
                case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
                case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
//                case ERAS: throw new DateTimeException("Unable to add era, standard calendar system only has one era");
//                case FOREVER: return (period == 0 ? this : (period > 0 ? LocalDate.MAX_DATE : LocalDate.MIN_DATE));
            }
            throw new DateTimeException(unit + " not valid for chronology " + getChronology().getId());
        }
        return (ChronoDateImpl<D>) getChronology().ensureChronoLocalDate(unit.addTo(this, amountToAdd));
    }
751556
public static function getFullYear($year)
    {
        is_string($year) && ($year = (int)$year);
        if ($year < 100) {
            $yr = (int)date("Y");
            $century = (int)($yr / 100);
            if ($yr % 100 > 50) {
                $c1 = $century + 1;
                $c0 = $century;
            } else {
                $c1 = $century;
                $c0 = $century - 1;
            }
            $c1 *= 100;
            // if 2-digit year is less than 30 years in future, set it to this century
            // otherwise if more than 30 years in future, then we set 2-digit year to the prev century.
            if (($year + $c1) < $yr + 30) {
                $year = $year + $c1;
            } else {
                $year = $year + $c0 * 100;
            }
        }
        return $year;
    }
659515
function startOfYear() {
      var result = this.clone();
      result.day = 1;
      result.month = 1;
      result.isDate = true;
      result.hour = 0;
      result.minute = 0;
      result.second = 0;
      return result;
    }
867143
def delay_2(year):
    ''''''

    last = delay_1(year - 1)
    present = delay_1(year)
    next_ = delay_1(year + 1)

    if next_ - present == 356:
        return 2
    elif present - last == 382:
        return 1
    else:
        return 0
475717
def decyear2dt(t):
    
    year = int(t)
    rem = t - year 
    base = datetime(year, 1, 1)
    dt = base + timedelta(seconds=(base.replace(year=base.year+1) - base).total_seconds() * rem)
    #This works for np array input
    #year = t.astype(int)
    #rem = t - year 
    #base = np.array([datetime(y, 1, 1) for y in year])
    return dt
82699
private long newYearOnOrBefore(long utcDays) {
        long ny = this.newYearInSui(utcDays);
        if (utcDays >= ny) {
            return ny;
        } else {
            return this.newYearInSui(utcDays - 180); // previous sui
        }
    }
1322351
long calculateFirstDayOfYearMillis(int year) {
        if (year > MAX_YEAR) {
            throw new ArithmeticException("Year is too large: " + year + " > " + MAX_YEAR);
        }
        if (year < MIN_YEAR) {
            throw new ArithmeticException("Year is too small: " + year + " < " + MIN_YEAR);
        }

        // Java epoch is 1970-01-01 Gregorian which is 0622-07-16 Islamic.
        // 0001-01-01 Islamic is -42520809600000L
        // would prefer to calculate against year zero, but leap year
        // can be in that year so it doesn't work
        year--;
        long cycle = year / CYCLE;
        long millis = MILLIS_YEAR_1 + cycle * MILLIS_PER_CYCLE;
        int cycleRemainder = (year % CYCLE) + 1;
        
        for (int i = 1; i < cycleRemainder; i++) {
            millis += (isLeapYear(i) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR);
        }
        
        return millis;
    }
1052726
function getDayOfYear (date, year) {
  date = toStringDate(date)
  if (baseExports.isDate(date)) {
    return baseExports.isLeapYear(getWhatYear(date, year)) ? 366 : 365
  }
  return date
}
1099822
function toGregorian(oBuddhist) {
		var iEraStartYear = UniversalDate.getEraStartDate(CalendarType.Buddhist, 0).year,
			iYear = oBuddhist.year + iEraStartYear - 1;
		// Before 1941 new year started on 1st of April
		if (iYear < 1941 && oBuddhist.month < 3) {
			iYear += 1;
		}
		if (oBuddhist.year === null) {
			iYear = undefined;
		}
		return {
			year: iYear,
			month: oBuddhist.month,
			day: oBuddhist.day
		};
	}
345216
static long transform(
        int relgregyear,
        int dayOfYear
    ) {

        if (relgregyear >= 1873) {
            return PlainDate.of(relgregyear, dayOfYear).getDaysSinceEpochUTC();
        } else {
            return START_OF_YEAR[relgregyear - 701] + dayOfYear - 1;
        }

    }
200549
def y2k(year: int) -> int:
    ''''''
    assert 0 <= year <= 99, 'Not a two digit year {}'.format(year)
    return year + 1000 if year >= 69 else year + 2000
474601
public static int dayOfYear(int year, int month, int date) {
        int leapAdjust = month > 2 && isLeapYear(year) ? 1 : 0;
        return MONTH_START_TO_DOY[month - 1] + leapAdjust + date - 1;
    }