Top Description Inners Fields Constructors Methods
java.time.temporal

public final Class JulianFields

extends Object
Class Inheritance
Static Imports
java.time.temporal.ChronoField.EPOCH_DAY, .ChronoUnit.DAYS, .ChronoUnit.FOREVER

A set of date fields that provide access to Julian Days.

The Julian Day is a standard way of expressing date and time commonly used in the scientific community. It is expressed as a decimal number of whole days where days start at midday. This class represents variations on Julian Days that count whole days from midnight.

The fields are implemented relative to EPOCH_DAY. The fields are supported, and can be queried and set if EPOCH_DAY is available. The fields work with all chronologies.

Implementation Specification

This is an immutable and thread-safe class.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
JulianFields.Field

Implementation of JulianFields.

Field Summary

Modifier and TypeField and Description
public static final TemporalField
JULIAN_DAY

Julian Day field.

private static final long
JULIAN_DAY_OFFSET

The offset from Julian to EPOCH DAY.

public static final TemporalField
MODIFIED_JULIAN_DAY

Modified Julian Day field.

public static final TemporalField
RATA_DIE

Rata Die field.

Constructor Summary

AccessConstructor and Description
private
JulianFields()

Restricted constructor.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

JULIAN_DAYback to summary
public static final TemporalField JULIAN_DAY

Julian Day field.

This is an integer-based version of the Julian Day Number. Julian Day is a well-known system that represents the count of whole days since day 0, which is defined to be January 1, 4713 BCE in the Julian calendar, and -4713-11-24 Gregorian. The field has "JulianDay" as 'name', and 'DAYS' as 'baseUnit'. The field always refers to the local date-time, ignoring the offset or zone.

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 Temporal objects that can be converted into ChronoField#EPOCH_DAY. An UnsupportedTemporalTypeException is thrown for any other type of object.

In the resolving phase of parsing, a date can be created from a Julian Day field. In strict mode and smart mode the Julian Day value is validated against the range of valid values. In lenient mode no validation occurs.

Astronomical and Scientific Notes

The standard astronomical definition uses a fraction to indicate the time-of-day, where each day is counted from midday to midday. For example, a fraction of 0 represents midday, a fraction of 0.25 represents 18:00, a fraction of 0.5 represents midnight and a fraction of 0.75 represents 06:00.

By contrast, this implementation has no fractional part, and counts days from midnight to midnight. This implementation uses an integer and days starting at midnight. The integer value for the Julian Day Number is the astronomical Julian Day value at midday of the date in question. This amounts to the astronomical Julian Day, rounded to an integer JDN = floor(JD + 0.5).

 | ISO date          |  Julian Day Number | Astronomical Julian Day |
 | 1970-01-01T00:00  |         2,440,588  |         2,440,587.5     |
 | 1970-01-01T06:00  |         2,440,588  |         2,440,587.75    |
 | 1970-01-01T12:00  |         2,440,588  |         2,440,588.0     |
 | 1970-01-01T18:00  |         2,440,588  |         2,440,588.25    |
 | 1970-01-02T00:00  |         2,440,589  |         2,440,588.5     |
 | 1970-01-02T06:00  |         2,440,589  |         2,440,588.75    |
 | 1970-01-02T12:00  |         2,440,589  |         2,440,589.0     |

Julian Days are sometimes taken to imply Universal Time or UTC, but this implementation always uses the Julian Day number for the local date, regardless of the offset or time-zone.

JULIAN_DAY_OFFSETback to summary
private static final long JULIAN_DAY_OFFSET

The offset from Julian to EPOCH DAY.

MODIFIED_JULIAN_DAYback to summary
public static final TemporalField MODIFIED_JULIAN_DAY

Modified Julian Day field.

This is an integer-based version of the Modified Julian Day Number. Modified Julian Day (MJD) is a well-known system that counts days continuously. It is defined relative to astronomical Julian Day as MJD = JD - 2400000.5. Each Modified Julian Day runs from midnight to midnight. The field always refers to the local date-time, ignoring the offset or zone.

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 Temporal objects that can be converted into ChronoField#EPOCH_DAY. An UnsupportedTemporalTypeException is thrown for any other type of object.

