src/share/classes/java/time/temporal/JulianFields.java
Print this page
*** 64,73 ****
--- 64,74 ----
import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.FOREVER;
import java.time.DateTimeException;
+ import java.time.format.ResolverStyle;
import java.util.Collections;
import java.util.Map;
/**
* A set of date fields that provide access to Julian Days.
*** 104,114 ****
* For date-times, 'JULIAN_DAY.getFrom()' assumes the same value from
* midnight until just before the next midnight.
* When 'JULIAN_DAY.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
* 'JULIAN_DAY.adjustInto()' and 'JULIAN_DAY.getFrom()' only apply to {@code Temporal} objects that
* can be converted into {@link ChronoField#EPOCH_DAY}.
! * A {@link DateTimeException} is thrown for any other type of object.
* <p>
* <h3>Astronomical and Scientific Notes</h3>
* The standard astronomical definition uses a fraction to indicate the time-of-day,
* thus 3.25 would represent the time 18:00, since days start at midday.
* This implementation uses an integer and days starting at midnight.
--- 105,120 ----
* For date-times, 'JULIAN_DAY.getFrom()' assumes the same value from
* midnight until just before the next midnight.
* When 'JULIAN_DAY.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
* 'JULIAN_DAY.adjustInto()' and 'JULIAN_DAY.getFrom()' only apply to {@code Temporal} objects that
* can be converted into {@link ChronoField#EPOCH_DAY}.
! * An {@link UnsupportedTemporalTypeException} is thrown for any other type of object.
! * <p>
! * In the resolving phase of parsing, a date can be created from a Julian Day field.
! * In {@linkplain ResolverStyle#STRICT strict mode} and {@linkplain ResolverStyle#SMART smart mode}
! * the Julian Day value is validated against the range of valid values.
! * In {@linkplain ResolverStyle#LENIENT lenient mode} no validation occurs.
* <p>
* <h3>Astronomical and Scientific Notes</h3>
* The standard astronomical definition uses a fraction to indicate the time-of-day,
* thus 3.25 would represent the time 18:00, since days start at midday.
* This implementation uses an integer and days starting at midnight.
*** 145,158 ****
* For date-times, 'MODIFIED_JULIAN_DAY.getFrom()' assumes the same value from
* midnight until just before the next midnight.
* When 'MODIFIED_JULIAN_DAY.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
* 'MODIFIED_JULIAN_DAY.adjustInto()' and 'MODIFIED_JULIAN_DAY.getFrom()' only apply to {@code Temporal} objects
* that can be converted into {@link ChronoField#EPOCH_DAY}.
! * A {@link DateTimeException} is thrown for any other type of object.
* <p>
* This implementation is an integer version of MJD with the decimal part rounded to floor.
* <p>
* <h3>Astronomical and Scientific Notes</h3>
* <pre>
* | ISO date | Modified Julian Day | Decimal MJD |
* | 1970-01-01T00:00 | 40,587 | 40,587.0 |
* | 1970-01-01T06:00 | 40,587 | 40,587.25 |
--- 151,169 ----
* For date-times, 'MODIFIED_JULIAN_DAY.getFrom()' assumes the same value from
* midnight until just before the next midnight.
* When 'MODIFIED_JULIAN_DAY.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
* 'MODIFIED_JULIAN_DAY.adjustInto()' and 'MODIFIED_JULIAN_DAY.getFrom()' only apply to {@code Temporal} objects
* that can be converted into {@link ChronoField#EPOCH_DAY}.
! * An {@link UnsupportedTemporalTypeException} is thrown for any other type of object.
* <p>
* This implementation is an integer version of MJD with the decimal part rounded to floor.
* <p>
+ * In the resolving phase of parsing, a date can be created from a Modified Julian Day field.
+ * In {@linkplain ResolverStyle#STRICT strict mode} and {@linkplain ResolverStyle#SMART smart mode}
+ * the Modified Julian Day value is validated against the range of valid values.
+ * In {@linkplain ResolverStyle#LENIENT lenient mode} no validation occurs.
+ * <p>
* <h3>Astronomical and Scientific Notes</h3>
* <pre>
* | ISO date | Modified Julian Day | Decimal MJD |
* | 1970-01-01T00:00 | 40,587 | 40,587.0 |
* | 1970-01-01T06:00 | 40,587 | 40,587.25 |
*** 178,188 ****
* For date-times, 'RATA_DIE.getFrom()' assumes the same value from
* midnight until just before the next midnight.
* When 'RATA_DIE.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
* 'RATA_DIE.adjustInto()' and 'RATA_DIE.getFrom()' only apply to {@code Temporal} objects
* that can be converted into {@link ChronoField#EPOCH_DAY}.
! * A {@link DateTimeException} is thrown for any other type of object.
*/
public static final TemporalField RATA_DIE = Field.RATA_DIE;
/**
* Restricted constructor.
--- 189,204 ----
* For date-times, 'RATA_DIE.getFrom()' assumes the same value from
* midnight until just before the next midnight.
* When 'RATA_DIE.adjustInto()' is applied to a date-time, the time of day portion remains unaltered.
* 'RATA_DIE.adjustInto()' and 'RATA_DIE.getFrom()' only apply to {@code Temporal} objects
* that can be converted into {@link ChronoField#EPOCH_DAY}.
! * An {@link UnsupportedTemporalTypeException} is thrown for any other type of object.
! * <p>
! * In the resolving phase of parsing, a date can be created from a Rata Die field.
! * In {@linkplain ResolverStyle#STRICT strict mode} and {@linkplain ResolverStyle#SMART smart mode}
! * the Rata Die value is validated against the range of valid values.
! * In {@linkplain ResolverStyle#LENIENT lenient mode} no validation occurs.
*/
public static final TemporalField RATA_DIE = Field.RATA_DIE;
/**
* Restricted constructor.
*** 230,239 ****
--- 246,260 ----
public TemporalUnit getRangeUnit() {
return rangeUnit;
}
@Override
+ public boolean isDateBased() {
+ return true;
+ }
+
+ @Override
public ValueRange range() {
return range;
}
//-----------------------------------------------------------------------
*** 264,275 ****
return (R) temporal.with(EPOCH_DAY, Math.subtractExact(newValue, offset));
}
//-----------------------------------------------------------------------
@Override
! public Map<TemporalField, Long> resolve(TemporalAccessor temporal, long value) {
! return Collections.<TemporalField, Long>singletonMap(EPOCH_DAY, Math.subtractExact(value, offset));
}
//-----------------------------------------------------------------------
@Override
public String toString() {
--- 285,303 ----
return (R) temporal.with(EPOCH_DAY, Math.subtractExact(newValue, offset));
}
//-----------------------------------------------------------------------
@Override
! public Map<TemporalField, Long> resolve(TemporalAccessor temporal, long value, ResolverStyle resolverStyle) {
! long epochDay;
! if (resolverStyle == ResolverStyle.LENIENT) {
! epochDay = Math.subtractExact(value, offset);
! } else {
! range().checkValidValue(value, this);
! epochDay = value - offset;
! }
! return Collections.<TemporalField, Long>singletonMap(EPOCH_DAY, epochDay);
}
//-----------------------------------------------------------------------
@Override
public String toString() {