Converts a year in Western format into Japanese format.

@param $year
@param int $yearType : era name output format (kanji, kana, romaji)
@param int $numeralType : the numeral type used
@return string The Japanese year.
@throws Exception
183098
public static function toJapaneseYear($year, $yearType = self::YEAR_KANJI, $numeralType = null)
    {
        if ($year < self::$mapEras[0]['year']) {
            throw new Exception('The year ' . $year . ' is before any of the known Japanese eras. The first era started in ' . self::$mapEras[0]['year'] . '.');
        }
        $max = count(self::$mapEras);
        $era = self::$mapEras[$max - 1];
        for ($i = 1; $i < $max; $i++) {
            $currentEra = self::$mapEras[$i];
            $startYear = $currentEra['year'];
            if ($startYear > $year) {
                $era = self::$mapEras[$i - 1];
                break;
            }
        }
        $eraValue = $year - $era['year'] + 1;
        if ($numeralType !== null) {
            $eraValue = self::toJapaneseNumeral($eraValue, $numeralType);
        }
        switch ($yearType) {
            case self::YEAR_KANJI:
                $eraName = $era['kanji'];
                $eraValue .= '年';
                break;
            case self::YEAR_ROMAJI:
                $eraName = $era['romaji'] . ' ';
                break;
            case self::YEAR_KANA:
                $eraName = $era['kana'];
                $eraValue .= 'ねん';
                break;
            default:
                throw new Exception('Unknown year type');
        }
        return $eraName . $eraValue;
    }
1222518
private function getDatesByYearMonthAndPeriodType($dates)
    {
        $result = array();
        foreach ($dates as $date) {
            $yearMonth = ArchiveTableCreator::getTableMonthFromDate($date);
            $result[$yearMonth][null][] = $date->toString();

            // since we're removing all periods, we must make sure to remove year periods as well.
            // this means we have to make sure the january table is processed.
            $janYearMonth = $date->toString('Y') . '_01';
            $result[$janYearMonth][null][] = $date->toString();
        }
        return $result;
    }
846447
public function withYear(int $year): DateTime
    {
        return new static(
            Date::create($year, $this->month(), $this->day()),
            $this->time(),
            $this->timezone()
        );
    }
647079
public function getHolidaysByYear($year)
    {
        $easter = $this->getEasterDates($year);

        return array(
            '01-01' => $this->createData('1. nyttårsdag'),
            '05-01' => $this->createData('1. mai'),
            '05-17' => $this->createData('Grunnlovsdagen'),
            '12-25' => $this->createData('1. juledag'),
            '12-26' => $this->createData('2. juledag'),
            // Variable dates
			$easter['maundyThursday']->format(self::DATE_FORMAT)  => $this->createData('Skjærtorsdag'),
            $easter['goodFriday']->format(self::DATE_FORMAT)      => $this->createData('Langfredag'),
            $easter['easterSunday']->format(self::DATE_FORMAT)    => $this->createData('1. påskedag'),
            $easter['easterMonday']->format(self::DATE_FORMAT)    => $this->createData('2. påskedag'),
            $easter['ascensionDay']->format(self::DATE_FORMAT)    => $this->createData('Kristi Himmelfartsdag'),
            $easter['pentecostMonday']->format(self::DATE_FORMAT) => $this->createData('2. pinsedag'),
		);
    }
230529
protected function extractYear(string $year): int
    {
        if (preg_match('/^(\d\d\d\d)\/\d{1,4}$/', $year, $match)) {
            // Assume the first year is correct
            $this->new_old_style = true;

            return (int) $match[1] + 1;
        }

        if (preg_match('/^(\d+) B\.C\.$/', $year, $match)) {
            return - (int) $match[1];
        }

        return (int) $year;
    }
