/** * Outputs Date(time) Sting nicely formatted (+ localized!) * * Options: * - timezone: User's timezone * - default: Default string (defaults to "-----") * - oclock: Set to true to append oclock string * * @param string $dateString, * @param string $format Format (YYYY-MM-DD, DD.MM.YYYY) * @param array $options @return string * @return string */ public static function localDate($dateString = null, $format = null, $options = []) { $defaults = ['default' => '-----', 'timezone' => null]; $options += $defaults; if ($options['timezone'] === null && strlen($dateString) === 10) { $options['timezone'] = date_default_timezone_get(); } if ($dateString === null) { $dateString = time(); } $date = static::fromString($dateString, $options['timezone']); if ($date === null || $date === false || $date <= 0) { return $options['default']; } if ($format === null) { if (is_int($dateString) || strpos($dateString, ' ') !== false) { $format = FORMAT_LOCAL_YMDHM; } else { $format = FORMAT_LOCAL_YMD; } } $date = parent::_strftime($format, $date); if (!empty($options['oclock'])) { switch ($format) { case FORMAT_LOCAL_YMDHM: case FORMAT_LOCAL_YMDHMS: case FORMAT_LOCAL_YMDHM: case FORMAT_LOCAL_HM: case FORMAT_LOCAL_HMS: $date .= ' ' . __d('tools', 'o\'clock'); break; } } return $date; }