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 ZDT()
 {
     return LocalDateTime::of(2008, 6, 30, 11, 30, 10, 500)->atZone(ZoneOffset::ofHours(2));
 }
Ejemplo n.º 3
0
 public function provider_offsets()
 {
     return [["+HH", "+00", ZoneOffset::UTC()], ["+HH", "-00", ZoneOffset::UTC()], ["+HH", "+01", ZoneOffset::ofHours(1)], ["+HH", "-01", ZoneOffset::ofHours(-1)], ["+HHMM", "+0000", ZoneOffset::UTC()], ["+HHMM", "-0000", ZoneOffset::UTC()], ["+HHMM", "+0102", ZoneOffset::ofHoursMinutes(1, 2)], ["+HHMM", "-0102", ZoneOffset::ofHoursMinutes(-1, -2)], ["+HH:MM", "+00:00", ZoneOffset::UTC()], ["+HH:MM", "-00:00", ZoneOffset::UTC()], ["+HH:MM", "+01:02", ZoneOffset::ofHoursMinutes(1, 2)], ["+HH:MM", "-01:02", ZoneOffset::ofHoursMinutes(-1, -2)], ["+HHMMss", "+0000", ZoneOffset::UTC()], ["+HHMMss", "-0000", ZoneOffset::UTC()], ["+HHMMss", "+0100", ZoneOffset::ofHoursMinutesSeconds(1, 0, 0)], ["+HHMMss", "+0159", ZoneOffset::ofHoursMinutesSeconds(1, 59, 0)], ["+HHMMss", "+0200", ZoneOffset::ofHoursMinutesSeconds(2, 0, 0)], ["+HHMMss", "+1800", ZoneOffset::ofHoursMinutesSeconds(18, 0, 0)], ["+HHMMss", "+010215", ZoneOffset::ofHoursMinutesSeconds(1, 2, 15)], ["+HHMMss", "-0100", ZoneOffset::ofHoursMinutesSeconds(-1, 0, 0)], ["+HHMMss", "-0200", ZoneOffset::ofHoursMinutesSeconds(-2, 0, 0)], ["+HHMMss", "-1800", ZoneOffset::ofHoursMinutesSeconds(-18, 0, 0)], ["+HHMMss", "+000000", ZoneOffset::UTC()], ["+HHMMss", "-000000", ZoneOffset::UTC()], ["+HHMMss", "+010000", ZoneOffset::ofHoursMinutesSeconds(1, 0, 0)], ["+HHMMss", "+010203", ZoneOffset::ofHoursMinutesSeconds(1, 2, 3)], ["+HHMMss", "+015959", ZoneOffset::ofHoursMinutesSeconds(1, 59, 59)], ["+HHMMss", "+020000", ZoneOffset::ofHoursMinutesSeconds(2, 0, 0)], ["+HHMMss", "+180000", ZoneOffset::ofHoursMinutesSeconds(18, 0, 0)], ["+HHMMss", "-010000", ZoneOffset::ofHoursMinutesSeconds(-1, 0, 0)], ["+HHMMss", "-020000", ZoneOffset::ofHoursMinutesSeconds(-2, 0, 0)], ["+HHMMss", "-180000", ZoneOffset::ofHoursMinutesSeconds(-18, 0, 0)], ["+HH:MM:ss", "+00:00", ZoneOffset::UTC()], ["+HH:MM:ss", "-00:00", ZoneOffset::UTC()], ["+HH:MM:ss", "+01:00", ZoneOffset::ofHoursMinutesSeconds(1, 0, 0)], ["+HH:MM:ss", "+01:02", ZoneOffset::ofHoursMinutesSeconds(1, 2, 0)], ["+HH:MM:ss", "+01:59", ZoneOffset::ofHoursMinutesSeconds(1, 59, 0)], ["+HH:MM:ss", "+02:00", ZoneOffset::ofHoursMinutesSeconds(2, 0, 0)], ["+HH:MM:ss", "+18:00", ZoneOffset::ofHoursMinutesSeconds(18, 0, 0)], ["+HH:MM:ss", "+01:02:15", ZoneOffset::ofHoursMinutesSeconds(1, 2, 15)], ["+HH:MM:ss", "-01:00", ZoneOffset::ofHoursMinutesSeconds(-1, 0, 0)], ["+HH:MM:ss", "-02:00", ZoneOffset::ofHoursMinutesSeconds(-2, 0, 0)], ["+HH:MM:ss", "-18:00", ZoneOffset::ofHoursMinutesSeconds(-18, 0, 0)], ["+HH:MM:ss", "+00:00:00", ZoneOffset::UTC()], ["+HH:MM:ss", "-00:00:00", ZoneOffset::UTC()], ["+HH:MM:ss", "+01:00:00", ZoneOffset::ofHoursMinutesSeconds(1, 0, 0)], ["+HH:MM:ss", "+01:02:03", ZoneOffset::ofHoursMinutesSeconds(1, 2, 3)], ["+HH:MM:ss", "+01:59:59", ZoneOffset::ofHoursMinutesSeconds(1, 59, 59)], ["+HH:MM:ss", "+02:00:00", ZoneOffset::ofHoursMinutesSeconds(2, 0, 0)], ["+HH:MM:ss", "+18:00:00", ZoneOffset::ofHoursMinutesSeconds(18, 0, 0)], ["+HH:MM:ss", "-01:00:00", ZoneOffset::ofHoursMinutesSeconds(-1, 0, 0)], ["+HH:MM:ss", "-02:00:00", ZoneOffset::ofHoursMinutesSeconds(-2, 0, 0)], ["+HH:MM:ss", "-18:00:00", ZoneOffset::ofHoursMinutesSeconds(-18, 0, 0)], ["+HHMMSS", "+000000", ZoneOffset::UTC()], ["+HHMMSS", "-000000", ZoneOffset::UTC()], ["+HHMMSS", "+010203", ZoneOffset::ofHoursMinutesSeconds(1, 2, 3)], ["+HHMMSS", "-010203", ZoneOffset::ofHoursMinutesSeconds(-1, -2, -3)], ["+HH:MM:SS", "+00:00:00", ZoneOffset::UTC()], ["+HH:MM:SS", "-00:00:00", ZoneOffset::UTC()], ["+HH:MM:SS", "+01:02:03", ZoneOffset::ofHoursMinutesSeconds(1, 2, 3)], ["+HH:MM:SS", "-01:02:03", ZoneOffset::ofHoursMinutesSeconds(-1, -2, -3)]];
 }
