--- old/src/share/classes/java/time/LocalDate.java 2013-02-08 10:47:49.000000000 -0800 +++ new/src/share/classes/java/time/LocalDate.java 2013-02-08 10:47:48.000000000 -0800 @@ -80,26 +80,22 @@ import java.io.InvalidObjectException; import java.io.ObjectStreamException; import java.io.Serializable; -import java.time.format.DateTimeBuilder; +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.Era; +import java.time.chrono.IsoChronology; import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeFormatters; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; -import java.time.temporal.ChronoLocalDate; import java.time.temporal.ChronoUnit; -import java.time.temporal.Era; -import java.time.temporal.ISOChrono; -import java.time.temporal.OffsetDate; +import java.time.temporal.Queries; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; -import java.time.temporal.TemporalAdder; import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQuery; -import java.time.temporal.TemporalSubtractor; import java.time.temporal.TemporalUnit; import java.time.temporal.ValueRange; -import java.time.temporal.Year; import java.time.zone.ZoneOffsetTransition; import java.time.zone.ZoneRules; import java.util.Objects; @@ -131,7 +127,7 @@ * @since 1.8 */ public final class LocalDate - implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable { + implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable { /** * The minimum supported {@code LocalDate}, '-999999999-01-01'. @@ -216,7 +212,7 @@ */ public static LocalDate now(Clock clock) { Objects.requireNonNull(clock, "clock"); - // inline OffsetDate factory to avoid creating object and InstantProvider checks + // inline to avoid creating object and Instant checks final Instant now = clock.instant(); // called once ZoneOffset offset = clock.getZone().getRules().getOffset(now); long epochSec = now.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later @@ -228,14 +224,15 @@ /** * Obtains an instance of {@code LocalDate} from a year, month and day. *

+ * This returns a {@code LocalDate} with the specified year, month and day-of-month. * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, not null * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @return the local date, not null - * @throws DateTimeException if the value of any field is out of range - * @throws DateTimeException if the day-of-month is invalid for the month-year + * @throws DateTimeException if the value of any field is out of range, + * or if the day-of-month is invalid for the month-year */ public static LocalDate of(int year, Month month, int dayOfMonth) { YEAR.checkValidValue(year); @@ -247,14 +244,15 @@ /** * Obtains an instance of {@code LocalDate} from a year, month and day. *

+ * This returns a {@code LocalDate} with the specified year, month and day-of-month. * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @return the local date, not null - * @throws DateTimeException if the value of any field is out of range - * @throws DateTimeException if the day-of-month is invalid for the month-year + * @throws DateTimeException if the value of any field is out of range, + * or if the day-of-month is invalid for the month-year */ public static LocalDate of(int year, int month, int dayOfMonth) { YEAR.checkValidValue(year); @@ -267,18 +265,19 @@ /** * Obtains an instance of {@code LocalDate} from a year and day-of-year. *

+ * This returns a {@code LocalDate} with the specified year and day-of-year. * The day-of-year must be valid for the year, otherwise an exception will be thrown. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param dayOfYear the day-of-year to represent, from 1 to 366 * @return the local date, not null - * @throws DateTimeException if the value of any field is out of range - * @throws DateTimeException if the day-of-year is invalid for the month-year + * @throws DateTimeException if the value of any field is out of range, + * or if the day-of-year is invalid for the month-year */ public static LocalDate ofYearDay(int year, int dayOfYear) { YEAR.checkValidValue(year); DAY_OF_YEAR.checkValidValue(dayOfYear); - boolean leap = ISOChrono.INSTANCE.isLeapYear(year); + boolean leap = IsoChronology.INSTANCE.isLeapYear(year); if (dayOfYear == 366 && leap == false) { throw new DateTimeException("Invalid date 'DayOfYear 366' as '" + year + "' is not a leap year"); } @@ -295,8 +294,9 @@ /** * Obtains an instance of {@code LocalDate} from the epoch day count. *

- * The Epoch Day count is a simple incrementing count of days - * where day 0 is 1970-01-01. Negative numbers represent earlier days. + * This returns a {@code LocalDate} with the specified epoch-day. + * The {@link ChronoField#EPOCH_DAY EPOCH_DAY} is a simple incrementing count + * of days where day 0 is 1970-01-01. Negative numbers represent earlier days. * * @param epochDay the Epoch Day to convert, based on the epoch 1970-01-01 * @return the local date, not null @@ -338,10 +338,12 @@ /** * Obtains an instance of {@code LocalDate} from a temporal object. *

- * A {@code TemporalAccessor} represents some form of date and time information. - * This factory converts the arbitrary temporal object to an instance of {@code LocalDate}. + * This obtains a local date based on the specified temporal. + * A {@code TemporalAccessor} represents an arbitrary set of date and time information, + * which this factory converts to an instance of {@code LocalDate}. *

- * The conversion extracts the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field. + * The conversion uses the {@link Queries#localDate()} query, which relies + * on extracting the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field. *

* This method matches the signature of the functional interface {@link TemporalQuery} * allowing it to be used as a query via method reference, {@code LocalDate::from}. @@ -351,26 +353,11 @@ * @throws DateTimeException if unable to convert to a {@code LocalDate} */ public static LocalDate from(TemporalAccessor temporal) { - if (temporal instanceof LocalDate) { - return (LocalDate) temporal; - } else if (temporal instanceof LocalDateTime) { - return ((LocalDateTime) temporal).getDate(); - } else if (temporal instanceof ZonedDateTime) { - return ((ZonedDateTime) temporal).getDate(); - } - // handle builder as a special case - if (temporal instanceof DateTimeBuilder) { - DateTimeBuilder builder = (DateTimeBuilder) temporal; - LocalDate date = builder.extract(LocalDate.class); - if (date != null) { - return date; - } - } - try { - return ofEpochDay(temporal.getLong(EPOCH_DAY)); - } catch (DateTimeException ex) { - throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " + temporal.getClass(), ex); + LocalDate date = temporal.query(Queries.localDate()); + if (date == null) { + throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " + temporal.getClass()); } + return date; } //----------------------------------------------------------------------- @@ -378,14 +365,14 @@ * Obtains an instance of {@code LocalDate} from a text string such as {@code 2007-12-03}. *

* The string must represent a valid date and is parsed using - * {@link java.time.format.DateTimeFormatters#isoLocalDate()}. + * {@link java.time.format.DateTimeFormatter#ISO_LOCAL_DATE}. * * @param text the text to parse such as "2007-12-03", not null * @return the parsed local date, not null * @throws DateTimeParseException if the text cannot be parsed */ public static LocalDate parse(CharSequence text) { - return parse(text, DateTimeFormatters.isoLocalDate()); + return parse(text, DateTimeFormatter.ISO_LOCAL_DATE); } /** @@ -414,7 +401,7 @@ * @throws DateTimeException if the day-of-month is invalid for the month-year */ private static LocalDate create(int year, Month month, int dayOfMonth) { - if (dayOfMonth > 28 && dayOfMonth > month.length(ISOChrono.INSTANCE.isLeapYear(year))) { + if (dayOfMonth > 28 && dayOfMonth > month.length(IsoChronology.INSTANCE.isLeapYear(year))) { if (dayOfMonth == 29) { throw new DateTimeException("Invalid date 'February 29' as '" + year + "' is not a leap year"); } else { @@ -435,7 +422,7 @@ private static LocalDate resolvePreviousValid(int year, int month, int day) { switch (month) { case 2: - day = Math.min(day, ISOChrono.INSTANCE.isLeapYear(year) ? 29 : 28); + day = Math.min(day, IsoChronology.INSTANCE.isLeapYear(year) ? 29 : 28); break; case 4: case 6: @@ -469,8 +456,6 @@ * {@link #get(TemporalField) get} methods will throw an exception. *

* If the field is a {@link ChronoField} then the query is implemented here. - * The {@link #isSupported(TemporalField) supported fields} will return valid - * values based on this date-time. * The supported fields are: *