/** * 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 $type * * @return string */ public function display($type = self::DISPLAY_SHORT) : string { return Calendar::formatDate($this, $type); }
/** * Render the date part of a date/time as a localized string. * * @param mixed $value $The date/time representation (one of the values accepted by toDateTime) * @param bool $longDate $Set to true for the long date format (eg 'December 31, 2000'), false (default) for the short format (eg '12/31/2000') * @param string $toTimezone The timezone to set. Special values are:<ul> * <li>'system' for the current system timezone</li> * <li>'user' (default) for the user's timezone</li> * <li>'app' for the app's timezone</li> * <li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li> * </ul> * * @return string Returns an empty string if $value couldn't be parsed, the localized string otherwise */ public function formatDate($value = 'now', $format = 'short', $toTimezone = 'user') { // legacy if ($format === true) { $format = 'medium'; } else { if ($format === false) { $format = 'short'; } } return Calendar::formatDate($this->toDateTime($value, $toTimezone), $format); }
/** * @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)); }
/** * Render the date part of a date/time as a localized string * @param mixed $value $The date/time representation (one of the values accepted by toDateTime) * @param bool $longDate $Set to true for the long date format (eg 'December 31, 2000'), false (default) for the short format (eg '12/31/2000') * @param string $toTimezone The timezone to set. Special values are:<ul> * <li>'system' for the current system timezone</li> * <li>'user' (default) for the user's timezone</li> * <li>'app' for the app's timezone</li> * <li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li> * </ul> * @return string Returns an empty string if $value couldn't be parsed, the localized string otherwise */ public function formatDate($value = 'now', $longDate = false, $toTimezone = 'user') { return Calendar::formatDate($this->toDateTime($value, $toTimezone), $longDate ? 'medium' : 'short'); }