Ejemplo n.º 4
0
 public function test_of()
 {
     //used for standard offset
     $stdOffset1 = ZoneOffset::UTC();
     $stdOffset2 = ZoneOffset::ofHours(1);
     $time_of_stdOffsetTransition1 = LocalDateTime::of(2013, 1, 5, 1, 0);
     $stdOffsetTransition1 = ZoneOffsetTransition::of($time_of_stdOffsetTransition1, $stdOffset1, $stdOffset2);
     $stdOffsetTransition_list = [];
     $stdOffsetTransition_list[] = $stdOffsetTransition1;
     //used for wall offset
     $wallOffset1 = ZoneOffset::ofHours(2);
     $wallOffset2 = ZoneOffset::ofHours(4);
     $wallOffset3 = ZoneOffset::ofHours(7);
     $time_of_wallOffsetTransition1 = LocalDateTime::of(2013, 2, 5, 1, 0);
     $time_of_wallOffsetTransition2 = LocalDateTime::of(2013, 3, 5, 1, 0);
     $time_of_wallOffsetTransition3 = LocalDateTime::of(2013, 10, 5, 1, 0);
     $wallOffsetTransition1 = ZoneOffsetTransition::of($time_of_wallOffsetTransition1, $wallOffset1, $wallOffset2);
     $wallOffsetTransition2 = ZoneOffsetTransition::of($time_of_wallOffsetTransition2, $wallOffset2, $wallOffset3);
     $wallOffsetTransition3 = ZoneOffsetTransition::of($time_of_wallOffsetTransition3, $wallOffset3, $wallOffset1);
     $wallOffsetTransition_list = [];
     $wallOffsetTransition_list[] = $wallOffsetTransition1;
     $wallOffsetTransition_list[] = $wallOffsetTransition2;
     $wallOffsetTransition_list[] = $wallOffsetTransition3;
     //used for ZoneOffsetTransitionRule
     $ruleOffset = ZoneOffset::ofHours(3);
     $timeDefinition = TimeDefinition::WALL();
     $rule1 = ZoneOffsetTransitionRule::of(Month::FEBRUARY(), 2, DayOfWeek::MONDAY(), LocalTime::of(1, 0), false, $timeDefinition, ZoneOffset::UTC(), ZoneOffset::UTC(), $ruleOffset);
     $rule_list = [];
     $rule_list[] = $rule1;
     //Begin verification
     $zoneRule = ZoneRules::of($stdOffset1, $wallOffset1, $stdOffsetTransition_list, $wallOffsetTransition_list, $rule_list);
     $before_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->minusSeconds(1);
     $after_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->getStandardOffset($before_time_of_stdOffsetTransition1->toInstant()), $stdOffset1);
     $this->assertEquals($zoneRule->getStandardOffset($after_time_of_stdOffsetTransition1->toInstant()), $stdOffset2);
     $before_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->minusSeconds(1);
     $after_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition1);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition2);
     $before_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->minusSeconds(1);
     $after_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition2);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition3);
     $before_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->minusSeconds(1);
     $after_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition3->toInstant()), $wallOffsetTransition3);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition3->toInstant()), $rule1->createTransition(2014));
 }
