public function test_parse_leapSecond() { $expected = OffsetDateTime::of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset::UTC())->toInstant(); $f = (new DateTimeFormatterBuilder())->appendInstant4(-1)->toFormatter(); foreach (ResolverStyle::values() as $style) { $pared = $f->withResolverStyle($style)->parse("1970-02-03T23:59:60.123456789Z"); $this->assertEquals($pared->query(Instant::fromQuery()), $expected); $this->assertEquals($pared->query(DateTimeFormatter::parsedExcessDays()), Period::ZERO()); $this->assertEquals($pared->query(DateTimeFormatter::parsedLeapSecond()), true); } }
/** * @dataProvider data_resolveClockHourOfDay */ public function test_resolveClockHourOfDay(ResolverStyle $style, $value, $expectedHour, $expectedDays) { $str = strval($value); $f = (new DateTimeFormatterBuilder())->appendValue(ChronoField::CLOCK_HOUR_OF_DAY())->toFormatter(); if ($expectedHour !== null) { $accessor = $f->withResolverStyle($style)->parse($str); $this->assertEquals($accessor->query(TemporalQueries::localDate()), null); $this->assertEquals($accessor->query(TemporalQueries::localTime()), LocalTime::of($expectedHour, 0)); $this->assertEquals($accessor->query(DateTimeFormatter::parsedExcessDays()), Period::ofDays($expectedDays)); } else { try { $f->withResolverStyle($style)->parse($str); $this->fail(); } catch (DateTimeParseException $ex) { // $expected } } }