Exemplo n.º 1
0
 /**
  * AgaviTimeZone API.
  *
  * @see        AgaviTimeZone::getOffsetRef()
  * 
  * @author     Dominik del Bondio <*****@*****.**>
  * @author     The ICU Project
  * @since      0.11.0
  */
 public function getOffsetRef($date, $local, &$rawoff, &$dstoff)
 {
     // The check against finalMillis will suffice most of the time, except
     // for the case in which finalMillis == DBL_MAX, date == DBL_MAX,
     // and finalZone == 0.  For this case we add "&& finalZone != 0".
     if ($date >= $this->finalMillis && $this->finalZone !== null) {
         $millis = 0;
         $days = AgaviToolkit::floorDivide($date, AgaviDateDefinitions::MILLIS_PER_DAY, $millis);
         $year = 0;
         $month = 0;
         $dom = 0;
         $dow = 0;
         AgaviCalendarGrego::dayToFields($days, $year, $month, $dom, $dow);
         $rawoff = $this->finalZone->getRawOffset();
         if (!$local) {
             // Adjust from GMT to local
             $date += $rawoff;
             $days2 = AgaviToolkit::floorDivide($date, AgaviDateDefinitions::MILLIS_PER_DAY, $millis);
             if ($days2 != $days) {
                 AgaviCalendarGrego::dayToFields($days2, $year, $month, $dom, $dow);
             }
         }
         $dstoff = $this->finalZone->getOffset(AgaviGregorianCalendar::AD, $year, $month, $dom, $dow, $millis) - $rawoff;
         return;
     }
     $secs = floor($date / AgaviDateDefinitions::MILLIS_PER_SECOND);
     $transition = $this->findTransition($secs, $local);
     $rawoff = $this->types[$transition['type']]['rawOffset'] * AgaviDateDefinitions::MILLIS_PER_SECOND;
     $dstoff = $this->types[$transition['type']]['dstOffset'] * AgaviDateDefinitions::MILLIS_PER_SECOND;
 }
Exemplo n.º 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);
 }