Ejemplo n.º 5
0
 private static function OFFSET_PONE()
 {
     return ZoneOffset::ofHours(1);
 }
Ejemplo n.º 6
0
 public function test_with_adjuster_LocalDate_retainOffset2()
 {
     $newYork = ZoneId::of("America/New_York");
     $ldt = LocalDateTime::of(2008, 11, 3, 1, 30);
     $base = ZonedDateTime::ofDateTime($ldt, $newYork);
     $this->assertEquals($base->getOffset(), ZoneOffset::ofHours(-5));
     $test = $base->adjust(LocalDate::of(2008, 11, 2));
     $this->assertEquals($test->getOffset(), ZoneOffset::ofHours(-5));
 }
 public function test_parseBest_firstOption()
 {
     $test = DateTimeFormatter::ofPattern("yyyy-MM-dd HH:mm[XXX]");
     $result = $test->parseBest("2011-06-30 12:30+03:00", TemporalQueries::fromCallable([ZonedDateTime::class, "from"]), TemporalQueries::fromCallable([LocalDateTime::class, "from"]));
     $ldt = LocalDateTime::of(2011, 6, 30, 12, 30);
     $this->assertEquals($result, ZonedDateTime::ofDateTime($ldt, ZoneOffset::ofHours(3)));
 }
 function data_adjustInto()
 {
     return [[OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::of(2012, 3, 4, 1, 1, 1, 100, ZoneOffset::UTC()), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::MAX(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::MIN(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [OffsetDateTime::MAX(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::ofDateTime(OffsetDateTime::MAX()->toLocalDateTime(), ZoneOffset::ofHours(-18)), null], [OffsetDateTime::MIN(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::ofDateTime(OffsetDateTime::MIN()->toLocalDateTime(), ZoneOffset::ofHours(18)), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), ZonedDateTime::of(2012, 3, 4, 1, 1, 1, 100, self::ZONE_GAZA()), ZonedDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::ZONE_GAZA()), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), LocalDateTime::of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException::class], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), LocalDate::of(2210, 2, 2), null, DateTimeException::class], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), LocalTime::of(22, 3, 0), null, DateTimeException::class], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetTime::of(22, 3, 0, 0, ZoneOffset::UTC()), null, DateTimeException::class]];
 }
Ejemplo n.º 9
0
 /**
  * @group long
  */
 public function test_toEpochSecond_afterEpoch()
 {
     for ($i = -5; $i < 5; $i++) {
         $offset = ZoneOffset::ofHours($i);
         for ($j = 0; $j < 100000; $j++) {
             $a = LocalDateTime::of(1970, 1, 1, 0, 0)->plusSeconds($j);
             $this->assertEquals($a->toEpochSecond($offset), $j - $i * 3600);
         }
     }
 }
 private static function OFFSET_0300()
 {
     return ZoneOffset::ofHours(3);
 }
