/** * @dataProvider data_resolveMinuteOfDay */ public function test_resolveMinuteOfDay(ResolverStyle $style, $value, $expectedMinute, $expectedDays) { $str = strval($value); $f = (new DateTimeFormatterBuilder())->appendValue(ChronoField::MINUTE_OF_DAY())->toFormatter(); if ($expectedMinute !== null) { $accessor = $f->withResolverStyle($style)->parse($str); $this->assertEquals($accessor->query(TemporalQueries::localDate()), null); $this->assertEquals($accessor->query(TemporalQueries::localTime()), LocalTime::ofSecondOfDay($expectedMinute * 60)); $this->assertEquals($accessor->query(DateTimeFormatter::parsedExcessDays()), Period::ofDays($expectedDays)); } else { try { $f->withResolverStyle($style)->parse($str); $this->fail(); } catch (DateTimeParseException $ex) { // $expected } } }
/** * Parses a Rule line. * * @param $s \CachingIterator the line scanner, not null * @param TZDBMonthDayTime $mdt the object to parse into, not null */ private function parseMonthDayTime(\CachingIterator $s, TZDBMonthDayTime $mdt) { $mdt->month = $this->parseMonth($s); if ($s->hasNext()) { $s->next(); $dayRule = $s->current(); if (strpos($dayRule, "last") === 0) { $mdt->dayOfMonth = -1; $mdt->dayOfWeek = $this->parseDayOfWeek(substr($dayRule, 4)); $mdt->adjustForwards = false; } else { $index = strpos($dayRule, ">="); if ($index > 0) { $mdt->dayOfWeek = $this->parseDayOfWeek(substr($dayRule, 0, $index)); $dayRule = substr($dayRule, $index + 2); } else { $index = strpos($dayRule, "<="); if ($index > 0) { $mdt->dayOfWeek = $this->parseDayOfWeek(substr($dayRule, 0, $index)); $mdt->adjustForwards = false; $dayRule = substr($dayRule, $index + 2); } } $mdt->dayOfMonth = \intval($dayRule); } if ($s->hasNext()) { $s->next(); $timeStr = $s->current(); $secsOfDay = $this->parseSecs($timeStr); if ($secsOfDay === 86400) { $mdt->endOfDay = true; $secsOfDay = 0; } $mdt->time = LocalTime::ofSecondOfDay($secsOfDay); $mdt->timeDefinition = $this->parseTimeDefinition($timeStr[strlen($timeStr) - 1]); } } }
/** * @group long */ public function test_toSecondOfDay_fromNanoOfDay_symmetry() { $t = LocalTime::of(0, 0); for ($i = 0; $i < 24 * 60 * 60; $i++) { $this->assertEquals(LocalTime::ofSecondOfDay($t->toSecondOfDay()), $t); $t = $t->plusSeconds(1); } }