Ejemplo n.º 1
0
 private function doTestOffset(ZoneOffset $offset, $hours, $minutes, $seconds)
 {
     $this->assertEquals($offset->getTotalSeconds(), $hours * 60 * 60 + $minutes * 60 + $seconds);
     if ($hours == 0 && $minutes == 0 && $seconds == 0) {
         $id = "Z";
     } else {
         $str = $hours < 0 || $minutes < 0 || $seconds < 0 ? "-" : "+";
         $str .= substr(Math::abs($hours) + 100, 1);
         $str .= ":";
         $str .= substr(Math::abs($minutes) + 100, 1);
         if ($seconds != 0) {
             $str .= ":";
             $str .= substr(Math::abs($seconds) + 100, 1);
         }
         $id = $str;
     }
     $this->assertEquals($offset->getId(), $id);
     $this->assertEquals($offset, ZoneOffset::ofHoursMinutesSeconds($hours, $minutes, $seconds));
     if ($seconds == 0) {
         $this->assertEquals($offset, ZoneOffset::ofHoursMinutes($hours, $minutes));
         if ($minutes == 0) {
             $this->assertEquals($offset, ZoneOffset::ofHours($hours));
         }
     }
     $this->assertEquals(ZoneOffset::of($id), $offset);
     $this->assertEquals($offset->__toString(), $id);
 }
Ejemplo n.º 2
0
 private static function OFFSET_0130()
 {
     return ZoneOffset::of("+01:30");
 }
Ejemplo n.º 3
0
 public function test_NewYork_getStandardOffset()
 {
     $test = $this->americaNewYork();
     $dateTime = $this->createZDT(1860, 1, 1, ZoneOffset::UTC());
     while ($dateTime->getYear() < 2010) {
         $instant = $dateTime->toInstant();
         if ($dateTime->toLocalDate()->isBefore(LocalDate::of(1883, 11, 18))) {
             $this->assertEquals($test->getStandardOffset($instant), ZoneOffset::of("-04:56:02"));
         } else {
             $this->assertEquals($test->getStandardOffset($instant), ZoneOffset::ofHours(-5));
         }
         $dateTime = $dateTime->plusMonths(6);
     }
 }
 /**
  * @dataProvider provider_sampleToString
  */
 public function test_toString($y, $o, $d, $h, $m, $s, $n, $offsetId, $expected)
 {
     $t = OffsetDateTime::of($y, $o, $d, $h, $m, $s, $n, ZoneOffset::of($offsetId));
     $str = $t->__toString();
     $this->assertEquals($str, $expected);
 }
Ejemplo n.º 5
0
 private static function OFFSET_PTWO()
 {
     return ZoneOffset::of("+02:00");
 }
Ejemplo n.º 6
0
 /**
  * Parse once a prefix is established.
  *
  * @param string $zoneId the time-zone ID, not null
  * @param int $prefixLength the length of the prefix, 2 or 3
  * @param bool $checkAvailable
  * @return ZoneId the zone ID, not null
  * @throws DateTimeException if the zone ID has an invalid format
  */
 private static function ofWithPrefix($zoneId, $prefixLength, $checkAvailable)
 {
     $prefix = substr($zoneId, 0, $prefixLength);
     if (strlen($zoneId) === $prefixLength) {
         return self::ofOffset($prefix, ZoneOffset::UTC());
     }
     if ($zoneId[$prefixLength] != '+' && $zoneId[$prefixLength] != '-') {
         return ZoneRegion::ofId($zoneId, $checkAvailable);
         // drop through to ZoneRulesProvider
     }
     try {
         $offset = ZoneOffset::of(substr($zoneId, $prefixLength));
         if ($offset == ZoneOffset::UTC()) {
             return self::ofOffset($prefix, $offset);
         }
         return self::ofOffset($prefix, $offset);
     } catch (DateTimeException $ex) {
         throw new DateTimeException("Invalid ID for offset-based ZoneId: " . $zoneId, $ex);
     }
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider data_offsetBasedValidOther
  */
 public function test_factory_of_String_offsetBasedValidOther($input, $offsetId)
 {
     $test = ZoneId::of($input);
     $this->assertEquals($test->getId(), $input);
     $this->assertEquals($test->getRules(), ZoneOffset::of($offsetId)->getRules());
     $this->assertEquals($test->normalized(), ZoneOffset::of($offsetId));
 }
 /**
  * @param Expected $expected
  * @param $offsetId
  * @param $zoneId
  * @throws DateTimeException
  */
 private function buildCalendrical($expected, $offsetId, $zoneId)
 {
     if ($offsetId !== null) {
         $expected->add(ZoneOffset::of($offsetId));
     }
     if ($zoneId !== null) {
         $expected->zone = ZoneId::of($zoneId);
     }
 }