Ejemplo n.º 11
0
 private static function OFFSET_PTWO()
 {
     return ZoneOffset::ofHours(2);
 }
 private static function OFFSET_M0100()
 {
     return ZoneOffset::ofHours(-1);
 }
Ejemplo n.º 13
0
 public function test_factory_from_TemporalAccessor_offset()
 {
     $offset = ZoneOffset::ofHours(1);
     $this->assertEquals(ZoneId::from($offset), $offset);
 }
Ejemplo n.º 14
0
 public function test_NewYork_getOffsetInfo_overlap()
 {
     $test = ZoneId::of("America/New_York");
     $dateTime = LocalDateTime::of(2008, 11, 2, 1, 0, 0, 0);
     $trans = $this->checkOffset($test->getRules(), $dateTime, ZoneOffset::ofHours(-4), self::$OVERLAP);
     $this->assertEquals($trans->getOffsetBefore(), ZoneOffset::ofHours(-4));
     $this->assertEquals($trans->getOffsetAfter(), ZoneOffset::ofHours(-5));
     $this->assertEquals($trans->getInstant(), $this->createInstant8(2008, 11, 2, 2, 0, 0, 0, ZoneOffset::ofHours(-4)));
     $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHours(-1)), false);
     $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHours(-5)), true);
     $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHours(-4)), true);
     $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHours(2)), false);
     $this->assertEquals($trans->__toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");
     $this->assertFalse($trans->equals(null));
     $this->assertFalse($trans->equals(ZoneOffset::ofHours(-4)));
     $this->assertTrue($trans->equals($trans));
     $otherTrans = $test->getRules()->getTransition($dateTime);
     $this->assertTrue($trans->equals($otherTrans));
 }
Ejemplo n.º 15
0
 /**
  * @group long
  */
 public function test_atZone()
 {
     for ($i = 0; $i < 24 * 60 * 60; $i++) {
         $instant = Instant::ofEpochSecond($i);
         $test = $instant->atZone(ZoneOffset::ofHours(1));
         $this->assertEquals($test->getYear(), 1970);
         $this->assertEquals($test->getMonthValue(), 1);
         $this->assertEquals($test->getDayOfMonth(), 1 + ($i >= 23 * 60 * 60 ? 1 : 0));
         $this->assertEquals($test->getHour(), ($i / (60 * 60) + 1) % 24);
         $this->assertEquals($test->getMinute(), $i / 60 % 60);
         $this->assertEquals($test->getSecond(), $i % 60);
     }
 }
 /**
  * SPI method to get the rules for the zone ID.
  * <p>
  * This loads the rules for the specified zone ID.
  * The provider implementation must validate that the zone ID is valid and
  * available, throwing a {@code ZoneRulesException} if it is not.
  * The result of the method in the valid case depends on the caching flag.
  * <p>
  * If the provider implementation is not dynamic, then the result of the
  * method must be the non-null set of rules selected by the ID.
  * <p>
  * If the provider implementation is dynamic, then the flag gives the option
  * of preventing the returned rules from being cached in {@link ZoneId}.
  * When the flag is true, the provider is permitted to return null, where
  * null will prevent the rules from being cached in {@code ZoneId}.
  * When the flag is false, the provider must return non-null rules.
  *
  * @param string $zoneId the zone ID as defined by {@code ZoneId}, not null
  * @param bool $forCaching whether the rules are being queried for caching,
  * true if the returned rules will be cached by {@code ZoneId},
  * false if they will be returned to the user without being cached in {@code ZoneId}
  * @return ZoneRules the rules, null if {@code forCaching} is true and this
  * is a dynamic provider that wants to prevent caching in {@code ZoneId},
  * otherwise not null
  * @throws ZoneRulesException if rules cannot be obtained for the zone ID
  */
 protected function provideRules($zoneId, $forCaching)
 {
     return ZoneRules::ofOffset(ZoneOffset::ofHours(1));
 }