Newscoop\ArticleDatetime::__construct PHP Méthode

__construct() public méthode

public __construct ( mixed $format, string $recurring = null )
$format mixed array of start_date, end_date, etc. keys array with 1 element: start_date => end_date strings - Date and Time formats: http://php.net/manual/en/datetime.formats.php string formatted like above and start separated by end with a - (dash) padded with spaces also in case of array you can add recurring => [daily|weekly|etc.]
$recurring string
    public function __construct($format, $recurring = null)
    {
        if (is_array($format)) {
            if (array_key_exists('start_date', $format)) {
                $this->setStartDate($format['start_date']);
                $this->setEndDate(isset($format['end_date']) ? $format['end_date'] : null);
                $this->setStartTime(isset($format['start_time']) ? $format['start_time'] : null);
                $this->setEndTime(isset($format['end_time']) ? $format['end_time'] : null);
                if (isset($format['recurring'])) {
                    $this->recurring = $format['recurring'];
                }
                return;
            }
            $start = key($format);
            $end = current($format);
        } elseif (is_string($format)) {
            list($start, $end) = explode(" - ", $format);
            if (in_array($end = trim($end), array('1', '0', 'true', 'false'))) {
                $end = (bool) $end;
            }
        }
        $this->setRecurring($recurring);
        if (!($startTimestamp = strtotime($start))) {
            return;
        }
        $parsedStart = date_parse($start);
        $startHasDate = $parsedStart['month'] !== false && $parsedStart['day'] !== false;
        $startHasTime = $parsedStart['hour'] !== false && $parsedStart['minute'] !== false;
        $startDate = strftime('%F', $startTimestamp);
        switch (true) {
            // TODO fix midnight for relative formats
            case is_bool($end) && $end:
                // full day
                $this->setStartDate($startDate);
                $this->setStartTime($startHasTime ? strftime('%T', $startTimestamp) : null);
                $this->setEndDate(null);
                $this->setEndTime(null);
                break;
            case is_string($end):
                // ...until date, or just a single time value for the date
                $parsedEnd = date_parse($end);
                $endHasDate = $parsedEnd['month'] !== false && $parsedEnd['day'] !== false;
                $endHasTime = $parsedEnd['hour'] !== false && $parsedEnd['minute'] !== false;
                $end = preg_replace("/-\\s*recurring:(\\w+)/", "", $end);
                $this->setStartDate($startDate);
                if ($endHasDate) {
                    $this->setEndDate(strftime('%F', strtotime($end)));
                }
                if ($endHasTime && ($parsedEnd['hour'] != 0 || $parsedEnd['minute'] != 0 || $parsedEnd['second'] != 0)) {
                    $this->setEndTime(strftime('%T', strtotime($end)));
                }
                if ($startHasTime && ($parsedStart['hour'] != 0 || $parsedStart['minute'] != 0 || $parsedStart['second'] != 0)) {
                    $this->setStartTime(strftime('%T', strtotime($start)));
                }
                break;
            case is_array($end):
                // time interval for current date
                $spawn =& $this;
                foreach ($end as $startTime => $endTime) {
                    if ($startTime == 'recurring') {
                        // TODO dirty fix for reccuring flag take out
                        continue;
                    }
                    $spawn->setStartDate($startDate);
                    $spawn->setEndDate(null);
                    $spawn->setStartTime(strftime('%T', strtotime($startTime)));
                    $spawn->setEndTime(strftime('%T', strtotime($endTime)));
                    $this->spawns[] = clone $spawn;
                    $spawn =& $this->spawns[count($this->spawns) - 1];
                }
                array_pop($this->spawns);
                break;
        }
    }