* @license PHP License * @package WB * @subpackage base */ /** * String DateFormatter * * Helper to get international date formatter * * @version 0.2.0 * @package WB * @subpackage base */ class WBString_DateFormatter extends WBStdClass { /** * Configured Timezone * @var DateTimeZone */ static private $timezone; /** * Current Format Pattern */ private $pattern = 'd. MMM yyyy'; /** * Set Current Timezone String * * @param string * @return WBString_DateFormatter */ public function setTimeZone($timezone) { self::$timezone = new DateTimeZone($timezone); return $this; } /** * Get Time Zone String * * @param bool true for locale timezone, false for UTC * @return string */ public function getTimeZone($local = false) { if (!$local) { return 'UTC'; } $conf = WBClass::create('WBConfig'); $conf->load('locale'); return $conf->get('locale/timezone', 'UTC'); } /** * Set Format Pattern * * @param string pattern * @return WBString_DateFormatter */ public function setPattern($pattern) { $this->pattern = $pattern; return $this; } /** * Format Timestamp * * @param string timestamp * @return string */ public function format($timestamp) { $this->initTimezone(); // support for international formats like Sunday is Sonntag in German... $fmt = new IntlDateFormatter(patI18n::getLocale(), IntlDateFormatter::FULL, IntlDateFormatter::FULL, self::$timezone); $fmt->setPattern($this->pattern); return $fmt->format($timestamp); } /** * Load Timezone Once * * */ private function initTimezone() { if (!empty(self::$timezone)) { return ; } $this->setTimezone($this->getTimeZone()); } }