function data_format_withZone_withChronology() { $ym = YearMonth::of(2008, 6); $ld = LocalDate::of(2008, 6, 30); $lt = LocalTime::of(11, 30); $ldt = LocalDateTime::of(2008, 6, 30, 11, 30); $ot = OffsetTime::ofLocalTime(LocalTime::of(11, 30), self::OFFSET_PONE()); $odt = OffsetDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::OFFSET_PONE()); $zdt = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::ZONE_PARIS()); $thaiZdt = ThaiBuddhistChronology::INSTANCE()->zonedDateTimeFrom($zdt); $instant = Instant::ofEpochSecond(3600); return [[null, null, DayOfWeek::MONDAY(), "::::"], [null, null, $ym, "2008::::ISO"], [null, null, $ld, "2008::::ISO"], [null, null, $lt, ":11:::"], [null, null, $ldt, "2008:11:::ISO"], [null, null, $ot, ":11:+01:00::"], [null, null, $odt, "2008:11:+01:00::ISO"], [null, null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, null, $instant, "::::"], [IsoChronology::INSTANCE(), null, DayOfWeek::MONDAY(), "::::ISO"], [IsoChronology::INSTANCE(), null, $ym, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $ld, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $lt, ":11:::ISO"], [IsoChronology::INSTANCE(), null, $ldt, "2008:11:::ISO"], [IsoChronology::INSTANCE(), null, $ot, ":11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $odt, "2008:11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [IsoChronology::INSTANCE(), null, $instant, "::::ISO"], [null, self::ZONE_PARIS(), DayOfWeek::MONDAY(), ":::Europe/Paris:"], [null, self::ZONE_PARIS(), $ym, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ld, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $lt, ":11::Europe/Paris:"], [null, self::ZONE_PARIS(), $ldt, "2008:11::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:"], [null, self::ZONE_PARIS(), $odt, "2008:12:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $instant, "1970:02:+01:00:Europe/Paris:ISO"], [null, self::OFFSET_PTHREE(), DayOfWeek::MONDAY(), ":::+03:00:"], [null, self::OFFSET_PTHREE(), $ym, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ld, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $lt, ":11::+03:00:"], [null, self::OFFSET_PTHREE(), $ldt, "2008:11::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ot, null], [null, self::OFFSET_PTHREE(), $odt, "2008:13:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $zdt, "2008:12:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $instant, "1970:04:+03:00:+03:00:ISO"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), null, $ym, null], [ThaiBuddhistChronology::INSTANCE(), null, $ld, "2551::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $lt, ":11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ldt, "2551:11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ot, ":11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $odt, "2551:11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $instant, "::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ym, null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ld, "2551:::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $lt, ":11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ldt, "2551:11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"], [null, self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [IsoChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"]]; }
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)); }
public function test_toOffsetDateTime() { $this->assertEquals($this->TEST_DATE_TIME->toOffsetDateTime(), OffsetDateTime::ofDateTime($this->TEST_DATE_TIME->toLocalDateTime(), $this->TEST_DATE_TIME->getOffset())); }
/** * Combines this date with an offset time to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this date at the specified time. * All possible combinations of date and time are valid. * * @param OffsetTime $time the time to combine with, not null * @return OffsetDateTime the offset date-time formed from this date and the specified time, not null */ public function atOffsetTime(OffsetTime $time) { return OffsetDateTime::ofDateTime(LocalDateTime::ofDateAndTime($this, $time->toLocalTime()), $time->getOffset()); }
public function test_atOffset() { $t = LocalDateTime::of(2008, 6, 30, 11, 30); $this->assertEquals($t->atOffset(self::OFFSET_PTWO()), OffsetDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::OFFSET_PTWO())); }
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]]; }
/** * @dataProvider data_print_localized */ public function test_print_localized(TextStyle $style, LocalDateTime $ldt, ZoneOffset $offset, $expected) { $odt = OffsetDateTime::ofDateTime($ldt, $offset); $zdt = $ldt->atZone($offset); $f = (new DateTimeFormatterBuilder())->appendLocalizedOffset($style)->toFormatter(); $this->assertEquals($f->format($odt), $expected); $this->assertEquals($f->format($zdt), $expected); $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset); if ($style == TextStyle::FULL()) { $f = (new DateTimeFormatterBuilder())->appendPattern("ZZZZ")->toFormatter(); $this->assertEquals($f->format($odt), $expected); $this->assertEquals($f->format($zdt), $expected); $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset); $f = (new DateTimeFormatterBuilder())->appendPattern("OOOO")->toFormatter(); $this->assertEquals($f->format($odt), $expected); $this->assertEquals($f->format($zdt), $expected); $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset); } if ($style == TextStyle::SHORT()) { $f = (new DateTimeFormatterBuilder())->appendPattern("O")->toFormatter(); $this->assertEquals($f->format($odt), $expected); $this->assertEquals($f->format($zdt), $expected); $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset); } }
/** * Combines this date-time with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this date-time at the specified offset. * All possible combinations of date-time and offset are valid. * * @param ZoneOffset $offset the offset to combine with, not null * @return OffsetDateTime the offset date-time formed from this date-time and the specified offset, not null */ public function atOffset(ZoneOffset $offset) { return OffsetDateTime::ofDateTime($this, $offset); }
/** * Converts this date-time to an {@code OffsetDateTime}. * <p> * This creates an offset date-time using the local date-time and offset. * The zone ID is ignored. * * @return OffsetDateTime an offset date-time representing the same local date-time and offset, not null */ public function toOffsetDateTime() { return OffsetDateTime::ofDateTime($this->dateTime, $this->offset); }