request = Icinga::app()->getFrontController()->getRequest(); } else { $this->request = $request; } } /** * Helper entry point * * @return self */ public function dateFormat() { return $this; } /** * Return date formatted according to given format respecting the user's timezone * * @param int $timestamp * @param string $format * * @return string */ public function format($timestamp, $format) { $dt = DateTimeFactory::create(); if (DateTimeFactory::isUnixTimestamp($timestamp)) { $dt->setTimestamp($timestamp); } else { return $timestamp; } return $dt->format($format); } /** * Format date according to user's format * * @param int $timestamp A unix timestamp * * @return string The formatted date string */ public function formatDate($timestamp) { return $this->format($timestamp, $this->getDateFormat()); } /** * Format time according to user's format * * @param int $timestamp A unix timestamp * * @return string The formatted time string */ public function formatTime($timestamp) { return $this->format($timestamp, $this->getTimeFormat()); } /** * Format datetime according to user's format * * @param int $timestamp A unix timestamp * @return string The formatted datetime string */ public function formatDateTime($timestamp) { return $this->format($timestamp, $this->getDateTimeFormat()); } /** * Retrieve the user's date format string * * @return string */ public function getDateFormat() { // TODO(mh): Missing localized format (#6077) return 'd/m/Y'; } /** * Retrieve the user's time format string * * @return string */ public function getTimeFormat() { // TODO(mh): Missing localized format (#6077) return 'g:i A'; } /** * Retrieve the user's datetime format string * * @return string */ public function getDateTimeFormat() { return $this->getDateFormat() . ' ' . $this->getTimeFormat(); } }