You are here

final class DatexPoorMansGregorianCalendar in Datex 8

Hierarchy

Expanded class hierarchy of DatexPoorMansGregorianCalendar

1 file declares its use of DatexPoorMansGregorianCalendar
datex.module in ./datex.module

File

src/Datex/DatexPoorMansGregorianCalendar.php, line 10
Fallback calendar implementation in case php-intl is not available.

Namespace

Drupal\datex\Datex
View source
final class DatexPoorMansGregorianCalendar extends DatexPartialImplementation implements DatexInterface {
  public function __construct($tz, $lang_code) {
    $lang_code = $lang_code !== 'fa' && $lang_code !== 'en' ? 'en' : $lang_code;
    parent::__construct($tz, 'gregorian', $lang_code);
  }
  public function format($format) {
    return date_format(parent::getOrigin(), $format);
  }
  public function setDateLocale($y = 1, $m = 1, $d = 1) {
    $this
      ->xSetDate($y, $m, $d);
    return $this;
  }
  public function copy() {
    return new DatexPoorMansGregorianCalendar($this->timezone, $this->langCode);
  }
  public function validate(array $arr) {
    if ((!isset($arr['year']) || empty($arr['year'])) && (!isset($arr['month']) || empty($arr['month'])) && (!isset($arr['day']) || empty($arr['day']))) {
      return NULL;
    }
    $zero = TRUE;
    $year = intval($arr['year']);
    $month = intval($arr['month']);
    $day = intval($arr['day']);
    if ($year < 0 || $year === 0 && $zero) {
      return t('Year out of range');
    }
    if ($month < 0 || 12 < $month || $month === 0 && $zero) {
      return t('Month out of range');
    }
    if ($day === 0 && $zero || $day < 0 || 31 < $day) {
      return t('Day out of range');
    }
    return FALSE;
  }
  public function parse($value, $format) {
    $dt = \DateTime::createFromFormat($format, $value);
    if (!$dt) {
      return FALSE;
    }
    $this
      ->setTimestamp($dt
      ->getTimestamp());
    return TRUE;
  }
  function getBaseYear() {
    return 2018;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatexPartialImplementation::$calendar protected property
DatexPartialImplementation::$langCode protected property
DatexPartialImplementation::$origin protected property
DatexPartialImplementation::$timezone protected property
DatexPartialImplementation::formatArray final function Overrides DatexInterface::formatArray
DatexPartialImplementation::getCalendarName final function Overrides DatexInterface::getCalendarName
DatexPartialImplementation::getLangcode function Overrides DatexInterface::getLangcode
DatexPartialImplementation::getOrigin protected function
DatexPartialImplementation::getTimestamp final function Overrides DatexInterface::getTimestamp
DatexPartialImplementation::listOptions function Overrides DatexInterface::listOptions
DatexPartialImplementation::setTime final function Overrides DatexInterface::setTime
DatexPartialImplementation::setTimestamp final function Overrides DatexInterface::setTimestamp
DatexPartialImplementation::tz final protected function
DatexPartialImplementation::xFormat final function Format date time, in gregorian. Overrides DatexInterface::xFormat
DatexPartialImplementation::xFormatArray final function Put all day and time parts in an array, in gregorian. Overrides DatexInterface::xFormatArray
DatexPartialImplementation::xSetDate final function Overrides DatexInterface::xSetDate
DatexPoorMansGregorianCalendar::copy public function Overrides DatexInterface::copy
DatexPoorMansGregorianCalendar::format public function Overrides DatexInterface::format
DatexPoorMansGregorianCalendar::getBaseYear function Overrides DatexPartialImplementation::getBaseYear
DatexPoorMansGregorianCalendar::parse public function Overrides DatexInterface::parse
DatexPoorMansGregorianCalendar::setDateLocale public function Overrides DatexInterface::setDateLocale
DatexPoorMansGregorianCalendar::validate public function Overrides DatexPartialImplementation::validate
DatexPoorMansGregorianCalendar::__construct public function Overrides DatexPartialImplementation::__construct