/** * Reorder the days property based on current language */ private static function init() { $day = Calendar::getFirstWeekday(); DateTime::$weekStartsAt = $day; while (array_keys(self::$days)[0] != $day) { $key = array_keys(self::$days)[0]; $value = self::$days[$key]; unset(self::$days[$key]); self::$days[$key] = $value; } self::$init = true; }
/** * 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; } }