--- old/src/share/classes/java/time/YearMonth.java 2013-04-11 23:15:23.000000000 -0700 +++ new/src/share/classes/java/time/YearMonth.java 2013-04-11 23:15:23.000000000 -0700 @@ -61,9 +61,9 @@ */ package java.time; -import static java.time.temporal.ChronoField.EPOCH_MONTH; import static java.time.temporal.ChronoField.ERA; import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static java.time.temporal.ChronoUnit.MONTHS; @@ -82,7 +82,6 @@ import java.time.format.SignStyle; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; -import java.time.temporal.Queries; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; @@ -90,6 +89,7 @@ import java.time.temporal.TemporalField; import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Objects; @@ -255,7 +255,7 @@ * Obtains an instance of {@code YearMonth} from a text string such as {@code 2007-12}. *

* The string must represent a valid year-month. - * The format must be {@code yyyy-MM}. + * The format must be {@code uuuu-MM}. * Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol. * * @param text the text to parse such as "2007-12", not null @@ -320,7 +320,7 @@ * The supported fields are: *

*

- * All other {@code ChronoUnit} instances will throw a {@code DateTimeException}. + * All other {@code ChronoUnit} instances will throw an {@code UnsupportedTemporalTypeException}. *

* If the field is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)} @@ -741,6 +747,7 @@ * @param unit the unit of the amount to add, not null * @return a {@code YearMonth} based on this year-month with the specified amount added, not null * @throws DateTimeException if the addition cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override @@ -754,7 +761,7 @@ case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000)); case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd)); } - throw new DateTimeException("Unsupported unit: " + unit.getName()); + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName()); } return unit.addTo(this, amountToAdd); } @@ -838,6 +845,7 @@ * @param unit the unit of the amount to subtract, not null * @return a {@code YearMonth} based on this year-month with the specified amount subtracted, not null * @throws DateTimeException if the subtraction cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override @@ -893,9 +901,9 @@ @SuppressWarnings("unchecked") @Override public R query(TemporalQuery query) { - if (query == Queries.chronology()) { + if (query == TemporalQuery.chronology()) { return (R) IsoChronology.INSTANCE; - } else if (query == Queries.precision()) { + } else if (query == TemporalQuery.precision()) { return (R) MONTHS; } return Temporal.super.query(query); @@ -908,7 +916,7 @@ * with the year and month changed to be the same as this. *

* The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} - * passing {@link ChronoField#EPOCH_MONTH} as the field. + * passing {@link ChronoField#PROLEPTIC_MONTH} as the field. * If the specified temporal object does not use the ISO calendar system then * a {@code DateTimeException} is thrown. *

@@ -932,7 +940,7 @@ if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time"); } - return temporal.with(EPOCH_MONTH, getEpochMonth()); + return temporal.with(PROLEPTIC_MONTH, getProlepticMonth()); } /** @@ -977,6 +985,7 @@ * @param unit the unit to measure the period in, not null * @return the amount of the period between this year-month and the end year-month * @throws DateTimeException if the period cannot be calculated + * @throws UnsupportedTemporalTypeException if the unit is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override @@ -987,7 +996,7 @@ } YearMonth end = (YearMonth) endYearMonth; if (unit instanceof ChronoUnit) { - long monthsUntil = end.getEpochMonth() - getEpochMonth(); // no overflow + long monthsUntil = end.getProlepticMonth() - getProlepticMonth(); // no overflow switch ((ChronoUnit) unit) { case MONTHS: return monthsUntil; case YEARS: return monthsUntil / 12; @@ -996,11 +1005,25 @@ case MILLENNIA: return monthsUntil / 12000; case ERAS: return end.getLong(ERA) - getLong(ERA); } - throw new DateTimeException("Unsupported unit: " + unit.getName()); + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName()); } return unit.between(this, endYearMonth); } + /** + * Formats this year-month using the specified formatter. + *

+ * This year-month will be passed to the formatter to produce a string. + * + * @param formatter the formatter to use, not null + * @return the formatted year-month string, not null + * @throws DateTimeException if an error occurs during printing + */ + public String format(DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.format(this); + } + //----------------------------------------------------------------------- /** * Combines this year-month with a day-of-month to create a {@code LocalDate}. @@ -1115,7 +1138,7 @@ /** * Outputs this year-month as a {@code String}, such as {@code 2007-12}. *

- * The output will be in the format {@code yyyy-MM}: + * The output will be in the format {@code uuuu-MM}: * * @return a string representation of this year-month, not null */ @@ -1137,21 +1160,6 @@ .toString(); } - /** - * Outputs this year-month as a {@code String} using the formatter. - *

- * This year-month will be passed to the formatter - * {@link DateTimeFormatter#format(TemporalAccessor) format method}. - * - * @param formatter the formatter to use, not null - * @return the formatted year-month string, not null - * @throws DateTimeException if an error occurs during printing - */ - public String toString(DateTimeFormatter formatter) { - Objects.requireNonNull(formatter, "formatter"); - return formatter.format(this); - } - //----------------------------------------------------------------------- /** * Writes the object using a