This implementation is an integer version of MJD with the decimal part rounded to floor.

In the resolving phase of parsing, a date can be created from a Modified Julian Day field. In strict mode and smart mode the Modified Julian Day value is validated against the range of valid values. In lenient mode no validation occurs.

Astronomical and Scientific Notes

 | 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  |
 | 1970-01-01T12:00  |             40,587  |       40,587.5   |
 | 1970-01-01T18:00  |             40,587  |       40,587.75  |
 | 1970-01-02T00:00  |             40,588  |       40,588.0   |
 | 1970-01-02T06:00  |             40,588  |       40,588.25  |
 | 1970-01-02T12:00  |             40,588  |       40,588.5   |
Modified Julian Days are sometimes taken to imply Universal Time or UTC, but this implementation always uses the Modified Julian Day for the local date, regardless of the offset or time-zone.
RATA_DIEback to summary
public static final TemporalField RATA_DIE

Rata Die field.

Rata Die counts whole days continuously starting day 1 at midnight at the beginning of 0001-01-01 (ISO). The field always refers to the local date-time, ignoring the offset or zone.

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 Temporal objects that can be converted into ChronoField#EPOCH_DAY. An UnsupportedTemporalTypeException is thrown for any other type of object.

In the resolving phase of parsing, a date can be created from a Rata Die field. In strict mode and smart mode the Rata Die value is validated against the range of valid values. In lenient mode no validation occurs.

Constructor Detail

JulianFieldsback to summary
private JulianFields()

Restricted constructor.

java.time.temporal back to summary

private final Enum JulianFields.Field

extends Enum<JulianFields.Field>
implements TemporalField
Class Inheritance
All Implemented Interfaces
java.time.temporal.TemporalField

Implementation of JulianFields. Each instance is a singleton.

Field Summary

Modifier and TypeField and Description
private final transient TemporalUnit
public static final JulianFields.Field
public static final JulianFields.Field
private final transient String
private final transient long
private final transient ValueRange
private final transient TemporalUnit
public static final JulianFields.Field

Constructor Summary

AccessConstructor and Description
private
Field(String name, TemporalUnit baseUnit, TemporalUnit rangeUnit, long offset)

Method Summary

Modifier and TypeMethod and Description
public <R extends Temporal> R
adjustInto(R
the temporal object to adjust, not null
temporal
,
long
the new value of the field
newValue
)

Implements java.time.temporal.TemporalField.adjustInto.

Returns a copy of the specified temporal object with the value of this field set.

public TemporalUnit
getBaseUnit()

Implements java.time.temporal.TemporalField.getBaseUnit.

Gets the unit that the field is measured in.

The unit of the field is the period that varies within the range.

public long
getFrom(TemporalAccessor
the temporal object to query, not null
temporal
)

Implements java.time.temporal.TemporalField.getFrom.

Gets the value of this field from the specified temporal object.

public TemporalUnit
getRangeUnit()

Implements java.time.temporal.TemporalField.getRangeUnit.

Gets the range that the field is bound by.

public boolean
isDateBased()

Implements java.time.temporal.TemporalField.isDateBased.

Checks if this field represents a component of a date.

public boolean
isSupportedBy(TemporalAccessor
the temporal object to query, not null
temporal
)

Implements java.time.temporal.TemporalField.isSupportedBy.

Checks if this field is supported by the temporal object.

public boolean
isTimeBased()

Implements java.time.temporal.TemporalField.isTimeBased.

Checks if this field represents a component of a time.

public ValueRange
range()

Implements java.time.temporal.TemporalField.range.

Gets the range of valid values for the field.

public ValueRange
rangeRefinedBy(TemporalAccessor
the temporal object used to refine the result, not null
temporal
)

Implements java.time.temporal.TemporalField.rangeRefinedBy.

Get the range of valid values for this field using the temporal object to refine the result.

public ChronoLocalDate
resolve(Map<TemporalField, Long>
the map of fields to values, which can be updated, not null
fieldValues
,
TemporalAccessor
the partially complete temporal to query for zone and chronology; querying for other things is undefined and not recommended, not null
partialTemporal
,
ResolverStyle
the requested type of resolve, not null
resolverStyle
)