579301
public function centuryName(int $century): string
    {
        if ($century < 0) {
            return I18N::translate('%s BCE', $this->centuryName(-$century));
        }

        // The current chart engine (Google charts) can't handle <sup></sup> markup
        switch ($century) {
            case 21:
                return strip_tags(I18N::translateContext('CENTURY', '21st'));
            case 20:
                return strip_tags(I18N::translateContext('CENTURY', '20th'));
            case 19:
                return strip_tags(I18N::translateContext('CENTURY', '19th'));
            case 18:
                return strip_tags(I18N::translateContext('CENTURY', '18th'));
            case 17:
                return strip_tags(I18N::translateContext('CENTURY', '17th'));
            case 16:
                return strip_tags(I18N::translateContext('CENTURY', '16th'));
            case 15:
                return strip_tags(I18N::translateContext('CENTURY', '15th'));
            case 14:
                return strip_tags(I18N::translateContext('CENTURY', '14th'));
            case 13:
                return strip_tags(I18N::translateContext('CENTURY', '13th'));
            case 12:
                return strip_tags(I18N::translateContext('CENTURY', '12th'));
            case 11:
                return strip_tags(I18N::translateContext('CENTURY', '11th'));
            case 10:
                return strip_tags(I18N::translateContext('CENTURY', '10th'));
            case 9:
                return strip_tags(I18N::translateContext('CENTURY', '9th'));
            case 8:
                return strip_tags(I18N::translateContext('CENTURY', '8th'));
            case 7:
                return strip_tags(I18N::translateContext('CENTURY', '7th'));
            case 6:
                return strip_tags(I18N::translateContext('CENTURY', '6th'));
            case 5:
                return strip_tags(I18N::translateContext('CENTURY', '5th'));
            case 4:
                return strip_tags(I18N::translateContext('CENTURY', '4th'));
            case 3:
                return strip_tags(I18N::translateContext('CENTURY', '3rd'));
            case 2:
                return strip_tags(I18N::translateContext('CENTURY', '2nd'));
            case 1:
                return strip_tags(I18N::translateContext('CENTURY', '1st'));
            default:
                return ($century - 1) . '01-' . $century . '00';
        }
    }
1313610
public function getDateFormat($includeYear = TRUE, $includeDate = TRUE) {
        $returnVar = $this->getCurrentFormat();
        if(!$includeYear) {
            if(preg_match('@^Y@', $returnVar)) {
                $returnVar = substr($returnVar, 2); //If it starts with the year
            } elseif(preg_match('@Y$@', $returnVar)) {
                $returnVar = substr($returnVar, 0, -2); //If ends with the year
            } else {
                $returnVar = preg_replace('@Y.@', '', $returnVar); //If in middle if year
            }
        }
        if(!$includeDate) {
            if(preg_match('@^d@', $returnVar)) {
                $returnVar = substr($returnVar, 2); //If it starts with the year
            } elseif(preg_match('@d$@', $returnVar)) {
                $returnVar = substr($returnVar, 0, -2); //If ends with the year
            } else {
                $returnVar = preg_replace('@d.@', '', $returnVar); //If in middle if year
            }
        }
        return $returnVar;
    }
1200088
private function yearType($year)
    {
        $year_length = $this->yToJd($year + 1) - $this->yToJd($year);

        if ($year_length === 353 || $year_length === 383) {
            return self::DEFECTIVE_YEAR;
        } elseif ($year_length === 355 || $year_length === 385) {
            return self::COMPLETE_YEAR;
        } else {
            return self::REGULAR_YEAR;
        }
    }
1147796
public function ymdToJd($year, $month, $day)
    {
        return
            $this->yToJd($year) +
            self::$CUMULATIVE_DAYS[$this->isLeapYear($year)][$this->yearType($year)][$month] +
            $day - 1;
    }
15963
private static function validateYear($year)
	    {
	        $year = filter_var($year, FILTER_VALIDATE_INT);
	        if (false === $year) {
	            throw new InvalidArgumentException("A Year must be a valid int");
	        }

	        return $year;
	    }
1347112
protected function formatGedcomYear(): string
    {
        if ($this->year < 0) {
            return sprintf('%04d B.C.', -$this->year);
        }

        if ($this->new_old_style) {
            return sprintf('%04d/%02d', $this->year - 1, $this->year % 100);
        }

        return sprintf('%04d', $this->year);
    }
896147
public function years($years)
    {
        return sprintf($this->formatPattern, $years, $this->year_words[$this->pluralization($years)]);
    }
1351803
public function archiveYearlyAction($year, Request $request = null)
    {
        $action = $this->container->get(YearlyPostArchiveAction::class);

        return $action($this->resolveRequest($request), $year);
    }
1115329
public NumberExpression<Integer> year() {
        if (year == null) {
            year = Expressions.numberOperation(Integer.class, Ops.DateTimeOps.YEAR, mixin);
        }
        return year;
    }
747334
public function getYear()
  {
    if (strlen($this->date) >= 4) {
      $year = substr($this->date, 0, 4);
      $year = str_replace('?', '', $year);

      return ($year ? (int) $year : null);
    }

    return null;
  }
541608
public static function getFirstOfYear($year='')
    {
        if ($year == '')
        {
            $currentTime = time();
            $year = date('Y', $currentTime);
        }
        
        $timestamp = mktime(0, 0, 0, $month=1, $day=1, $year);
        
        return $timestamp;
    }
1297282
public static function vin($year = 1980)
    {
        $modelYear = static::modelYear($year);
        $regex = "([a-hj-npr-z0-9]{8})_{$modelYear}([a-hj-npr-z0-9]{7})";
        $vin = static::regexify($regex);
        return str_replace('_', self::checkDigit($vin), $vin);
    }