Skip to content

Instantly share code, notes, and snippets.

@jodastephen
Created July 1, 2013 14:48
Show Gist options
  • Save jodastephen/5901479 to your computer and use it in GitHub Desktop.
Save jodastephen/5901479 to your computer and use it in GitHub Desktop.
Patch for #315
# HG changeset patch
# User scolebourne
# Date 1372689842 -3600
# Node ID 81d32359e09023be1f642f27181b38137295e457
# Parent e92ef0ad0c59d9e66bde0611640e3eaf96769d3b
Add Temporal.isSupported(TemporalUnit)
See #315
diff --git a/src/share/classes/java/time/Instant.java b/src/share/classes/java/time/Instant.java
--- a/src/share/classes/java/time/Instant.java
+++ b/src/share/classes/java/time/Instant.java
@@ -69,6 +69,7 @@
import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
+import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.NANOS;
import java.io.DataInput;
@@ -418,8 +419,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this instant can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -448,6 +450,44 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isTimeBased() || unit == DAYS;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/LocalDate.java b/src/share/classes/java/time/LocalDate.java
--- a/src/share/classes/java/time/LocalDate.java
+++ b/src/share/classes/java/time/LocalDate.java
@@ -466,8 +466,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -502,6 +503,41 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ return ChronoLocalDate.super.isSupported(unit);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/LocalDateTime.java b/src/share/classes/java/time/LocalDateTime.java
--- a/src/share/classes/java/time/LocalDateTime.java
+++ b/src/share/classes/java/time/LocalDateTime.java
@@ -515,8 +515,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -570,6 +571,48 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ return ChronoLocalDateTime.super.isSupported(unit);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/LocalTime.java b/src/share/classes/java/time/LocalTime.java
--- a/src/share/classes/java/time/LocalTime.java
+++ b/src/share/classes/java/time/LocalTime.java
@@ -470,8 +470,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -511,6 +512,43 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isTimeBased();
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/OffsetDateTime.java b/src/share/classes/java/time/OffsetDateTime.java
--- a/src/share/classes/java/time/OffsetDateTime.java
+++ b/src/share/classes/java/time/OffsetDateTime.java
@@ -65,6 +65,7 @@
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.NANO_OF_DAY;
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
+import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.io.IOException;
@@ -421,8 +422,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -474,6 +476,51 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit != FOREVER;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/OffsetTime.java b/src/share/classes/java/time/OffsetTime.java
--- a/src/share/classes/java/time/OffsetTime.java
+++ b/src/share/classes/java/time/OffsetTime.java
@@ -348,8 +348,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -390,6 +391,43 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isTimeBased();
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/Year.java b/src/share/classes/java/time/Year.java
--- a/src/share/classes/java/time/Year.java
+++ b/src/share/classes/java/time/Year.java
@@ -64,6 +64,10 @@
import static java.time.temporal.ChronoField.ERA;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
+import static java.time.temporal.ChronoUnit.CENTURIES;
+import static java.time.temporal.ChronoUnit.DECADES;
+import static java.time.temporal.ChronoUnit.ERAS;
+import static java.time.temporal.ChronoUnit.MILLENNIA;
import static java.time.temporal.ChronoUnit.YEARS;
import java.io.DataInput;
@@ -329,8 +333,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this year can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -358,6 +363,41 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/YearMonth.java b/src/share/classes/java/time/YearMonth.java
--- a/src/share/classes/java/time/YearMonth.java
+++ b/src/share/classes/java/time/YearMonth.java
@@ -66,7 +66,12 @@
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.CENTURIES;
+import static java.time.temporal.ChronoUnit.DECADES;
+import static java.time.temporal.ChronoUnit.ERAS;
+import static java.time.temporal.ChronoUnit.MILLENNIA;
import static java.time.temporal.ChronoUnit.MONTHS;
+import static java.time.temporal.ChronoUnit.YEARS;
import java.io.DataInput;
import java.io.DataOutput;
@@ -313,8 +318,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this year-month can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -345,6 +351,42 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit == MONTHS || unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/ZonedDateTime.java b/src/share/classes/java/time/ZonedDateTime.java
--- a/src/share/classes/java/time/ZonedDateTime.java
+++ b/src/share/classes/java/time/ZonedDateTime.java
@@ -642,8 +642,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -695,6 +696,48 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ return ChronoZonedDateTime.super.isSupported(unit);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
diff --git a/src/share/classes/java/time/chrono/ChronoLocalDate.java b/src/share/classes/java/time/chrono/ChronoLocalDate.java
--- a/src/share/classes/java/time/chrono/ChronoLocalDate.java
+++ b/src/share/classes/java/time/chrono/ChronoLocalDate.java
@@ -367,6 +367,25 @@
return (isLeapYear() ? 366 : 365);
}
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if the specified field can be queried on this date.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
+ * <p>
+ * The set of supported fields is defined by the chronology and normally includes
+ * all {@code ChronoField} date fields.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field can be queried, false if not
+ */
@Override
default boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
@@ -375,6 +394,32 @@
return field != null && field.isSupportedBy(this);
}
+ /**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to or subtracted from this date.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * The set of supported units is defined by the chronology and normally includes
+ * all {@code ChronoUnit} date units except {@code FOREVER}.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ default boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isDateBased();
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
//-----------------------------------------------------------------------
// override for covariant return type
/**
diff --git a/src/share/classes/java/time/chrono/ChronoLocalDateTime.java b/src/share/classes/java/time/chrono/ChronoLocalDateTime.java
--- a/src/share/classes/java/time/chrono/ChronoLocalDateTime.java
+++ b/src/share/classes/java/time/chrono/ChronoLocalDateTime.java
@@ -63,6 +63,7 @@
import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.NANO_OF_DAY;
+import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.time.DateTimeException;
@@ -73,6 +74,7 @@
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
@@ -191,9 +193,54 @@
*/
LocalTime toLocalTime();
- @Override // Override to provide javadoc
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if the specified field can be queried on this date-time.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
+ * <p>
+ * The set of supported fields is defined by the chronology and normally includes
+ * all {@code ChronoField} date and time fields.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field can be queried, false if not
+ */
+ @Override
boolean isSupported(TemporalField field);
+ /**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to or subtracted from this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * The set of supported units is defined by the chronology and normally includes
+ * all {@code ChronoUnit} units except {@code FOREVER}.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ default boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit != FOREVER;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
//-----------------------------------------------------------------------
// override for covariant return type
/**
diff --git a/src/share/classes/java/time/chrono/ChronoZonedDateTime.java b/src/share/classes/java/time/chrono/ChronoZonedDateTime.java
--- a/src/share/classes/java/time/chrono/ChronoZonedDateTime.java
+++ b/src/share/classes/java/time/chrono/ChronoZonedDateTime.java
@@ -63,6 +63,7 @@
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
+import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.time.DateTimeException;
@@ -73,6 +74,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
@@ -338,9 +340,54 @@
*/
ChronoZonedDateTime<D> withZoneSameInstant(ZoneId zone);
- @Override // Override to provide javadoc
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if the specified field can be queried on this date-time.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
+ * <p>
+ * The set of supported fields is defined by the chronology and normally includes
+ * all {@code ChronoField} fields.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field can be queried, false if not
+ */
+ @Override
boolean isSupported(TemporalField field);
+ /**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to or subtracted from this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * The set of supported units is defined by the chronology and normally includes
+ * all {@code ChronoUnit} units except {@code FOREVER}.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ default boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit != FOREVER;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
//-----------------------------------------------------------------------
// override for covariant return type
/**
diff --git a/src/share/classes/java/time/temporal/ChronoUnit.java b/src/share/classes/java/time/temporal/ChronoUnit.java
--- a/src/share/classes/java/time/temporal/ChronoUnit.java
+++ b/src/share/classes/java/time/temporal/ChronoUnit.java
@@ -224,22 +224,28 @@
*/
@Override
public boolean isDurationEstimated() {
- return isDateBased();
+ return this.compareTo(DAYS) >= 0;
}
//-----------------------------------------------------------------------
/**
* Checks if this unit is a date unit.
+ * <p>
+ * All units from days to eras inclusive are date-based.
+ * Time-based units and {@code FOREVER} return false.
*
* @return true if a date unit, false if a time unit
*/
@Override
public boolean isDateBased() {
- return this.compareTo(DAYS) >= 0;
+ return this.compareTo(DAYS) >= 0 && this != FOREVER;
}
/**
* Checks if this unit is a time unit.
+ * <p>
+ * All units from nanos to half-days inclusive are time-based.
+ * Date-based units and {@code FOREVER} return false.
*
* @return true if a time unit, false if a date unit
*/
@@ -251,10 +257,7 @@
//-----------------------------------------------------------------------
@Override
public boolean isSupportedBy(Temporal temporal) {
- if (this == FOREVER) {
- return false;
- }
- return TemporalUnit.super.isSupportedBy(temporal);
+ return temporal.isSupported(this);
}
@SuppressWarnings("unchecked")
diff --git a/src/share/classes/java/time/temporal/Temporal.java b/src/share/classes/java/time/temporal/Temporal.java
--- a/src/share/classes/java/time/temporal/Temporal.java
+++ b/src/share/classes/java/time/temporal/Temporal.java
@@ -129,6 +129,29 @@
public interface Temporal extends TemporalAccessor {
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ *
+ * @implSpec
+ * Implementations must check and handle all units defined in {@link ChronoUnit}.
+ * If the unit is supported, then true must be returned, otherwise false must be returned.
+ * <p>
+ * If the field is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * <p>
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ boolean isSupported(TemporalUnit unit);
+
+ /**
* Returns an adjusted object of the same type as this object with the adjustment made.
* <p>
* This adjusts this date-time according to the rules of the specified adjuster.
@@ -399,7 +422,8 @@
* return unit.between(this, endTemporal);
* </pre>
* <p>
- * Neither this object, nor the specified temporal, may be altered.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param endTemporal the end temporal, of the same type as this object, not null
* @param unit the unit to measure the amount in, not null
diff --git a/src/share/classes/java/time/temporal/TemporalAccessor.java b/src/share/classes/java/time/temporal/TemporalAccessor.java
--- a/src/share/classes/java/time/temporal/TemporalAccessor.java
+++ b/src/share/classes/java/time/temporal/TemporalAccessor.java
@@ -111,13 +111,14 @@
*
* @implSpec
* Implementations must check and handle all fields defined in {@link ChronoField}.
- * If the field is supported, then true is returned, otherwise false
+ * If the field is supported, then true must be returned, otherwise false must be returned.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter either this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param field the field to check, null returns false
* @return true if this date-time can be queried for the field, false if not
@@ -146,7 +147,8 @@
* is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessorl)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter either this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
* <p>
* The default implementation must behave equivalent to this code:
* <pre>
@@ -193,7 +195,8 @@
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
* <p>
* The default implementation must behave equivalent to this code:
* <pre>
@@ -240,7 +243,8 @@
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter either this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param field the field to get, not null
* @return the value for the field
@@ -291,6 +295,9 @@
* }
* return TemporalAccessor.super.query(query);
* </pre>
+ * <p>
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
diff --git a/test/java/time/tck/java/time/TCKDayOfWeek.java b/test/java/time/tck/java/time/TCKDayOfWeek.java
--- a/test/java/time/tck/java/time/TCKDayOfWeek.java
+++ b/test/java/time/tck/java/time/TCKDayOfWeek.java
@@ -159,6 +159,44 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(DayOfWeek.THURSDAY.isSupported((TemporalField) null), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ERA), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKLocalDate.java b/test/java/time/tck/java/time/TCKLocalDate.java
--- a/test/java/time/tck/java/time/TCKLocalDate.java
+++ b/test/java/time/tck/java/time/TCKLocalDate.java
@@ -620,6 +620,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2007_07_15.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2007_07_15.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.NANOS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MICROS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MILLIS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.SECONDS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MINUTES), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.HOURS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.HALF_DAYS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKLocalDateTime.java b/test/java/time/tck/java/time/TCKLocalDateTime.java
--- a/test/java/time/tck/java/time/TCKLocalDateTime.java
+++ b/test/java/time/tck/java/time/TCKLocalDateTime.java
@@ -938,6 +938,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKLocalTime.java b/test/java/time/tck/java/time/TCKLocalTime.java
--- a/test/java/time/tck/java/time/TCKLocalTime.java
+++ b/test/java/time/tck/java/time/TCKLocalTime.java
@@ -620,6 +620,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_12_30_40_987654321.isSupported((TemporalField) null), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ERA), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_12_30_40_987654321.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MONTHS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.YEARS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.DECADES), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.CENTURIES), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MILLENNIA), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.ERAS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKMonth.java b/test/java/time/tck/java/time/TCKMonth.java
--- a/test/java/time/tck/java/time/TCKMonth.java
+++ b/test/java/time/tck/java/time/TCKMonth.java
@@ -151,6 +151,44 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(Month.AUGUST.isSupported((TemporalField) null), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ERA), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKMonthDay.java b/test/java/time/tck/java/time/TCKMonthDay.java
--- a/test/java/time/tck/java/time/TCKMonthDay.java
+++ b/test/java/time/tck/java/time/TCKMonthDay.java
@@ -388,6 +388,44 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_07_15.isSupported((TemporalField) null), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_07_15.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ERA), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKOffsetDateTime.java b/test/java/time/tck/java/time/TCKOffsetDateTime.java
--- a/test/java/time/tck/java/time/TCKOffsetDateTime.java
+++ b/test/java/time/tck/java/time/TCKOffsetDateTime.java
@@ -126,6 +126,7 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -555,6 +556,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.INSTANT_SECONDS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.OFFSET_SECONDS), true);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKOffsetTime.java b/test/java/time/tck/java/time/TCKOffsetTime.java
--- a/test/java/time/tck/java/time/TCKOffsetTime.java
+++ b/test/java/time/tck/java/time/TCKOffsetTime.java
@@ -543,6 +543,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalField) null), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ERA), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.OFFSET_SECONDS), true);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MONTHS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.YEARS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DECADES), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.CENTURIES), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLENNIA), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.ERAS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKYear.java b/test/java/time/tck/java/time/TCKYear.java
--- a/test/java/time/tck/java/time/TCKYear.java
+++ b/test/java/time/tck/java/time/TCKYear.java
@@ -348,6 +348,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2008.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2008.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2008.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2008.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2008.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.NANOS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MICROS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MILLIS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.SECONDS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MINUTES), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.HOURS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.HALF_DAYS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MONTHS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKYearMonth.java b/test/java/time/tck/java/time/TCKYearMonth.java
--- a/test/java/time/tck/java/time/TCKYearMonth.java
+++ b/test/java/time/tck/java/time/TCKYearMonth.java
@@ -408,6 +408,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2008_06.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2008_06.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.NANOS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MICROS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MILLIS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.SECONDS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MINUTES), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.HOURS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.HALF_DAYS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/TCKZonedDateTime.java b/test/java/time/tck/java/time/TCKZonedDateTime.java
--- a/test/java/time/tck/java/time/TCKZonedDateTime.java
+++ b/test/java/time/tck/java/time/TCKZonedDateTime.java
@@ -127,6 +127,7 @@
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -723,10 +724,12 @@
public boolean isSupported(TemporalField field) {
return TEST_DATE_TIME_PARIS.toLocalDateTime().isSupported(field);
}
+
@Override
public long getLong(TemporalField field) {
return TEST_DATE_TIME_PARIS.toLocalDateTime().getLong(field);
}
+
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
@@ -901,6 +904,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_DATE_TIME.isSupported((TemporalField) null), false);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.INSTANT_SECONDS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.OFFSET_SECONDS), true);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_DATE_TIME.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
diff --git a/test/java/time/tck/java/time/temporal/TCKChronoUnit.java b/test/java/time/tck/java/time/temporal/TCKChronoUnit.java
--- a/test/java/time/tck/java/time/temporal/TCKChronoUnit.java
+++ b/test/java/time/tck/java/time/temporal/TCKChronoUnit.java
@@ -59,10 +59,12 @@
import static java.time.temporal.ChronoUnit.CENTURIES;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.DECADES;
+import static java.time.temporal.ChronoUnit.ERAS;
import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.HALF_DAYS;
import static java.time.temporal.ChronoUnit.HOURS;
import static java.time.temporal.ChronoUnit.MICROS;
+import static java.time.temporal.ChronoUnit.MILLENNIA;
import static java.time.temporal.ChronoUnit.MILLIS;
import static java.time.temporal.ChronoUnit.MINUTES;
import static java.time.temporal.ChronoUnit.MONTHS;
@@ -89,12 +91,16 @@
*/
@Test
public class TCKChronoUnit {
+
//-----------------------------------------------------------------------
// isDateBased(), isTimeBased() and isDurationEstimated()
//-----------------------------------------------------------------------
@DataProvider(name="chronoUnit")
Object[][] data_chronoUnit() {
return new Object[][] {
+ {FOREVER, false, false, true},
+ {ERAS, true, false, true},
+ {MILLENNIA, true, false, true},
{CENTURIES, true, false, true},
{DECADES, true, false, true},
{YEARS, true, false, true},
@@ -118,9 +124,6 @@
assertEquals(unit.isDateBased(), isDateBased);
assertEquals(unit.isTimeBased(), isTimeBased);
assertEquals(unit.isDurationEstimated(), isDurationEstimated);
-
- assertEquals(unit.isTimeBased(), !unit.isDateBased());
- assertEquals(unit.isDateBased(), unit.isDurationEstimated());
}
//-----------------------------------------------------------------------
@RogerRiggs
Copy link

With respect to isSupported(null) is it more useful to return false than to throw NPE?
Otherwise it looks ok to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment