public function data_text() { return [[ChronoField::DAY_OF_WEEK(), 1, TextStyle::SHORT(), self::enUS(), "Mon"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::SHORT(), self::enUS(), "Tue"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::SHORT(), self::enUS(), "Wed"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::SHORT(), self::enUS(), "Thu"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::SHORT(), self::enUS(), "Fri"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::SHORT(), self::enUS(), "Sat"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::SHORT(), self::enUS(), "Sun"], [ChronoField::DAY_OF_WEEK(), 1, TextStyle::SHORT(), self::ptBR(), "seg"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::SHORT(), self::ptBR(), "ter"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::SHORT(), self::ptBR(), "qua"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::SHORT(), self::ptBR(), "qui"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::SHORT(), self::ptBR(), "sex"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::SHORT(), self::ptBR(), "sáb"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::SHORT(), self::ptBR(), "dom"], [ChronoField::DAY_OF_WEEK(), 1, TextStyle::FULL(), self::enUS(), "Monday"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::FULL(), self::enUS(), "Tuesday"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::FULL(), self::enUS(), "Wednesday"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::FULL(), self::enUS(), "Thursday"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::FULL(), self::enUS(), "Friday"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::FULL(), self::enUS(), "Saturday"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::FULL(), self::enUS(), "Sunday"], [ChronoField::DAY_OF_WEEK(), 1, TextStyle::FULL(), self::ptBR(), "segunda-feira"], [ChronoField::DAY_OF_WEEK(), 2, TextStyle::FULL(), self::ptBR(), "terça-feira"], [ChronoField::DAY_OF_WEEK(), 3, TextStyle::FULL(), self::ptBR(), "quarta-feira"], [ChronoField::DAY_OF_WEEK(), 4, TextStyle::FULL(), self::ptBR(), "quinta-feira"], [ChronoField::DAY_OF_WEEK(), 5, TextStyle::FULL(), self::ptBR(), "sexta-feira"], [ChronoField::DAY_OF_WEEK(), 6, TextStyle::FULL(), self::ptBR(), "sábado"], [ChronoField::DAY_OF_WEEK(), 7, TextStyle::FULL(), self::ptBR(), "domingo"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::SHORT(), self::enUS(), "Jan"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::SHORT(), self::enUS(), "Feb"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::SHORT(), self::enUS(), "Mar"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::SHORT(), self::enUS(), "Apr"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::SHORT(), self::enUS(), "May"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::SHORT(), self::enUS(), "Jun"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::SHORT(), self::enUS(), "Jul"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::SHORT(), self::enUS(), "Aug"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::SHORT(), self::enUS(), "Sep"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::SHORT(), self::enUS(), "Oct"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::SHORT(), self::enUS(), "Nov"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::SHORT(), self::enUS(), "Dec"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::SHORT(), self::ptBR(), "jan"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::SHORT(), self::ptBR(), "fev"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::SHORT(), self::ptBR(), "mar"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::SHORT(), self::ptBR(), "abr"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::SHORT(), self::ptBR(), "mai"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::SHORT(), self::ptBR(), "jun"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::SHORT(), self::ptBR(), "jul"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::SHORT(), self::ptBR(), "ago"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::SHORT(), self::ptBR(), "set"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::SHORT(), self::ptBR(), "out"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::SHORT(), self::ptBR(), "nov"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::SHORT(), self::ptBR(), "dez"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::FULL(), self::enUS(), "January"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::FULL(), self::enUS(), "February"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::FULL(), self::enUS(), "March"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::FULL(), self::enUS(), "April"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::FULL(), self::enUS(), "May"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::FULL(), self::enUS(), "June"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::FULL(), self::enUS(), "July"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::FULL(), self::enUS(), "August"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::FULL(), self::enUS(), "September"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::FULL(), self::enUS(), "October"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::FULL(), self::enUS(), "November"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::FULL(), self::enUS(), "December"], [ChronoField::MONTH_OF_YEAR(), 1, TextStyle::FULL(), self::ptBR(), "janeiro"], [ChronoField::MONTH_OF_YEAR(), 2, TextStyle::FULL(), self::ptBR(), "fevereiro"], [ChronoField::MONTH_OF_YEAR(), 3, TextStyle::FULL(), self::ptBR(), "março"], [ChronoField::MONTH_OF_YEAR(), 4, TextStyle::FULL(), self::ptBR(), "abril"], [ChronoField::MONTH_OF_YEAR(), 5, TextStyle::FULL(), self::ptBR(), "maio"], [ChronoField::MONTH_OF_YEAR(), 6, TextStyle::FULL(), self::ptBR(), "junho"], [ChronoField::MONTH_OF_YEAR(), 7, TextStyle::FULL(), self::ptBR(), "julho"], [ChronoField::MONTH_OF_YEAR(), 8, TextStyle::FULL(), self::ptBR(), "agosto"], [ChronoField::MONTH_OF_YEAR(), 9, TextStyle::FULL(), self::ptBR(), "setembro"], [ChronoField::MONTH_OF_YEAR(), 10, TextStyle::FULL(), self::ptBR(), "outubro"], [ChronoField::MONTH_OF_YEAR(), 11, TextStyle::FULL(), self::ptBR(), "novembro"], [ChronoField::MONTH_OF_YEAR(), 12, TextStyle::FULL(), self::ptBR(), "dezembro"], [ChronoField::AMPM_OF_DAY(), 0, TextStyle::SHORT(), self::enUS(), "AM"], [ChronoField::AMPM_OF_DAY(), 1, TextStyle::SHORT(), self::enUS(), "PM"]]; }
public function test_getLong_TemporalField() { $test = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 12, 30, 40, 987654321), self::ZONE_0100()); $this->assertEquals($test->getLong(CF::YEAR()), 2008); $this->assertEquals($test->getLong(CF::MONTH_OF_YEAR()), 6); $this->assertEquals($test->getLong(CF::DAY_OF_MONTH()), 30); $this->assertEquals($test->getLong(CF::DAY_OF_WEEK()), 1); $this->assertEquals($test->getLong(CF::DAY_OF_YEAR()), 182); $this->assertEquals($test->getLong(CF::HOUR_OF_DAY()), 12); $this->assertEquals($test->getLong(CF::MINUTE_OF_HOUR()), 30); $this->assertEquals($test->getLong(CF::SECOND_OF_MINUTE()), 40); $this->assertEquals($test->getLong(CF::NANO_OF_SECOND()), 987654321); $this->assertEquals($test->getLong(CF::HOUR_OF_AMPM()), 0); $this->assertEquals($test->getLong(CF::AMPM_OF_DAY()), 1); $this->assertEquals($test->getLong(CF::OFFSET_SECONDS()), 3600); $this->assertEquals($test->getLong(CF::INSTANT_SECONDS()), $test->toEpochSecond()); }
/** * Returns a copy of this time with the specified field set to a new value. * <p> * This returns a {@code LocalTime}, based on this one, with the value * for the specified field changed. * This can be used to change any supported field, such as the hour, minute or second. * If it is not possible to set the value, because the field is not supported or for * some other reason, an exception is thrown. * <p> * If the field is a {@link ChronoField} then the adjustment is implemented here. * The supported fields behave as follows: * <ul> * <li>{@code NANO_OF_SECOND} - * Returns a {@code LocalTime} with the specified nano-of-second. * The hour, minute and second will be unchanged. * <li>{@code NANO_OF_DAY} - * Returns a {@code LocalTime} with the specified nano-of-day. * This completely replaces the time and is equivalent to {@link #ofNanoOfDay(long)}. * <li>{@code MICRO_OF_SECOND} - * Returns a {@code LocalTime} with the nano-of-second replaced by the specified * micro-of-second multiplied by 1,000. * The hour, minute and second will be unchanged. * <li>{@code MICRO_OF_DAY} - * Returns a {@code LocalTime} with the specified micro-of-day. * This completely replaces the time and is equivalent to using {@link #ofNanoOfDay(long)} * with the micro-of-day multiplied by 1,000. * <li>{@code MILLI_OF_SECOND} - * Returns a {@code LocalTime} with the nano-of-second replaced by the specified * milli-of-second multiplied by 1,000,000. * The hour, minute and second will be unchanged. * <li>{@code MILLI_OF_DAY} - * Returns a {@code LocalTime} with the specified milli-of-day. * This completely replaces the time and is equivalent to using {@link #ofNanoOfDay(long)} * with the milli-of-day multiplied by 1,000,000. * <li>{@code SECOND_OF_MINUTE} - * Returns a {@code LocalTime} with the specified second-of-minute. * The hour, minute and nano-of-second will be unchanged. * <li>{@code SECOND_OF_DAY} - * Returns a {@code LocalTime} with the specified second-of-day. * The nano-of-second will be unchanged. * <li>{@code MINUTE_OF_HOUR} - * Returns a {@code LocalTime} with the specified minute-of-hour. * The hour, second-of-minute and nano-of-second will be unchanged. * <li>{@code MINUTE_OF_DAY} - * Returns a {@code LocalTime} with the specified minute-of-day. * The second-of-minute and nano-of-second will be unchanged. * <li>{@code HOUR_OF_AMPM} - * Returns a {@code LocalTime} with the specified hour-of-am-pm. * The AM/PM, minute-of-hour, second-of-minute and nano-of-second will be unchanged. * <li>{@code CLOCK_HOUR_OF_AMPM} - * Returns a {@code LocalTime} with the specified clock-hour-of-am-pm. * The AM/PM, minute-of-hour, second-of-minute and nano-of-second will be unchanged. * <li>{@code HOUR_OF_DAY} - * Returns a {@code LocalTime} with the specified hour-of-day. * The minute-of-hour, second-of-minute and nano-of-second will be unchanged. * <li>{@code CLOCK_HOUR_OF_DAY} - * Returns a {@code LocalTime} with the specified clock-hour-of-day. * The minute-of-hour, second-of-minute and nano-of-second will be unchanged. * <li>{@code AMPM_OF_DAY} - * Returns a {@code LocalTime} with the specified AM/PM. * The hour-of-am-pm, minute-of-hour, second-of-minute and nano-of-second will be unchanged. * </ul> * <p> * In all cases, if the new value is outside the valid range of values for the field * then a {@code DateTimeException} will be thrown. * <p> * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. * <p> * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)} * passing {@code this} as the argument. In this case, the field determines * whether and how to adjust the instant. * <p> * This instance is immutable and unaffected by this method call. * * @param TemporalField $field the field to set in the result, not null * @param int $newValue the new value of the field in the result * @return LocalTime a {@code LocalTime} based on {@code this} with the specified field set, not null * @throws DateTimeException if the field cannot be set * @throws UnsupportedTemporalTypeException if the field is not supported * @throws ArithmeticException if numeric overflow occurs */ public function with(TemporalField $field, $newValue) { if ($field instanceof ChronoField) { $f = $field; $f->checkValidValue($newValue); switch ($f) { case ChronoField::NANO_OF_SECOND(): return $this->withNano((int) $newValue); case ChronoField::NANO_OF_DAY(): return self::ofNanoOfDay($newValue); case ChronoField::MICRO_OF_SECOND(): return $this->withNano((int) $newValue * 1000); case ChronoField::MICRO_OF_DAY(): return self::ofNanoOfDay($newValue * 1000); case ChronoField::MILLI_OF_SECOND(): return $this->withNano((int) $newValue * 1000000); case ChronoField::MILLI_OF_DAY(): return self::ofNanoOfDay($newValue * 1000000); case ChronoField::SECOND_OF_MINUTE(): return $this->withSecond((int) $newValue); case ChronoField::SECOND_OF_DAY(): return $this->plusSeconds($newValue - $this->toSecondOfDay()); case ChronoField::MINUTE_OF_HOUR(): return $this->withMinute((int) $newValue); case ChronoField::MINUTE_OF_DAY(): return $this->plusMinutes($newValue - ($this->hour * 60 + $this->minute)); case ChronoField::HOUR_OF_AMPM(): return $this->plusHours($newValue - $this->hour % 12); case ChronoField::CLOCK_HOUR_OF_AMPM(): return $this->plusHours(($newValue === 12 ? 0 : $newValue) - $this->hour % 12); case ChronoField::HOUR_OF_DAY(): return $this->withHour((int) $newValue); case ChronoField::CLOCK_HOUR_OF_DAY(): return $this->withHour((int) ($newValue === 24 ? 0 : $newValue)); case ChronoField::AMPM_OF_DAY(): return $this->plusHours(($newValue - Math::div($this->hour, 12)) * 12); } throw new UnsupportedTemporalTypeException("Unsupported field: " . $field); } return $field->adjustInto($this, $newValue); }
public function test_isSupported_TemporalField() { // TODO $this->assertEquals(self::TEST_2008_06()->isSupported(null), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::NANO_OF_SECOND()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::NANO_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MICRO_OF_SECOND()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MICRO_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MILLI_OF_SECOND()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MILLI_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::SECOND_OF_MINUTE()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::SECOND_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MINUTE_OF_HOUR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MINUTE_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::HOUR_OF_AMPM()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::CLOCK_HOUR_OF_AMPM()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::HOUR_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::CLOCK_HOUR_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::AMPM_OF_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::DAY_OF_WEEK()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_DAY_OF_WEEK_IN_MONTH()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_DAY_OF_WEEK_IN_YEAR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::DAY_OF_MONTH()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::DAY_OF_YEAR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::EPOCH_DAY()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_WEEK_OF_MONTH()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ALIGNED_WEEK_OF_YEAR()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::MONTH_OF_YEAR()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::PROLEPTIC_MONTH()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::YEAR()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::YEAR_OF_ERA()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::ERA()), true); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::INSTANT_SECONDS()), false); $this->assertEquals(self::TEST_2008_06()->isSupported(CF::OFFSET_SECONDS()), false); }
public function test_getLong_TemporalField() { $test = LocalDateTime::of(2008, 6, 30, 12, 30, 40, 987654321); $this->assertEquals($test->getLong(CF::YEAR()), 2008); $this->assertEquals($test->getLong(CF::MONTH_OF_YEAR()), 6); $this->assertEquals($test->getLong(CF::DAY_OF_MONTH()), 30); $this->assertEquals($test->getLong(CF::DAY_OF_WEEK()), 1); $this->assertEquals($test->getLong(CF::DAY_OF_YEAR()), 182); $this->assertEquals($test->getLong(CF::HOUR_OF_DAY()), 12); $this->assertEquals($test->getLong(CF::MINUTE_OF_HOUR()), 30); $this->assertEquals($test->getLong(CF::SECOND_OF_MINUTE()), 40); $this->assertEquals($test->getLong(CF::NANO_OF_SECOND()), 987654321); $this->assertEquals($test->getLong(CF::HOUR_OF_AMPM()), 0); $this->assertEquals($test->getLong(CF::AMPM_OF_DAY()), 1); }
/** * @expectedException \Celest\DateTimeException */ public function test_with_TemporalField_long_timeField() { self::TEST_2007_07_15()->with(CF::AMPM_OF_DAY(), 1); }
function data_fieldBased() { return [[CF::DAY_OF_WEEK(), true, false], [CF::ALIGNED_DAY_OF_WEEK_IN_MONTH(), true, false], [CF::ALIGNED_DAY_OF_WEEK_IN_YEAR(), true, false], [CF::DAY_OF_MONTH(), true, false], [CF::DAY_OF_YEAR(), true, false], [CF::EPOCH_DAY(), true, false], [CF::ALIGNED_WEEK_OF_MONTH(), true, false], [CF::ALIGNED_WEEK_OF_YEAR(), true, false], [CF::MONTH_OF_YEAR(), true, false], [CF::PROLEPTIC_MONTH(), true, false], [CF::YEAR_OF_ERA(), true, false], [CF::YEAR(), true, false], [CF::ERA(), true, false], [CF::AMPM_OF_DAY(), false, true], [CF::CLOCK_HOUR_OF_DAY(), false, true], [CF::HOUR_OF_DAY(), false, true], [CF::CLOCK_HOUR_OF_AMPM(), false, true], [CF::HOUR_OF_AMPM(), false, true], [CF::MINUTE_OF_DAY(), false, true], [CF::MINUTE_OF_HOUR(), false, true], [CF::SECOND_OF_DAY(), false, true], [CF::SECOND_OF_MINUTE(), false, true], [CF::MILLI_OF_DAY(), false, true], [CF::MILLI_OF_SECOND(), false, true], [CF::MICRO_OF_DAY(), false, true], [CF::MICRO_OF_SECOND(), false, true], [CF::NANO_OF_DAY(), false, true], [CF::NANO_OF_SECOND(), false, true]]; }
function data_localeDisplayNames() { return [[ChronoField::ERA()], [ChronoField::YEAR()], [ChronoField::MONTH_OF_YEAR()], [ChronoField::DAY_OF_WEEK()], [ChronoField::DAY_OF_MONTH()], [ChronoField::AMPM_OF_DAY()], [ChronoField::HOUR_OF_DAY()], [ChronoField::MINUTE_OF_HOUR()], [ChronoField::SECOND_OF_MINUTE()]]; }
private function resolveTimeFields() { // simplify fields if ($this->fieldValues->has(CF::CLOCK_HOUR_OF_DAY())) { // lenient allows anything, smart allows 0-24, strict allows 1-24 $ch = $this->fieldValues->remove(CF::CLOCK_HOUR_OF_DAY()); if ($this->resolverStyle == ResolverStyle::STRICT() || $this->resolverStyle == ResolverStyle::SMART() && $ch != 0) { CF::CLOCK_HOUR_OF_DAY()->checkValidValue($ch); } $this->updateCheckConflict3(CF::CLOCK_HOUR_OF_DAY(), CF::HOUR_OF_DAY(), $ch == 24 ? 0 : $ch); } if ($this->fieldValues->has(CF::CLOCK_HOUR_OF_AMPM())) { // lenient allows anything, smart allows 0-12, strict allows 1-12 $ch = $this->fieldValues->remove(CF::CLOCK_HOUR_OF_AMPM()); if ($this->resolverStyle == ResolverStyle::STRICT() || $this->resolverStyle == ResolverStyle::SMART() && $ch != 0) { CF::CLOCK_HOUR_OF_AMPM()->checkValidValue($ch); } $this->updateCheckConflict3(CF::CLOCK_HOUR_OF_AMPM(), CF::HOUR_OF_AMPM(), $ch == 12 ? 0 : $ch); } if ($this->fieldValues->has(CF::AMPM_OF_DAY()) && $this->fieldValues->has(CF::HOUR_OF_AMPM())) { $ap = $this->fieldValues->remove(CF::AMPM_OF_DAY()); $hap = $this->fieldValues->remove(CF::HOUR_OF_AMPM()); if ($this->resolverStyle == ResolverStyle::LENIENT()) { $this->updateCheckConflict3(CF::AMPM_OF_DAY(), CF::HOUR_OF_DAY(), Math::addExact(Math::multiplyExact($ap, 12), $hap)); } else { // STRICT or SMART CF::AMPM_OF_DAY()->checkValidValue($ap); CF::HOUR_OF_AMPM()->checkValidValue($ap); $this->updateCheckConflict3(CF::AMPM_OF_DAY(), CF::HOUR_OF_DAY(), $ap * 12 + $hap); } } if ($this->fieldValues->has(CF::NANO_OF_DAY())) { $nod = $this->fieldValues->remove(CF::NANO_OF_DAY()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::NANO_OF_DAY()->checkValidValue($nod); } $this->updateCheckConflict3(CF::NANO_OF_DAY(), CF::HOUR_OF_DAY(), Math::div($nod, 3600000000000)); $this->updateCheckConflict3(CF::NANO_OF_DAY(), CF::MINUTE_OF_HOUR(), Math::div($nod, 60000000000) % 60); $this->updateCheckConflict3(CF::NANO_OF_DAY(), CF::SECOND_OF_MINUTE(), Math::div($nod, 1000000000) % 60); $this->updateCheckConflict3(CF::NANO_OF_DAY(), CF::NANO_OF_SECOND(), $nod % 1000000000); } if ($this->fieldValues->has(CF::MICRO_OF_DAY())) { $cod = $this->fieldValues->remove(CF::MICRO_OF_DAY()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::MICRO_OF_DAY()->checkValidValue($cod); } $this->updateCheckConflict3(CF::MICRO_OF_DAY(), CF::SECOND_OF_DAY(), Math::div($cod, 1000000)); $this->updateCheckConflict3(CF::MICRO_OF_DAY(), CF::MICRO_OF_SECOND(), $cod % 1000000); } if ($this->fieldValues->has(CF::MILLI_OF_DAY())) { $lod = $this->fieldValues->remove(CF::MILLI_OF_DAY()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::MILLI_OF_DAY()->checkValidValue($lod); } $this->updateCheckConflict3(CF::MILLI_OF_DAY(), CF::SECOND_OF_DAY(), Math::div($lod, 1000)); $this->updateCheckConflict3(CF::MILLI_OF_DAY(), CF::MILLI_OF_SECOND(), $lod % 1000); } if ($this->fieldValues->has(CF::SECOND_OF_DAY())) { $sod = $this->fieldValues->remove(CF::SECOND_OF_DAY()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::SECOND_OF_DAY()->checkValidValue($sod); } $this->updateCheckConflict3(CF::SECOND_OF_DAY(), CF::HOUR_OF_DAY(), Math::div($sod, 3600)); $this->updateCheckConflict3(CF::SECOND_OF_DAY(), CF::MINUTE_OF_HOUR(), Math::div($sod, 60) % 60); $this->updateCheckConflict3(CF::SECOND_OF_DAY(), CF::SECOND_OF_MINUTE(), $sod % 60); } if ($this->fieldValues->has(CF::MINUTE_OF_DAY())) { $mod = $this->fieldValues->remove(CF::MINUTE_OF_DAY()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::MINUTE_OF_DAY()->checkValidValue($mod); } $this->updateCheckConflict3(CF::MINUTE_OF_DAY(), CF::HOUR_OF_DAY(), Math::div($mod, 60)); $this->updateCheckConflict3(CF::MINUTE_OF_DAY(), CF::MINUTE_OF_HOUR(), $mod % 60); } // combine partial second fields strictly, leaving lenient expansion to later if ($this->fieldValues->has(CF::NANO_OF_SECOND())) { $nos = $this->fieldValues->get(CF::NANO_OF_SECOND()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::NANO_OF_SECOND()->checkValidValue($nos); } if ($this->fieldValues->has(CF::MICRO_OF_SECOND())) { $cos = $this->fieldValues->remove(CF::MICRO_OF_SECOND()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::MICRO_OF_SECOND()->checkValidValue($cos); } $nos = $cos * 1000 + $nos % 1000; $this->updateCheckConflict3(CF::MICRO_OF_SECOND(), CF::NANO_OF_SECOND(), $nos); } if ($this->fieldValues->has(CF::MILLI_OF_SECOND())) { $los = $this->fieldValues->remove(CF::MILLI_OF_SECOND()); if ($this->resolverStyle != ResolverStyle::LENIENT()) { CF::MILLI_OF_SECOND()->checkValidValue($los); } $this->updateCheckConflict3(CF::MILLI_OF_SECOND(), CF::NANO_OF_SECOND(), $los * 1000000 + $nos % 1000000); } } // convert to time if all four fields available (optimization) if ($this->fieldValues->has(CF::HOUR_OF_DAY()) && $this->fieldValues->has(CF::MINUTE_OF_HOUR()) && $this->fieldValues->has(CF::SECOND_OF_MINUTE()) && $this->fieldValues->has(CF::NANO_OF_SECOND())) { $hod = $this->fieldValues->remove(CF::HOUR_OF_DAY()); $moh = $this->fieldValues->remove(CF::MINUTE_OF_HOUR()); $som = $this->fieldValues->remove(CF::SECOND_OF_MINUTE()); $nos = $this->fieldValues->remove(CF::NANO_OF_SECOND()); $this->resolveTime($hod, $moh, $som, $nos); } }
/** * @dataProvider data_resolveAmPm */ public function test_resolveAmPm(ResolverStyle $style, $value, $expectedValue) { $str = strval($value); $f = (new DateTimeFormatterBuilder())->appendValue(ChronoField::AMPM_OF_DAY())->toFormatter(); if ($expectedValue !== null) { $accessor = $f->withResolverStyle($style)->parse($str); $this->assertEquals($accessor->query(TemporalQueries::localDate()), null); $this->assertEquals($accessor->query(TemporalQueries::localTime()), null); $this->assertEquals($accessor->isSupported(ChronoField::AMPM_OF_DAY()), true); $this->assertEquals($accessor->getLong(ChronoField::AMPM_OF_DAY()), $expectedValue); } else { try { $f->withResolverStyle($style)->parse($str); $this->fail(); } catch (DateTimeParseException $ex) { // $expected } } }
/** * Gets an iterator of text to field for the specified field, locale and style * for the purpose of parsing. * <p> * The iterator must be returned in order from the longest text to the shortest. * <p> * The null return value should be used if there is no applicable parsable text, or * if the text would be a numeric representation of the value. * Text can only be parsed if all the values for that field-style-locale combination are unique. * * @param TemporalField $field the field to get text for, not null * @param TextStyle $style the style to get text for, null for all parsable text * @param Locale $locale the locale to get text for, not null * @return array the iterator of text to field pairs, in order from longest text to shortest text, * null if the field or style is not parsable */ public function getTextIterator(TemporalField $field, $style, Locale $locale) { $values = null; if ($field == ChronoField::DAY_OF_WEEK()) { $values = self::tryFetchStyleValues('dayNames', $style, $locale, function ($i) { return $i === 0 ? 7 : $i; }); } if ($field == ChronoField::MONTH_OF_YEAR()) { $values = self::tryFetchStyleValues('monthNames', $style, $locale, function ($i) { return $i + 1; }); } if ($field == IsoFields::QUARTER_OF_YEAR()) { $values = self::tryFetchStyleValues('quarters', $style, $locale, function ($i) { return $i + 1; }); } if ($field == ChronoField::AMPM_OF_DAY()) { $values = self::tryFetchStyleValues('AmPmMarkers', $style, $locale, function ($i) { return $i; }); } if ($values === null) { return null; } \uksort($values, function ($a, $b) { return strlen($b) - strlen($a); }); return $values; }
function data_withTemporalField_outOfRange() { return [[CF::NANO_OF_SECOND(), $this->time(0, 0, 0, 0), CF::NANO_OF_SECOND()->range()->getMinimum() - 1], [CF::NANO_OF_SECOND(), $this->time(0, 0, 0, 0), CF::NANO_OF_SECOND()->range()->getMaximum() + 1], [CF::NANO_OF_DAY(), $this->time(0, 0, 0, 0), CF::NANO_OF_DAY()->range()->getMinimum() - 1], [CF::NANO_OF_DAY(), $this->time(0, 0, 0, 0), CF::NANO_OF_DAY()->range()->getMaximum() + 1], [CF::MICRO_OF_SECOND(), $this->time(0, 0, 0, 0), CF::MICRO_OF_SECOND()->range()->getMinimum() - 1], [CF::MICRO_OF_SECOND(), $this->time(0, 0, 0, 0), CF::MICRO_OF_SECOND()->range()->getMaximum() + 1], [CF::MICRO_OF_DAY(), $this->time(0, 0, 0, 0), CF::MICRO_OF_DAY()->range()->getMinimum() - 1], [CF::MICRO_OF_DAY(), $this->time(0, 0, 0, 0), CF::MICRO_OF_DAY()->range()->getMaximum() + 1], [CF::MILLI_OF_SECOND(), $this->time(0, 0, 0, 0), CF::MILLI_OF_SECOND()->range()->getMinimum() - 1], [CF::MILLI_OF_SECOND(), $this->time(0, 0, 0, 0), CF::MILLI_OF_SECOND()->range()->getMaximum() + 1], [CF::MILLI_OF_DAY(), $this->time(0, 0, 0, 0), CF::MILLI_OF_DAY()->range()->getMinimum() - 1], [CF::MILLI_OF_DAY(), $this->time(0, 0, 0, 0), CF::MILLI_OF_DAY()->range()->getMaximum() + 1], [CF::SECOND_OF_MINUTE(), $this->time(0, 0, 0, 0), CF::SECOND_OF_MINUTE()->range()->getMinimum() - 1], [CF::SECOND_OF_MINUTE(), $this->time(0, 0, 0, 0), CF::SECOND_OF_MINUTE()->range()->getMaximum() + 1], [CF::SECOND_OF_DAY(), $this->time(0, 0, 0, 0), CF::SECOND_OF_DAY()->range()->getMinimum() - 1], [CF::SECOND_OF_DAY(), $this->time(0, 0, 0, 0), CF::SECOND_OF_DAY()->range()->getMaximum() + 1], [CF::MINUTE_OF_HOUR(), $this->time(0, 0, 0, 0), CF::MINUTE_OF_HOUR()->range()->getMinimum() - 1], [CF::MINUTE_OF_HOUR(), $this->time(0, 0, 0, 0), CF::MINUTE_OF_HOUR()->range()->getMaximum() + 1], [CF::MINUTE_OF_DAY(), $this->time(0, 0, 0, 0), CF::MINUTE_OF_DAY()->range()->getMinimum() - 1], [CF::MINUTE_OF_DAY(), $this->time(0, 0, 0, 0), CF::MINUTE_OF_DAY()->range()->getMaximum() + 1], [CF::HOUR_OF_AMPM(), $this->time(0, 0, 0, 0), CF::HOUR_OF_AMPM()->range()->getMinimum() - 1], [CF::HOUR_OF_AMPM(), $this->time(0, 0, 0, 0), CF::HOUR_OF_AMPM()->range()->getMaximum() + 1], [CF::CLOCK_HOUR_OF_AMPM(), $this->time(0, 0, 0, 0), CF::CLOCK_HOUR_OF_AMPM()->range()->getMinimum() - 1], [CF::CLOCK_HOUR_OF_AMPM(), $this->time(0, 0, 0, 0), CF::CLOCK_HOUR_OF_AMPM()->range()->getMaximum() + 1], [CF::HOUR_OF_DAY(), $this->time(0, 0, 0, 0), CF::HOUR_OF_DAY()->range()->getMinimum() - 1], [CF::HOUR_OF_DAY(), $this->time(0, 0, 0, 0), CF::HOUR_OF_DAY()->range()->getMaximum() + 1], [CF::CLOCK_HOUR_OF_DAY(), $this->time(0, 0, 0, 0), CF::CLOCK_HOUR_OF_DAY()->range()->getMinimum() - 1], [CF::CLOCK_HOUR_OF_DAY(), $this->time(0, 0, 0, 0), CF::CLOCK_HOUR_OF_DAY()->range()->getMaximum() + 1], [CF::AMPM_OF_DAY(), $this->time(0, 0, 0, 0), CF::AMPM_OF_DAY()->range()->getMinimum() - 1], [CF::AMPM_OF_DAY(), $this->time(0, 0, 0, 0), CF::AMPM_OF_DAY()->range()->getMaximum() + 1]]; }
public function test_with_TemporalField() { $test = OffsetTime::of(12, 30, 40, 987654321, self::OFFSET_PONE()); $this->assertEquals($test->with(CF::HOUR_OF_DAY(), 15), OffsetTime::of(15, 30, 40, 987654321, self::OFFSET_PONE())); $this->assertEquals($test->with(CF::MINUTE_OF_HOUR(), 50), OffsetTime::of(12, 50, 40, 987654321, self::OFFSET_PONE())); $this->assertEquals($test->with(CF::SECOND_OF_MINUTE(), 50), OffsetTime::of(12, 30, 50, 987654321, self::OFFSET_PONE())); $this->assertEquals($test->with(CF::NANO_OF_SECOND(), 12345), OffsetTime::of(12, 30, 40, 12345, self::OFFSET_PONE())); $this->assertEquals($test->with(CF::HOUR_OF_AMPM(), 6), OffsetTime::of(18, 30, 40, 987654321, self::OFFSET_PONE())); $this->assertEquals($test->with(CF::AMPM_OF_DAY(), 0), OffsetTime::of(0, 30, 40, 987654321, self::OFFSET_PONE())); $this->assertEquals($test->with(CF::OFFSET_SECONDS(), 7205), OffsetTime::of(12, 30, 40, 987654321, ZoneOffset::ofHoursMinutesSeconds(2, 0, 5))); }
public static function init() { self::$FIELD_MAP = ['G' => ChronoField::ERA(), 'y' => ChronoField::YEAR_OF_ERA(), 'u' => ChronoField::YEAR(), 'Q' => IsoFields::QUARTER_OF_YEAR(), 'q' => IsoFields::QUARTER_OF_YEAR(), 'M' => ChronoField::MONTH_OF_YEAR(), 'L' => ChronoField::MONTH_OF_YEAR(), 'D' => ChronoField::DAY_OF_YEAR(), 'd' => ChronoField::DAY_OF_MONTH(), 'F' => ChronoField::ALIGNED_DAY_OF_WEEK_IN_MONTH(), 'E' => ChronoField::DAY_OF_WEEK(), 'c' => ChronoField::DAY_OF_WEEK(), 'e' => ChronoField::DAY_OF_WEEK(), 'a' => ChronoField::AMPM_OF_DAY(), 'H' => ChronoField::HOUR_OF_DAY(), 'k' => ChronoField::CLOCK_HOUR_OF_DAY(), 'K' => ChronoField::HOUR_OF_AMPM(), 'h' => ChronoField::CLOCK_HOUR_OF_AMPM(), 'm' => ChronoField::MINUTE_OF_HOUR(), 's' => ChronoField::SECOND_OF_MINUTE(), 'S' => ChronoField::NANO_OF_SECOND(), 'A' => ChronoField::MILLI_OF_DAY(), 'n' => ChronoField::NANO_OF_SECOND(), 'N' => ChronoField::NANO_OF_DAY()]; }