public function test_with_adjuster_Year() { $ldt = LocalDateTime::of(2008, 6, 30, 23, 30, 59, 0); $base = ZonedDateTime::ofDateTime($ldt, self::ZONE_0100()); $test = $base->adjust(Year::of(2007)); $this->assertEquals($test, ZonedDateTime::ofDateTime($ldt->withYear(2007), self::ZONE_0100())); }
public function test_with_Year_noChange_equal() { $test = YearMonth::of(2008, 6); $this->assertEquals($test->adjust(Year::of(2008)), $test); }
public function test_toString() { for ($i = -4; $i <= 2104; $i++) { $a = Year::of($i); $this->assertEquals($a->__toString(), "" . $i); } }
/** * Returns a copy of this year with the specified field set to a new value. * <p> * This returns a {@code Year}, based on this one, with the value * for the specified field changed. * 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 YEAR_OF_ERA} - * Returns a {@code Year} with the specified year-of-era * The era will be unchanged. * <li>{@code YEAR} - * Returns a {@code Year} with the specified year. * This completely replaces the date and is equivalent to {@link #of(int)}. * <li>{@code ERA} - * Returns a {@code Year} with the specified era. * The year-of-era 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 Year a {@code Year} 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::YEAR_OF_ERA(): return Year::of((int) ($this->year < 1 ? 1 - $newValue : $newValue)); case ChronoField::YEAR(): return Year::of((int) $newValue); case ChronoField::ERA(): return $this->getLong(ChronoField::ERA()) == $newValue ? $this : Year::of(1 - $this->year); } throw new UnsupportedTemporalTypeException("Unsupported field: " . $field); } return $field->adjustInto($this, $newValue); }
/** * @expectedException \Celest\DateTimeException */ public function test_print_isoOrdinalDate_missingField() { $test = Year::of(2008); DateTimeFormatter::ISO_ORDINAL_DATE()->format($test); }