You are here

abstract class CalendarSystemsPartialImplementation in Calendar Systems 8.3

Hierarchy

Expanded class hierarchy of CalendarSystemsPartialImplementation

File

src/CalendarSystems/CalendarSystemsPartialImplementation.php, line 7

Namespace

Drupal\calendar_systems\CalendarSystems
View source
abstract class CalendarSystemsPartialImplementation implements CalendarSystemsInterface {
  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;
  }

  /**
   * 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 function getOrigin() {
    return $this->origin;
  }
  protected final function tz($tz) {
    $this->origin = new DateTime('@' . $this->origin
      ->getTimestamp(), $tz);
  }

}

Members

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