Example #1
0
 /**
  * Called by the overload handler in the constructor.
  *
  * @param      AgaviTimeZone The timezone to use.
  * @param      AgaviLocale   The locale to use.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     The ICU Project
  * @since      0.11.0
  */
 protected function constructorOO(AgaviTimeZone $zone, AgaviLocale $locale)
 {
     $this->translationManager = $zone->getTranslationManager();
     $this->clear();
     $this->fZone = clone $zone;
     $this->setWeekCountData($locale, null);
 }
 /**
  * AgaviTimeZone API.
  *
  * @see        AgaviTimeZone::getDSTSavings()
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     The ICU Project
  * @since      0.11.0
  */
 public function getDSTSavings()
 {
     if ($this->finalZone !== null) {
         return $this->finalZone->getDSTSavings();
     }
     return parent::getDSTSavings();
 }
Example #3
0
 public function testFebruary()
 {
     // Time zone with daylight savings time from the first Sunday in November
     // to the last Sunday in February.
     // Similar to the new rule for Brazil (Sao Paulo) in tzdata2006n.
     //
     // Note: In tzdata2007h, the rule had changed, so no actual zones uses
     // lastSun in Feb anymore.
     $tz1 = new AgaviSimpleTimeZone($this->tm, -3 * AgaviDateDefinitions::MILLIS_PER_HOUR, "nov-feb", AgaviDateDefinitions::NOVEMBER, 1, AgaviDateDefinitions::SUNDAY, 0, AgaviDateDefinitions::FEBRUARY, -1, AgaviDateDefinitions::SUNDAY, 0);
     // Now hardcode the same rules as for Brazil, so that we cover the intended code
     // even when in the future zoneinfo hardcodes these transition dates.
     $tz2 = new AgaviSimpleTimeZone($this->tm, -3 * AgaviDateDefinitions::MILLIS_PER_HOUR, "nov-feb2", AgaviDateDefinitions::NOVEMBER, 1, -AgaviDateDefinitions::SUNDAY, 0, AgaviDateDefinitions::FEBRUARY, -29, -AgaviDateDefinitions::SUNDAY, 0);
     // Gregorian calendar with the UTC time zone for getting sample test date/times.
     $gc = new AgaviGregorianCalendar(AgaviTimeZone::getGMT($this->tm));
     $data = array(array('year' => 2006, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 5, 'hour' => 02, 'minute' => 59, 'second' => 59, 'offsetHours' => -3), array('year' => 2006, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 5, 'hour' => 03, 'minute' => 00, 'second' => 00, 'offsetHours' => -2), array('year' => 2007, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 25, 'hour' => 01, 'minute' => 59, 'second' => 59, 'offsetHours' => -2), array('year' => 2007, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 25, 'hour' => 02, 'minute' => 00, 'second' => 00, 'offsetHours' => -3), array('year' => 2007, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 4, 'hour' => 02, 'minute' => 59, 'second' => 59, 'offsetHours' => -3), array('year' => 2007, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 4, 'hour' => 03, 'minute' => 00, 'second' => 00, 'offsetHours' => -2), array('year' => 2008, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 24, 'hour' => 01, 'minute' => 59, 'second' => 59, 'offsetHours' => -2), array('year' => 2008, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 24, 'hour' => 02, 'minute' => 00, 'second' => 00, 'offsetHours' => -3), array('year' => 2008, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 2, 'hour' => 02, 'minute' => 59, 'second' => 59, 'offsetHours' => -3), array('year' => 2008, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 2, 'hour' => 03, 'minute' => 00, 'second' => 00, 'offsetHours' => -2), array('year' => 2009, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 22, 'hour' => 01, 'minute' => 59, 'second' => 59, 'offsetHours' => -2), array('year' => 2009, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 22, 'hour' => 02, 'minute' => 00, 'second' => 00, 'offsetHours' => -3), array('year' => 2009, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 1, 'hour' => 02, 'minute' => 59, 'second' => 59, 'offsetHours' => -3), array('year' => 2009, 'month' => AgaviDateDefinitions::NOVEMBER, 'day' => 1, 'hour' => 03, 'minute' => 00, 'second' => 00, 'offsetHours' => -2), array('year' => 2010, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 28, 'hour' => 01, 'minute' => 59, 'second' => 59, 'offsetHours' => -2), array('year' => 2010, 'month' => AgaviDateDefinitions::FEBRUARY, 'day' => 28, 'hour' => 02, 'minute' => 00, 'second' => 00, 'offsetHours' => -3));
     $timezones = array($tz1, $tz2);
     #	    TimeZone *tz;
     #	    UDate dt;
     #	    int32_t t, i, raw, dst;
     $t = $i = $raw = $dst = null;
     for ($t = 0; $t < count($timezones); ++$t) {
         $tz = clone $timezones[$t];
         for ($i = 0; $i < count($data); ++$i) {
             $gc->set($data[$i]['year'], $data[$i]['month'], $data[$i]['day'], $data[$i]['hour'], $data[$i]['minute'], $data[$i]['second']);
             $dt = $gc->getTime();
             $tz->getOffsetRef($dt, false, $raw, $dst);
             if ($raw + $dst != $data[$i]['offsetHours'] * AgaviDateDefinitions::MILLIS_PER_HOUR) {
                 $this->fail(sprintf("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) returns %d+%d != %d", $t, $i, $data[$i]['year'], $data[$i]['month'] + 1, $data[$i]['day'], $data[$i]['hour'], $data[$i]['minute'], $data[$i]['second'], $raw, $dst, $data[$i]['offsetHours'] * AgaviDateDefinitions::MILLIS_PER_HOUR));
             }
         }
     }
 }
 /**
  * Creates a new timezone instance for the given identifier.
  *
  * Please note that this method caches the results for each identifier, so
  * if you plan to modify the timezones returned by this method you need to 
  * clone them first. Alternatively you can set the cache parameter to false,
  * but this will mean the data for this timezone will be loaded from the 
  * hdd again.
  *
  * @return     AgaviTimeZone The timezone instance for the given id.
  *
  * @author     Dominik del Bondio <*****@*****.**>
  * @since      0.11.0
  */
 public function createTimeZone($id, $cache = true)
 {
     if (!isset($this->timeZoneList[$id])) {
         try {
             return AgaviTimeZone::createCustomTimeZone($this, $id);
         } catch (Exception $e) {
             return null;
         }
     }
     if (!isset($this->timeZoneCache[$id]) || !$cache) {
         $currId = $id;
         // resolve links
         while ($this->timeZoneList[$currId]['type'] == 'link') {
             $currId = $this->timeZoneList[$currId]['to'];
         }
         $zoneData = (include AgaviConfig::get('core.cldr_dir') . '/timezones/' . $this->timeZoneList[$currId]['filename']);
         $zone = new AgaviOlsonTimeZone($this, $id, $zoneData);
         $zone->setResolvedId($currId);
         if ($cache) {
             $this->timeZoneCache[$id] = $zone;
         }
     } else {
         $zone = $this->timeZoneCache[$id];
     }
     return $zone;
 }
 /**
  * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
  * and times to start and end daylight savings time. To create a TimeZone that
  * doesn't observe daylight savings time, don't use this constructor; use
  * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
  * TimeZone.createInstance() to create a TimeZone instead of creating a
  * SimpleTimeZone directly with this constructor.
  * <P>
  * Various types of daylight-savings time rules can be specified by using 
  * different values for startDay and startDayOfWeek and endDay and 
  * endDayOfWeek. For a complete explanation of how these parameters work, see 
  * the documentation for setStartRule().
  *
  * @param      AgaviTranslationManager The translation Manager
  * @param      int    The new SimpleTimeZone's raw GMT offset
  * @param      string The new SimpleTimeZone's time zone ID.
  * @param      int    The daylight savings starting month. Month is
  *                    0-based. eg, 0 for January.
  * @param      int    The daylight savings starting
  *                    day-of-week-in-month. See setStartRule() for a
  *                    complete explanation.
  * @param      int    The daylight savings starting day-of-week.
  *                    See setStartRule() for a complete explanation.
  * @param      int    The daylight savings starting time, expressed as the
  *                    number of milliseconds after midnight.
  * @param      int    Whether the start time is local wall time, local
  *                    standard time, or UTC time. Default is local wall time.
  * @param      int    The daylight savings ending month. Month is
  *                    0-based. eg, 0 for January.
  * @param      int    The daylight savings ending day-of-week-in-month.
  *                    See setStartRule() for a complete explanation.
  * @param      int    The daylight savings ending day-of-week.
  *                    See setStartRule() for a complete explanation.
  * @param      int    The daylight savings ending time, expressed as the
  *                    number of milliseconds after midnight.
  * @param      int    Whether the end time is local wall time, local
  *                    standard time, or UTC time. Default is local wall time.
  * @param      int    The number of milliseconds added to standard time
  *                    to get DST time. Default is one hour.
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     The ICU Project
  * @since      0.11.0
  */
 protected function constructorOISIIIIIIIIIII(AgaviTranslationManager $tm, $rawOffsetGMT, $id, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, $savingsStartTimeMode, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, $savingsEndTimeMode, $savingsDST)
 {
     parent::__construct($tm, $id);
     $this->construct($rawOffsetGMT, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, $savingsStartTimeMode, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, $savingsEndTimeMode, $savingsDST);
 }
 /**
  * Returns true if this zone has the same rule and offset as another zone.
  * That is, if this zone differs only in ID, if at all.
  * 
  * @param      AgaviTimeZone The object to be compared with
  * 
  * @return     bool True if the given zone is the same as this one,
  *                  with the possible exception of the ID
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     The ICU Project
  * @since      0.11.0
  */
 public function hasSameRules(AgaviTimeZone $other)
 {
     return $this->getRawOffset() == $other->getRawOffset() && $this->useDaylightTime() == $other->useDaylightTime();
 }
Example #7
0
 public function testJD()
 {
     $kEpochStartAsJulianDay = 2440588;
     $cal = $this->tm->createCalendar();
     $cal->setTimeZone(AgaviTimeZone::getGMT($this->tm));
     $cal->clear();
     $jd = $cal->get(AgaviDateDefinitions::JULIAN_DAY);
     $this->assertEquals($kEpochStartAsJulianDay, (int) $jd);
     $cal->setTime(AgaviCalendar::getNow());
     $cal->clear();
     $cal->set(AgaviDateDefinitions::JULIAN_DAY, $kEpochStartAsJulianDay);
     $epochTime = $cal->getTime();
     $this->assertEquals(0, (int) $epochTime);
 }
Example #8
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testTicket958()
 {
     $tm = $this->getContext()->getTranslationManager();
     $tz = AgaviTimeZone::createCustomTimeZone($tm, '+01:00');
 }