/** * Localization * @param string $type Type of localization * @param \DateTime|int|string $data parameters for this localization * @param array $options * @return string|int|false * * Returns the localized data. * * Implemented types: * - date * - Creates a date * - params: timestamp (int/string) * - datetime * - Creates date and time * - params: timestamp (int/string) * - time * - Creates a time * - params: timestamp (int/string) * - firstday: Returns the first day of the week (0 sunday - 6 saturday) * - jsdate: Returns the short JS date format */ public function l($type, $data = null, $options = array()) { // Use the language of the instance $locale = $this->getLanguageCode(); if ($locale === 'sr@latin') { $locale = 'sr_latn'; } if ($type === 'firstday') { return (int) Calendar::getFirstWeekday($locale); } if ($type === 'jsdate') { return (string) Calendar::getDateFormat('short', $locale); } $value = new \DateTime(); if ($data instanceof \DateTime) { $value = $data; } else { if (is_string($data) && !is_numeric($data)) { $data = strtotime($data); $value->setTimestamp($data); } else { if ($data !== null) { $value->setTimestamp($data); } } } $options = array_merge(array('width' => 'long'), $options); $width = $options['width']; switch ($type) { case 'date': return (string) Calendar::formatDate($value, $width, $locale); case 'datetime': return (string) Calendar::formatDatetime($value, $width, $locale); case 'time': return (string) Calendar::formatTime($value, $width, $locale); default: return false; } }
/** * @param string|array $type * * @return string */ public function display($type = null) : string { if ($type == self::DISPLAY_DURATION) { return $this->diffForHumans(DateTime::now(), true); } if (is_null($type)) { $type = [self::DISPLAY_SHORT, self::DISPLAY_SHORT]; } elseif (!is_array($type)) { $type = [$type, $type]; } elseif (is_array($type)) { if (!isset($type[1])) { return Calendar::formatDate($this, $type[0]); } elseif (is_null($type[0])) { return Calendar::formatTime($this, $type[1]); } } return Calendar::formatDatetime($this, implode('|', $type)); }