You are here

abstract class DatexPartialImplementation in Datex 8

Hierarchy

Expanded class hierarchy of DatexPartialImplementation

File

src/Datex/DatexPartialImplementation.php, line 5

Namespace

Drupal\datex\Datex
View source
abstract class DatexPartialImplementation implements DatexInterface {
  protected $origin;
  protected $timezone;
  protected $calendar;
  protected $langCode;
  function __construct($tz, $calendar, $lang_code) {
    $this->timezone = $tz;
    $this->origin = new \DateTime('now', $this->timezone);
    $this->calendar = $calendar;
    $this->langCode = $lang_code;
  }
  final function getCalendarName() {
    return $this->calendar;
  }
  function listOptions($name, $required) {
    $none = [
      '' => '',
    ];
    $year = $this
      ->getBaseYear();
    switch ($name) {
      case 'monthNames':
        $m = [];
        for ($i = 1; $i < 13; $i++) {
          $this
            ->setDateLocale($year, $i, 1);
          $m[$i] = $this
            ->format('F');
        }
        return !$required ? $none + $m : $m;
      case 'monthNamesAbbr':
        $m = [];
        for ($i = 1; $i < 13; $i++) {
          $this
            ->setDateLocale($year, $i, 1);
          $m[$i] = $this
            ->format('M');
        }
        return !$required ? $none + $m : $m;
    }
    return $none;
  }
  abstract function getBaseYear();
  function getLangcode() {
    return $this->langCode;
  }
  protected function getOrigin() {
    return $this->origin;
  }

  // ------------------------------------ FORMAT

  /**
   * Format date time, in gregorian.
   *
   * @param $format
   *
   * @return string
   */
  final function xFormat($format) {
    return $this->origin
      ->format($format);
  }

  /**
   * Put all day and time parts in an array, in gregorian.
   *
   * @return array
   */
  final function xFormatArray() {
    return [
      'year' => intval($this->origin
        ->format('Y')),
      'month' => intval($this->origin
        ->format('n')),
      'day' => intval($this->origin
        ->format('j')),
      'hour' => intval($this->origin
        ->format('G')),
      'minute' => intval($this->origin
        ->format('i')),
      'second' => intval($this->origin
        ->format('s')),
    ];
  }
  final function xSetDate($y, $m, $d) {
    $this->origin
      ->setDate($y, $m, $d);
    return $this;
  }
  final function setTimestamp($timestamp) {
    $this->origin
      ->setTimestamp($timestamp);
    return $this;
  }
  final function getTimestamp() {
    return $this->origin
      ->getTimestamp();
  }
  function validate(array $arr) {
    return NULL;
  }
  final function setTime($hour, $minute, $second) {
    $this->origin
      ->setTime($hour, $minute, $second);
    return $this;
  }
  final function formatArray() {
    return [
      'year' => $this
        ->format('Y'),
      'month' => $this
        ->format('n'),
      'day' => $this
        ->format('j'),
      'hour' => $this
        ->format('G'),
      'minute' => $this
        ->format('i'),
      'second' => $this
        ->format('s'),
    ];
  }
  protected final function tz($tz) {
    $this->origin = new \DateTime('@' . $this->origin
      ->getTimestamp(), $tz);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatexInterface::copy function 3
DatexInterface::format function 3
DatexInterface::parse function 3
DatexInterface::setDateLocale function 3
DatexPartialImplementation::$calendar protected property
DatexPartialImplementation::$langCode protected property
DatexPartialImplementation::$origin protected property
DatexPartialImplementation::$timezone protected property
DatexPartialImplementation::formatArray final function Overrides DatexInterface::formatArray
DatexPartialImplementation::getBaseYear abstract function 3
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::validate function Overrides DatexInterface::validate 3
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
DatexPartialImplementation::__construct function 3