Overrides default java.time.temporal.TemporalField.resolve.

Resolves this field to provide a simpler alternative or a date.

public String
toString()

Overrides java.lang.Enum.toString.

Implements java.time.temporal.TemporalField.toString.

Gets a descriptive name for the field.

public static JulianFields.Field
public static JulianFields.Field[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

baseUnitback to summary
private final transient TemporalUnit baseUnit
JULIAN_DAYback to summary
public static final JulianFields.Field JULIAN_DAY
MODIFIED_JULIAN_DAYback to summary
public static final JulianFields.Field MODIFIED_JULIAN_DAY
nameback to summary
private final transient String name

Hides java.lang.Enum.name.

offsetback to summary
private final transient long offset
rangeback to summary
private final transient ValueRange range
rangeUnitback to summary
private final transient TemporalUnit rangeUnit
RATA_DIEback to summary
public static final JulianFields.Field RATA_DIE

Constructor Detail

Fieldback to summary
private Field(String name, TemporalUnit baseUnit, TemporalUnit rangeUnit, long offset)

Method Detail

adjustIntoback to summary
public <R extends Temporal> R adjustInto(R temporal, long newValue)

Implements java.time.temporal.TemporalField.adjustInto.

Doc from java.time.temporal.TemporalField.adjustInto.

Returns a copy of the specified temporal object with the value of this field set.

This returns a new temporal object based on the specified one with the value for this field changed. For example, on a LocalDate, this could be used to set the year, month or day-of-month. The returned object has the same observable type as the specified object.

In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then changing the month to February would be unclear. In cases like this, the implementation is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use Temporal#with(TemporalField, long):

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisField.adjustInto(temporal);
  temporal = temporal.with(thisField);
It is recommended to use the second approach, with(TemporalField), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported an UnsupportedTemporalTypeException must be thrown.

Implementations must not alter the specified temporal object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.

Parameters
<R>
the type of the Temporal object
temporal:R

the temporal object to adjust, not null

newValue:long

the new value of the field

Returns:R

the adjusted temporal object, not null

Annotations
@SuppressWarnings:unchecked
@Override
getBaseUnitback to summary
public TemporalUnit getBaseUnit()

Implements java.time.temporal.TemporalField.getBaseUnit.

Doc from java.time.temporal.TemporalField.getBaseUnit.

Gets the unit that the field is measured in.

The unit of the field is the period that varies within the range. For example, in the field 'MonthOfYear', the unit is 'Months'. See also getRangeUnit().

Returns:TemporalUnit

the unit defining the base unit of the field, not null

Annotations
@Override
getFromback to summary
public long getFrom(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.getFrom.

Doc from java.time.temporal.TemporalField.getFrom.

Gets the value of this field from the specified temporal object.

This queries the temporal object for the value of this field.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#getLong(TemporalField) (or TemporalAccessor#get(TemporalField)):

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisField.getFrom(temporal);
  temporal = temporal.getLong(thisField);
It is recommended to use the second approach, getLong(TemporalField), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported an UnsupportedTemporalTypeException must be thrown.

Parameters
temporal:TemporalAccessor

the temporal object to query, not null

Returns:long

the value of this field, not null

Annotations
@Override
getRangeUnitback to summary
public TemporalUnit getRangeUnit()

Implements java.time.temporal.TemporalField.getRangeUnit.

Doc from java.time.temporal.TemporalField.getRangeUnit.

Gets the range that the field is bound by.

The range of the field is the period that the field varies within. For example, in the field 'MonthOfYear', the range is 'Years'. See also getBaseUnit().

The range is never null. For example, the 'Year' field is shorthand for 'YearOfForever'. It therefore has a unit of 'Years' and a range of 'Forever'.

Returns:TemporalUnit

the unit defining the range of the field, not null

Annotations
@Override
isDateBasedback to summary
public boolean isDateBased()

Implements java.time.temporal.TemporalField.isDateBased.

Doc from java.time.temporal.TemporalField.isDateBased.

Checks if this field represents a component of a date.

A field is date-based if it can be derived from EPOCH_DAY. Note that it is valid for both isDateBased() and isTimeBased() to return false, such as when representing a field like minute-of-week.

Returns:boolean

true if this field is a component of a date

Annotations
@Override
isSupportedByback to summary
public boolean isSupportedBy(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.isSupportedBy.

Doc from java.time.temporal.TemporalField.isSupportedBy.

Checks if this field is supported by the temporal object.

This determines whether the temporal accessor supports this field. If this returns false, then the temporal cannot be queried for this field.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#isSupported(TemporalField):

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisField.isSupportedBy(temporal);
  temporal = temporal.isSupported(thisField);
It is recommended to use the second approach, isSupported(TemporalField), as it is a lot clearer to read in code.

Implementations should determine whether they are supported using the fields available in ChronoField.

Parameters
temporal:TemporalAccessor

the temporal object to query, not null

Returns:boolean

true if the date-time can be queried for this field, false if not

Annotations
@Override
isTimeBasedback to summary
public boolean isTimeBased()

Implements java.time.temporal.TemporalField.isTimeBased.

Doc from java.time.temporal.TemporalField.isTimeBased.

Checks if this field represents a component of a time.

A field is time-based if it can be derived from NANO_OF_DAY. Note that it is valid for both isDateBased() and isTimeBased() to return false, such as when representing a field like minute-of-week.

Returns:boolean

true if this field is a component of a time

Annotations
@Override
rangeback to summary
public ValueRange range()

Implements java.time.temporal.TemporalField.range.

Doc from java.time.temporal.TemporalField.range.

Gets the range of valid values for the field.

All fields can be expressed as a long integer. This method returns an object that describes the valid range for that value. This method is generally only applicable to the ISO-8601 calendar system.

Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.

Returns:ValueRange

the range of valid values for the field, not null

Annotations
@Override
rangeRefinedByback to summary
public ValueRange rangeRefinedBy(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.rangeRefinedBy.

Doc from java.time.temporal.TemporalField.rangeRefinedBy.

Get the range of valid values for this field using the temporal object to refine the result.

This uses the temporal object to find the range of valid values for the field. This is similar to range(), however this method refines the result using the temporal. For example, if the field is DAY_OF_MONTH the range method is not accurate as there are four possible month lengths, 28, 29, 30 and 31 days. Using this method with a date allows the range to be accurate, returning just one of those four options.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#range(TemporalField):

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisField.rangeRefinedBy(temporal);
  temporal = temporal.range(thisField);
It is recommended to use the second approach, range(TemporalField), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported an UnsupportedTemporalTypeException must be thrown.

Parameters
temporal:TemporalAccessor

the temporal object used to refine the result, not null

Returns:ValueRange

the range of valid values for this field, not null

Annotations
@Override
resolveback to summary
public ChronoLocalDate resolve(Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle)

Overrides default java.time.temporal.TemporalField.resolve.

Doc from java.time.temporal.TemporalField.resolve.

Resolves this field to provide a simpler alternative or a date.

This method is invoked during the resolve phase of parsing. It is designed to allow application defined fields to be simplified into more standard fields, such as those on ChronoField, or into a date.

Applications should not normally invoke this method directly.

Parameters
fieldValues:Map<TemporalField, Long>

the map of fields to values, which can be updated, not null

partialTemporal:TemporalAccessor

the partially complete temporal to query for zone and chronology; querying for other things is undefined and not recommended, not null

resolverStyle:ResolverStyle

the requested type of resolve, not null

Returns:ChronoLocalDate

the resolved temporal object; null if resolving only changed the map, or no resolve occurred

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Implements java.time.temporal.TemporalField.toString.

Doc from java.time.temporal.TemporalField.toString.

Gets a descriptive name for the field.

The should be of the format 'BaseOfRange', such as 'MonthOfYear', unless the field has a range of FOREVER, when only the base unit is mentioned, such as 'Year' or 'Era'.

Returns:String

the name of the field, not null

Annotations
@Override
valueOfback to summary
public static JulianFields.Field valueOf(String name)
valuesback to summary
public static JulianFields.Field[] values()