示例#1
0
 /**
  * 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();
 }
示例#2
0
 /**
  * @bug 4107570
  */
 public function testAlternateRules()
 {
     // Like TestDSTSavings, this test should probably be integrated somehow with the main
     // test at the top of this class, but I didn't have time to figure out how to do that.
     //                      --rtg 1/28/98
     $tz = new AgaviSimpleTimeZone($this->tm, -5 * AgaviDateDefinitions::MILLIS_PER_HOUR, "alternateRuleTest");
     // test the day-of-month API
     $tz->setStartRule(AgaviDateDefinitions::MARCH, 10, 12 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $tz->setEndRule(AgaviDateDefinitions::OCTOBER, 20, 12 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::MARCH, 5, AgaviDateDefinitions::THURSDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-5 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::MARCH, 15, AgaviDateDefinitions::SUNDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-4 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::OCTOBER, 15, AgaviDateDefinitions::THURSDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-4 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::OCTOBER, 25, AgaviDateDefinitions::SUNDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-5 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     // test the day-of-week-after-day-in-month API
     $tz->setStartRule(AgaviDateDefinitions::MARCH, 10, AgaviDateDefinitions::FRIDAY, intval(12 * AgaviDateDefinitions::MILLIS_PER_HOUR), true);
     $tz->setEndRule(AgaviDateDefinitions::OCTOBER, 20, AgaviDateDefinitions::FRIDAY, intval(12 * AgaviDateDefinitions::MILLIS_PER_HOUR), false);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::MARCH, 11, AgaviDateDefinitions::WEDNESDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-5 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::MARCH, 14, AgaviDateDefinitions::SATURDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-4 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::OCTOBER, 15, AgaviDateDefinitions::THURSDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-4 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
     $offset = $tz->getOffset(AgaviGregorianCalendar::AD, 1998, AgaviDateDefinitions::OCTOBER, 17, AgaviDateDefinitions::SATURDAY, 10 * AgaviDateDefinitions::MILLIS_PER_HOUR);
     $this->assertEquals(-5 * AgaviDateDefinitions::MILLIS_PER_HOUR, $offset);
 }
 /**
  * Parse a custom time zone identifier and return a corresponding zone.
  * 
  * @param      AgaviTranslationManager The translation manager
  * @param      string A string of the form GMT[+-]hh:mm, GMT[+-]hhmm, or
  *                    GMT[+-]hh.
  * 
  * @return     AgaviTimeZone A newly created AgaviSimpleTimeZone with the 
  *                           given offset and no Daylight Savings Time, or 
  *                           null if the id cannot be parsed.
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     The ICU Project
  * @since      0.11.0
  */
 public static function createCustomTimeZone(AgaviTranslationManager $tm, $id)
 {
     $maxCustomHour = 23;
     $maxCustomMin = 59;
     $maxCustomSec = 59;
     $hours = 0;
     $minutes = 0;
     $seconds = 0;
     $negative = false;
     if (preg_match('#^GMT([+-])(\\d{1,2}):(\\d{1,2})(?::(\\d{1,2}))?$#', $id, $match)) {
         $negative = $match[1] == '-';
         $hours = $match[2];
         $minutes = $match[3];
         $seconds = isset($match[4]) ? $match[4] : 0;
     } elseif (preg_match('#^GMT([+-])(\\d{1,6})$#', $id, $match)) {
         $negative = $match[1] == '-';
         // Supported formats are below -
         //
         // HHmmss
         // Hmmss
         // HHmm
         // Hmm
         // HH
         // H
         $hours = $match[2];
         switch (strlen($hours)) {
             case 1:
             case 2:
                 // already set to hour
                 break;
             case 3:
             case 4:
                 $minutes = $hours % 100;
                 $hours = (int) ($hours / 100);
                 break;
             case 5:
             case 6:
                 $seconds = $hours % 100;
                 $minutes = (int) ($hours / 100) % 100;
                 $hours = (int) ($hours / 10000);
                 break;
         }
     } else {
         throw new InvalidArgumentException('Zone identifier is not parseable');
     }
     if ($hours > $maxCustomHour || $minutes > $maxCustomMin || $seconds > $maxCustomSec) {
         throw new InvalidArgumentException('Zone identifier is not parseable');
     }
     $offset = $hours * 3600 + $minutes * 60 + $seconds;
     if ($negative) {
         $offset = -$offset;
     }
     // create the timezone with an empty id and set it afterwards
     $tz = new AgaviSimpleTimeZone($tm, $offset * 1000.0);
     $tz->setId($tz->formatOffset(false, ''));
     return $tz;
 }