/** * @setUp */ public function setUp() { $this->builder = new DateTimeFormatterBuilder(); $this->dta = ZonedDateTime::ofDateTime(LocalDateTime::of(2011, 6, 30, 12, 30, 40, 0), ZoneId::of("Europe/Paris")); $this->locale = Locale::of("en"); $this->decimalStyle = DecimalStyle::STANDARD(); }
public function test_now_ZoneId() { $zone = ZoneId::of("UTC+01:02:03"); $expected = Year::nowOf(Clock::system($zone)); $test = Year::nowIn($zone); for ($i = 0; $i < 100; $i++) { if ($expected->equals($test)) { return; } $expected = Year::nowOf(Clock::system($zone)); $test = Year::nowIn($zone); } $this->assertEquals($test, $expected); }
public function test_adjustInto_ZonedDateTime() { $base = ZoneOffset::ofHoursMinutesSeconds(1, 1, 1); foreach (ZoneId::getAvailableZoneIds() as $zoneId) { //Do not change $offset of ZonedDateTime after adjustInto() $zonedDateTime_target = ZonedDateTime::ofDateAndTime(LocalDate::of(1909, 2, 2), LocalTime::of(10, 10, 10), ZoneId::of($zoneId)); $zonedDateTime_result = $base->adjustInto($zonedDateTime_target); $this->assertEquals($zonedDateTime_target->getOffset(), $zonedDateTime_result->getOffset()); $offsetDateTime_target = $zonedDateTime_target->toOffsetDateTime(); $offsetDateTime_result = $base->adjustInto($offsetDateTime_target); $this->assertEquals($base, $offsetDateTime_result->getOffset()); } }
private static function PARIS() { return ZoneId::of("Europe/Paris"); }
public function test_Apia_jumpForwardOverInternationalDateLine_P12_to_M12() { // transition occurred at 1879-07-04T00:00+12:33:04 $test = $this->pacificApia(); $instantBefore = LocalDate::of(1879, 7, 2)->atStartOfDayWithZone(ZoneOffset::UTC())->toInstant(); $trans = $test->nextTransition($instantBefore); $this->assertEquals($trans->getDateTimeBefore(), LocalDateTime::of(1879, 7, 5, 0, 0)); $this->assertEquals($trans->getDateTimeAfter(), LocalDateTime::of(1879, 7, 4, 0, 0)); $this->assertEquals($trans->isGap(), false); $this->assertEquals($trans->isOverlap(), true); $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHoursMinutesSeconds(+12, 33, 4)), true); $this->assertEquals($trans->isValidOffset(ZoneOffset::ofHoursMinutesSeconds(-11, -26, -56)), true); $this->assertEquals($trans->getDuration(), Duration::ofHours(-24)); $this->assertEquals($trans->getInstant(), LocalDateTime::of(1879, 7, 4, 0, 0)->toInstant(ZoneOffset::ofHoursMinutesSeconds(-11, -26, -56))); $zdt = ZonedDateTime::of(1879, 7, 4, 23, 0, 0, 0, ZoneId::of("Pacific/Apia")); $this->assertEquals($zdt->plusHours(2)->toLocalDateTime(), LocalDateTime::of(1879, 7, 4, 1, 0, 0)); }
public function test_withZone() { $test = $this->fmt; $this->assertEquals($test->getZone(), null); $test = $test->withZone(ZoneId::of("Europe/Paris")); $this->assertEquals($test->getZone(), ZoneId::of("Europe/Paris")); $test = $test->withZone(ZoneOffset::UTC()); $this->assertEquals($test->getZone(), ZoneOffset::UTC()); $test = $test->withZone(null); $this->assertEquals($test->getZone(), null); }
/** * @dataProvider provider_sampleToString */ public function test_toString($y, $o, $d, $h, $m, $s, $n, $zoneId, $expected) { $z = ZonedDateTime::ofDateTime($this->dateTime($y, $o, $d, $h, $m, $s, $n), ZoneId::of($zoneId)); $str = $z->__toString(); $this->assertEquals($str, $expected); }
private static function ZONE_GAZA() { return ZoneId::of("Asia/Gaza"); }
/** * Parse an offset following a prefix and set the ZoneId if it is valid. * To matching the parsing of ZoneId.of the values are not normalized * to ZoneOffsets. * * @param DateTimeParseContext $context the parse context * @param string $text the input text * @param int $prefixPos start of the prefix * @param int $position start of text after the prefix * @param OffsetIdPrinterParser $parser parser for the value after the prefix * @return int the position after the parse */ private function parseOffsetBased(DateTimeParseContext $context, $text, $prefixPos, $position, OffsetIdPrinterParser $parser) { $prefix = strtoupper(substr($text, $prefixPos, $position - $prefixPos)); if ($position >= strlen($text)) { $context->setParsedZone(ZoneId::of($prefix)); return $position; } // '0' or 'Z' after prefix is not part of a valid ZoneId; use bare prefix if ($text[$position] === '0' || $context->charEquals($text[$position], 'Z')) { $context->setParsedZone(ZoneId::of($prefix)); return $position; } $newContext = $context->copy(); $endPos = $parser->parse($newContext, $text, $position); try { if ($endPos < 0) { if ($parser == OffsetIdPrinterParser::INSTANCE_ID_Z()) { return ~$prefixPos; } $context->setParsedZone(ZoneId::of($prefix)); return $position; } $offset = $newContext->getParsed(ChronoField::OFFSET_SECONDS()); $zoneOffset = ZoneOffset::ofTotalSeconds($offset); $context->setParsedZone(ZoneId::ofOffset($prefix, $zoneOffset)); return $endPos; } catch (DateTimeException $dte) { return ~$prefixPos; } }
/** * @dataProvider data_toString */ public function test_toString($id, $expected) { $test = ZoneId::of($id); $this->assertEquals($test->__toString(), $expected); }
/** * @expectedException \Celest\DateTimeParseException */ public function test_fieldResolvesToChronoZonedDateTime_overrideZone_wrongZone() { $zdt = ZonedDateTime::of(2010, 6, 30, 12, 30, 0, 0, self::EUROPE_PARIS()); $f = (new DateTimeFormatterBuilder())->appendValue(new ResolvingField($zdt))->toFormatter(); $f = $f->withZone(ZoneId::of("Europe/London")); $f->parse("1234567890"); }
public function test_get_TzdbFixed() { $test = ZoneId::of("+01:30"); $this->assertEquals($test->getId(), "+01:30"); $this->assertEquals($test->getRules()->isFixedOffset(), true); }
private static function preferred_s() { return [ZoneId::of("CET"), ZoneId::of("Australia/South"), ZoneId::of("Australia/West"), ZoneId::of("Asia/Shanghai")]; }
function data_parseSuccess() { return [["Z", 1, -1, ZoneId::of("Z")], ["UTC", 3, -1, ZoneId::of("UTC")], ["UT", 2, -1, ZoneId::of("UT")], ["GMT", 3, -1, ZoneId::of("GMT")], ["+00:00", 6, -1, ZoneOffset::UTC()], ["UTC+00:00", 9, -1, ZoneId::of("UTC")], ["UT+00:00", 8, -1, ZoneId::of("UT")], ["GMT+00:00", 9, -1, ZoneId::of("GMT")], ["-00:00", 6, -1, ZoneOffset::UTC()], ["UTC-00:00", 9, -1, ZoneId::of("UTC")], ["UT-00:00", 8, -1, ZoneId::of("UT")], ["GMT-00:00", 9, -1, ZoneId::of("GMT")], ["+01:30", 6, -1, ZoneOffset::ofHoursMinutes(1, 30)], ["UTC+01:30", 9, -1, ZoneId::of("UTC+01:30")], ["UT+02:30", 8, -1, ZoneId::of("UT+02:30")], ["GMT+03:30", 9, -1, ZoneId::of("GMT+03:30")], ["-01:30", 6, -1, ZoneOffset::ofHoursMinutes(-1, -30)], ["UTC-01:30", 9, -1, ZoneId::of("UTC-01:30")], ["UT-02:30", 8, -1, ZoneId::of("UT-02:30")], ["GMT-03:30", 9, -1, ZoneId::of("GMT-03:30")], ["UTC-01:WW", 3, -1, ZoneId::of("UTC")], ["UT-02:WW", 2, -1, ZoneId::of("UT")], ["GMT-03:WW", 3, -1, ZoneId::of("GMT")], ["Z0", 1, -1, ZoneOffset::UTC()], ["UTC1", 3, -1, ZoneId::of("UTC")], ["UTCZ", 3, -1, ZoneId::of("UTC")], ["UTZ", 2, -1, ZoneId::of("UT")], ["GMTZ", 3, -1, ZoneId::of("GMT")], ["UTC0", 3, -1, ZoneId::of("UTC")], ["UT0", 2, -1, ZoneId::of("UT")], ["", 0, 0, null], ["A", 0, 0, null], ["UZ", 0, 0, null], ["GMA", 0, 0, null], ["0", 0, 0, null], ["+", 0, 0, null], ["-", 0, 0, null], ["Europe/London", 13, -1, ZoneId::of("Europe/London")], ["America/New_York", 16, -1, ZoneId::of("America/New_York")], ["America/Bogusville", 0, 0, null]]; }
/** * @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); } }