<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::fromDateTimeZone());
var_dump(IntlTimeZone::fromDateTimeZone(1, 2));
var_dump(IntlTimeZone::fromDateTimeZone('sdfds'));
var_dump(IntlTimeZone::fromDateTimeZone(new stdclass()));
$dt = new DateTime('2012-08-01 00:00:00 WEST');
var_dump(IntlTimeZone::fromDateTimeZone($dt->getTimeZone()));
var_dump(intltz_from_date_time_zone());
Example #2
0
 public function testGetFormatterDateException()
 {
     $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) {
         return IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName));
     });
     if (empty($timezoneNameList)) {
         $this->markTestSkipped('No unsupported timezones');
     }
     try {
         $timeZoneName = \Functional\first($timezoneNameList);
         $render = new CM_Frontend_Render();
         $render->getFormatterDate(IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, null, new DateTimeZone($timeZoneName));
         $this->fail('Date formatter created with unsupported timezone');
     } catch (CM_Exception $ex) {
         $this->assertSame('Cannot create date formatter', $ex->getMessage());
     }
 }
Example #3
0
 /**
  * @return DateTimeZone|null
  */
 public function getTimeZone()
 {
     $pointCurrent = $this->getGeoPoint();
     if (null === $pointCurrent) {
         return null;
     }
     $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) {
         return null === IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName));
     });
     $distanceList = Functional\map($timezoneNameList, function ($timezoneName) use($pointCurrent) {
         $timezoneLocation = (new DateTimeZone($timezoneName))->getLocation();
         $pointTimeZone = new CM_Geo_Point($timezoneLocation['latitude'], $timezoneLocation['longitude']);
         return ['timezoneName' => $timezoneName, 'distance' => $pointCurrent->calculateDistanceTo($pointTimeZone)];
     });
     $closestDistance = Functional\reduce_left($distanceList, function (array $current, $index, $collection, array $minimal) {
         return $current['distance'] < $minimal['distance'] ? $current : $minimal;
     }, $distanceList[0]);
     return new DateTimeZone($closestDistance['timezoneName']);
 }
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Lisbon');
$tz = IntlTimeZone::fromDateTimeZone(new DateTimeZone('Europe/Amsterdam'));
var_dump($tz->getID(), $tz->getRawOffset());
$dt = new DateTime('2012-01-01 00:00:00 CET');
$dtz = $dt->getTimeZone();
/* this is different from new DateTimeZone('CET'),
 * which gives a Europe/Berlin timezone */
var_dump($dtz->getName());
$tz = IntlTimeZone::fromDateTimeZone($dtz);
var_dump($tz->getID(), $tz->getRawOffset());
$dt = new DateTime('2012-01-01 00:00:00 +0340');
$dtz = $dt->getTimeZone();
/* I don't think this timezone can be generated without a DateTime object */
var_dump($dtz->getName());
$tz = IntlTimeZone::fromDateTimeZone($dtz);
var_dump($tz->getID(), $tz->getRawOffset());