/** * Get a localized list of times at specified interval * * @param int $interval interval between times in minutes * @param int $start time in seconds from midnight to start list * @param int $end time in seconds from midnight to end list * * @return array */ public static function getList($interval = 15, $start = 0, $end = 86400) { $timeList = array(); $tz = new \DateTimeZone('UTC'); $start = (int) $start; $end = (int) $end; if (abs($end - $start) > 86400) { $start = 0; $end = 86400; } $end = $end <= 86400 && $end > 0 ? $end : 86400; $interval = (int) $interval !== 0 ? 60 * $interval : 60 * 15; for ($t = $start; $t < $end; $t += $interval) { //$formatted = Calendar::formatTimeEx($t, 'short', $tz); $formatted = \Xoops\Core\Locale\Time::formatTime($t, 'short', $tz); $timeList[$formatted] = $formatted; } return $timeList; }
/** * __construct * * @param string|array $caption Caption or array of all attributes * @param string $name name * @param integer|\DateTime $value unix timestamp or DateTime object */ public function __construct($caption, $name = null, $value = 0) { // stash everything in the tray and sort out later if (is_array($caption)) { parent::__construct($caption); $this->set(':joiner', ''); } else { parent::__construct($caption, '', $name); $this->set('value', $value); } $workingTime = \Xoops\Core\Locale\Time::cleanTime($this->get('value', 0)); $dateDefinition = ['caption' => '', 'name' => $this->get('name') . '[date]', 'id' => $this->get('name') . '-date', 'size' => 15, 'value' => $workingTime, ElementFactory::FORM_KEY => $this]; new DateSelect($dateDefinition); $minuteInterval = $this->get(':minuteinterval', 15); $hours = (int) ltrim($workingTime->format('H'), '0'); $minutes = (int) ltrim($workingTime->format('i'), '0'); $timeDefinition = ['caption' => '', 'name' => $this->get('name') . '[time]', 'id' => $this->get('name') . '-time', 'size' => 1, 'value' => \Xoops\Core\Locale\Time::formatTime($hours * 3600 + 60 * $minuteInterval * ceil($minutes / $minuteInterval), 'short', new \DateTimeZone('UTC')), ElementFactory::FORM_KEY => $this, 'option' => \Xoops\Core\Lists\Time::getList($minuteInterval)]; new Select($timeDefinition); }
/** * Function to display formatted times in user timezone * * @param mixed $time * @param string $format Format codes () * 's' or 'short' - short; * 'm' or 'medium' - medium; * 'l' or 'long' - long; * 'c' or 'custom' - format determined according to interval to present; * 'e' or 'elapse' - Elapsed; * 'mysql' - Y-m-d H:i:s; * 'rss' * * @return string */ public static function formatTimestamp($time, $format = 'l') { $workingTime = Time::cleanTime($time); switch (strtolower($format)) { case 'short': case 's': return Time::formatDateTime($workingTime, 'short'); case 'medium': case 'm': return Time::formatDateTime($workingTime, 'medium'); case 'long': case 'l': return Time::formatDateTime($workingTime, 'long'); case 'full': case 'f': return Time::formatDateTime($workingTime, 'full'); case 'custom': case 'c': $specialName = Calendar::getDateRelativeName($workingTime, true); if ($specialName != '') { return $specialName; } // no break - fall through // no break - fall through case 'elapse': case 'e': return Time::describeRelativeInterval($workingTime); case 'short-date': return Time::formatDate($workingTime, 'short'); case 'short-time': return Time::formatTime($workingTime, 'short'); case 'medium-date': return Time::formatDate($workingTime, 'medium'); case 'medium-time': return Time::formatTime($workingTime, 'medium'); case 'long-date': return Time::formatDate($workingTime, 'long'); case 'long-time': return Time::formatTime($workingTime, 'long'); case 'full-date': return Time::formatDate($workingTime, 'full'); case 'full-time': return Time::formatTime($workingTime, 'full'); case 'rss': $workingTime->setTimezone(new \DateTimeZone('UTC')); return $workingTime->format($workingTime::RSS); case 'mysql': $workingTime->setTimezone(new \DateTimeZone('UTC')); return $workingTime->format('Y-m-d H:i:s'); default: if ($format != '') { return $workingTime->format($format); } return Time::formatDateTime($workingTime, 'long'); break; } }