public final class JulianDate extends Object implements Comparable<JulianDate>, IEquatable<JulianDate>, IEquatableEpsilon<JulianDate>, ImmutableValueType
int
and the seconds into the day as a double
.
This type assumes that days always have TimeConstants.SecondsPerDay
(86400.0) seconds.
When using a JulianDate
with the CoordinatedUniversalTime
(get
) (UTC)
time standard, a day with a leap second actually has 86401.0 seconds.
The end result is that JulianDate
cannot represent the moment of a leap second in the UTC time standard.
However, it CAN represent the moment of a leap second in InternationalAtomicTime
(get
) (TAI).
Also, subtracting two UTC dates that are on opposite sides of a leap second will correctly take the leap second into account.
Constructor and Description |
---|
JulianDate()
Initializes a new instance.
|
JulianDate(double dayCount)
Initializes a
JulianDate from a double expressing the complete astronomical Julian Date. |
JulianDate(double dayCount,
TimeStandard timeStandard)
Initializes a
JulianDate from a double expressing the complete astronomical Julian Date. |
JulianDate(GregorianDate gregorianDate)
Initializes a
JulianDate from a GregorianDate . |
JulianDate(GregorianDate gregorianDate,
TimeStandard standard)
Initializes a
JulianDate from a GregorianDate where the GregorianDate
is expressed in the given TimeStandard . |
JulianDate(int day,
double secondsOfDay)
Initializes a
JulianDate from the provided values. |
JulianDate(int day,
double secondsOfDay,
TimeStandard timeStandard)
Initializes a
JulianDate from the provided values. |
JulianDate(ZonedDateTime dateTime)
Initializes a
JulianDate from a ZonedDateTime . |
JulianDate(ZonedDateTime dateTime,
TimeStandard standard)
Initializes a
JulianDate from a ZonedDateTime and specified time standard. |
Modifier and Type | Method and Description |
---|---|
JulianDate |
add(Duration duration)
Adds a
Duration to this Julian date, producing a new JulianDate . |
static JulianDate |
add(JulianDate left,
Duration right)
|
JulianDate |
addClamped(Duration duration)
Adds a
Duration to this Julian date, producing a new JulianDate . |
JulianDate |
addDays(double days)
Adds the specified number of days to this date and returns the new date.
|
JulianDate |
addHours(double hours)
Adds the specified number of hours to this date and returns the new date.
|
JulianDate |
addMinutes(double minutes)
Adds the specified number of minutes to this date and returns the new date.
|
JulianDate |
addSeconds(double seconds)
Adds the specified number of seconds to this date and returns the new date.
|
int |
compareTo(JulianDate other)
Compares this instance with another instance of the same type.
|
double |
daysDifference(JulianDate other)
Computes the number of days that have elapsed from this Julian date to the
other Julian date. |
static boolean |
equals(JulianDate left,
JulianDate right)
Returns true if two dates are exactly equal.
|
boolean |
equals(Object obj)
Returns true if this date exactly equals another date.
|
boolean |
equalsEpsilon(JulianDate other,
double epsilon)
Returns true if this date is within
epsilon seconds of the specified date. |
boolean |
equalsType(JulianDate other)
Returns true if this date exactly equals another date.
|
static JulianDate |
getCenterOfWindow(JulianDate referenceEpoch,
double windowLength,
JulianDate date)
Divides time into windows, each of length
windowLength seconds,
with the first window centered on referenceEpoch . |
int |
getDay()
Gets the integer portion of the Julian Date (or astronomical Julian day number).
|
static JulianDate |
getMaxValue()
Gets the largest possible value of
JulianDate . |
static JulianDate |
getMinValue()
Gets the smallest value possible of
JulianDate . |
static JulianDate |
getNow()
Gets the
JulianDate that represents the current system date and time. |
double |
getSecondsOfDay()
Gets the number of seconds past noon on the whole-number Julian Day.
|
TimeStandard |
getStandard()
Gets the
TimeStandard that this astronomical Julian date is based upon. |
double |
getTotalDays()
Gets the total number of whole and fractional days represented by this astronomical Julian date.
|
static boolean |
greaterThan(JulianDate left,
JulianDate right)
Returns true if
left occurs after right . |
static boolean |
greaterThanOrEqual(JulianDate left,
JulianDate right)
Returns true if
left occurs after or at the same time as right . |
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
boolean |
isIdentical(JulianDate other)
Returns true if this date is identical to another date.
|
static double |
julianDateToYearFraction(JulianDate julianDate)
Computes the fraction of the year corresponding to the given Julian date.
|
static boolean |
lessThan(JulianDate left,
JulianDate right)
Returns true if
left occurs before right . |
static boolean |
lessThanOrEqual(JulianDate left,
JulianDate right)
Returns true if
left occurs before or at the same time as right . |
double |
minutesDifference(JulianDate other)
Computes the number of minutes that have elapsed from this Julian date to the
other Julian date. |
static boolean |
notEquals(JulianDate left,
JulianDate right)
Returns true if two dates are NOT exactly equal.
|
double |
secondsDifference(JulianDate other)
Computes the number of seconds that have elapsed from this Julian date to the
other Julian date. |
JulianDate |
subtract(Duration duration)
Subtracts a
Duration from this Julian date, producing a new JulianDate . |
Duration |
subtract(JulianDate subtrahend)
Subtracts another Julian date from this Julian date.
|
static JulianDate |
subtract(JulianDate left,
Duration right)
Subtracts a
Duration from a Julian date, producing a new JulianDate . |
static Duration |
subtract(JulianDate left,
JulianDate right)
Subtracts a Julian date from another Julian date, producing a
Duration . |
JulianDate |
subtractDays(double days)
Subtracts the specified number of days from this date and returns the new date.
|
JulianDate |
subtractHours(double hours)
Subtracts the specified number of hours from this date and returns the new date.
|
JulianDate |
subtractMinutes(double minutes)
Subtracts the specified number of minutes from this date and returns the new date.
|
JulianDate |
subtractSeconds(double seconds)
Subtracts the specified number of seconds to this date and returns the new
date.
|
ZonedDateTime |
toDateTime()
Converts this
JulianDate to a ZonedDateTime
with a default time standard of CoordinatedUniversalTime (get ) (UTC). |
ZonedDateTime |
toDateTime(TimeStandard standard)
Converts this
JulianDate to a ZonedDateTime
expressed in the specified time standard. |
GregorianDate |
toGregorianDate()
Converts this
JulianDate to a GregorianDate
with a default time standard of CoordinatedUniversalTime (get ) (UTC). |
GregorianDate |
toGregorianDate(TimeStandard standard)
Converts this
JulianDate to a GregorianDate
expressed in the specified time standard. |
String |
toString()
Returns the value of this
JulianDate in the standard format. |
JulianDate |
toTimeStandard(TimeStandard timeStandard)
Converts this
JulianDate to the specified time standard. |
boolean |
tryConvertTimeStandard(TimeStandard timeStandard,
JulianDate[] result)
Try to convert this
JulianDate to the specified
TimeStandard , if the specified TimeStandard is
capable of representing this time. |
public JulianDate()
public JulianDate(@Nonnull ZonedDateTime dateTime)
JulianDate
from a ZonedDateTime
.
The time standard will be CoordinatedUniversalTime
(get
) (UTC).dateTime
- The ZonedDateTime
.public JulianDate(@Nonnull GregorianDate gregorianDate)
JulianDate
from a GregorianDate
.
The time standard will be CoordinatedUniversalTime
(get
) (UTC),
except when the gregorianDate
represents time during a leap second.
During a leap second, the JulianDate
will be in the
InternationalAtomicTime
(get
) (TAI) standard.gregorianDate
- The GregorianDate
to use to specify the JulianDate
.public JulianDate(@Nonnull ZonedDateTime dateTime, TimeStandard standard)
JulianDate
from a ZonedDateTime
and specified time standard.dateTime
- The ZonedDateTime
.standard
- The time standard to use for this Julian Date.
The dateTime
is assumed to be expressed in this time standard.public JulianDate(@Nonnull GregorianDate gregorianDate, TimeStandard standard)
JulianDate
from a GregorianDate
where the GregorianDate
is expressed in the given TimeStandard
.
If the date is during a leap second, the JulianDate
will be
expressed in InternationalAtomicTime
(get
) (TAI).gregorianDate
- The GregorianDate
.standard
- The time standard in which the gregorianDate
is expressed.public JulianDate(int day, double secondsOfDay)
JulianDate
from the provided values.
The values will be normalized so that the SecondsOfDay
(get
)
property is less than the length of a day.
The time standard will be International Atomic Time (TAI).day
- The whole number part of the date.secondsOfDay
- The time of day, expressed as seconds past noon on the given whole-number day.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.public JulianDate(int day, double secondsOfDay, TimeStandard timeStandard)
JulianDate
from the provided values.
The values will be normalized so that the SecondsOfDay
(get
)
property is less than the length of the day.day
- The whole number part of the date.secondsOfDay
- The time of day, expressed as seconds past noon on the given whole-number day.timeStandard
- The time standard to use for this Julian Date.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.public JulianDate(double dayCount)
JulianDate
from a double expressing the complete astronomical Julian Date.
The time standard will be InternationalAtomicTime
(get
).dayCount
- The complete astronomical Julian date.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.public JulianDate(double dayCount, TimeStandard timeStandard)
JulianDate
from a double expressing the complete astronomical Julian Date.dayCount
- The complete Julian date.timeStandard
- The time standard to use for this Julian Date.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public static JulianDate getMinValue()
JulianDate
.
This date is in InternationalAtomicTime
(get
) and may not be representable in other time standards.@Nonnull public static JulianDate getMaxValue()
JulianDate
.
This date is in InternationalAtomicTime
(get
) and may not be representable in other time standards.public final double getTotalDays()
public final int getDay()
public final double getSecondsOfDay()
@Nonnull public final TimeStandard getStandard()
TimeStandard
that this astronomical Julian date is based upon.@Nonnull public static JulianDate getNow()
JulianDate
that represents the current system date and time.
The time standard will be CoordinatedUniversalTime
(get
) (UTC).@Nonnull public final JulianDate toTimeStandard(@Nullable TimeStandard timeStandard)
JulianDate
to the specified time standard.
If timeStandard
is null
, no conversion will be performed.
timeStandard
- The requested time standard.JulianDate
using the requested time standard.ArgumentOutOfRangeException
- Thrown when the specified TimeStandard
is not capable of
representing this JulianDate
.public final boolean tryConvertTimeStandard(@Nullable TimeStandard timeStandard, @Nonnull JulianDate[] result)
JulianDate
to the specified
TimeStandard
, if the specified TimeStandard
is
capable of representing this time.
If timeStandard
is null
, no conversion will be performed.
timeStandard
- The requested time standard.result
- On input, an array with one element. On return, the array is populated with
an equivalent JulianDate
using the requested TimeStandard
, if it
is capable of representing this time; otherwise MinValue
(get
).true
if this date could be converted to the requested TimeStandard
; otherwise false
.public final double secondsDifference(@Nonnull JulianDate other)
other
Julian date.
This method subtracts the Julian date on which it is called from the other
Julian date and returns the number of seconds between them.
The computation is done in the time standard of this Julian date,
or the closest standard that is safe for arithmetic if this Julian date's time standard is not safe.
For best performance, this Julian date and the other
Julian date
should have the same time standard, and it should be safe for arithmetic.
other
- The other Julian date, which is the end of the interval.public final double minutesDifference(@Nonnull JulianDate other)
other
Julian date.
This method subtracts the Julian date on which it is called from the other
Julian date and returns the number of minutes between them.
The computation is done in the time standard of this Julian date,
or the closest standard that is safe for arithmetic if this Julian date's time standard is not safe.
For best performance, this Julian date and the other
Julian date
should have the same time standard, and it should be safe for arithmetic.
other
- The other Julian date, which is the end of the interval.public final double daysDifference(@Nonnull JulianDate other)
other
Julian date.
This method subtracts the Julian date on which it is called from the other
Julian date and returns the number of days between them.
The computation is done in the time standard of this Julian date,
or the closest standard that is safe for arithmetic if this Julian date's time standard is not safe.
For best performance, this Julian date and the other
Julian date
should have the same time standard, and it should be safe for arithmetic.
other
- The other Julian date, which is the end of the interval.@Nonnull public final JulianDate add(@Nonnull Duration duration)
Duration
to this Julian date, producing a new JulianDate
.
If the Standard
(get
) of duration
is
different from the Standard
(get
) of this JulianDate
,
this JulianDate
will be converted to
duration
's time standard before performing the addition.
Then, the result will be converted to this JulianDate
's
time standard before it is returned, unless the result cannot be represented in
this JulianDate
's time standard, in which case it will remain in a
TimeStandard
that can represent the result.
duration
- The duration to add.JulianDate
that is the result of the addition.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate addClamped(@Nonnull Duration duration)
Duration
to this Julian date, producing a new JulianDate
.
Unlike JulianDate.add(Duration)
, this method will clamp the result to the valid range
of values for JulianDate
rather than throwing an exception.
In most cases, JulianDate.add(Duration)
should be used instead.
If the Standard
(get
) of duration
is
different from the Standard
(get
) of this JulianDate
,
the JulianDate
will be converted to
duration
's time standard before performing the addition.
Then, the result will be converted to this JulianDate
's
time standard before it is returned, unless the result cannot be represented in
this JulianDate
's time standard, in which case it will remain in a
TimeStandard
that can represent the result.
duration
- The duration to add.JulianDate
that is the result of the addition.
If the result would exceed the valid range of values for a JulianDate
,
the value is clamped to MaxValue
(get
) or MinValue
(get
).@Nonnull public final Duration subtract(@Nonnull JulianDate subtrahend)
This method subtracts the subtrahend
Julian date from this
Julian date and returns the Duration
between them.
The computation is done in the time standard of the subtrahend
,
or the closest standard that is safe for arithmetic if the subtrahend's time standard is not safe.
For best performance, this Julian date and the subtrahend Julian date
should have the same time standard, and it should be safe for arithmetic.
subtrahend
- The Julian Date to subtract from this Julian Date.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a Duration
.@Nonnull public final JulianDate subtract(@Nonnull Duration duration)
Duration
from this Julian date, producing a new JulianDate
.
If the Standard
(get
) of duration
is
different from the Standard
(get
) of this JulianDate
,
this JulianDate
will be converted to
duration
's time standard before performing the subtraction.
Then, the result will be converted to this JulianDate
's
time standard before it is returned, unless the result cannot be represented in
this JulianDate
's time standard, in which case it will remain in a
TimeStandard
that can represent the result.
duration
- The duration to subtract.JulianDate
that is the result of the subtraction.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate addSeconds(double seconds)
seconds
- The number of seconds.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate subtractSeconds(double seconds)
seconds
- The number of seconds.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate addDays(double days)
days
- The number of days.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate subtractDays(double days)
days
- The number of days.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate addMinutes(double minutes)
minutes
- The number of minutes.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate subtractMinutes(double minutes)
minutes
- The number of minutes.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate addHours(double hours)
hours
- The number of hours.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public final JulianDate subtractHours(double hours)
hours
- The number of hours.ArgumentOutOfRangeException
- Thrown when the result represents a value too large to be stored in a JulianDate
.@Nonnull public static Duration subtract(@Nonnull JulianDate left, @Nonnull JulianDate right)
Duration
.
This method subtracts right
from
left
and returns the Duration
between them.
The computation is done in the time standard of right
,
or the closest standard that is safe for arithmetic if right
's time standard is not safe.
For best performance, the left and right Julian dates
should have the same time standard, and it should be safe for arithmetic.
left
- The minuend.right
- The subtrahend.left
minus right
.
The time standard will be the same as the time standard of the subtrahend.@Nonnull public static JulianDate subtract(@Nonnull JulianDate left, @Nonnull Duration right)
Duration
from a Julian date, producing a new JulianDate
.
If the Standard
(get
) of right
is
different from the Standard
(get
) of left
,
left
will be converted to
right
's time standard before performing the subtraction.
Then, the result will be converted to left
's
time standard before it is returned, unless the result cannot be represented in
left
's time standard, in which case it will remain in a
TimeStandard
that can represent the result.
left
- The minuend.right
- The subtrahend.JulianDate
that is the result of the subtraction;
that is, left
minus right
.@Nonnull public static JulianDate add(@Nonnull JulianDate left, @Nonnull Duration right)
Duration
to a JulianDate
, producing a new JulianDate
.
If the Standard
(get
) of right
is
different from the Standard
(get
) of left
,
left
will be converted to
right
's time standard before performing the addition.
Then, the result will be converted to left
's
time standard before it is returned, unless the result cannot be represented in
left
's time standard, in which case it will remain in a
TimeStandard
that can represent the result.
left
- The Julian date.right
- The duration.JulianDate
that is the result of the addition.public static boolean equals(@Nonnull JulianDate left, @Nonnull JulianDate right)
Day
(get
) and SecondsOfDay
(get
)
must be identical when converted to a common time standard.
It is highly recommended that you use JulianDate.equalsEpsilon(agi.foundation.time.JulianDate, double)
or
JulianDate.isIdentical(agi.foundation.time.JulianDate)
instead of this method.left
- The date on the left side.right
- The date on the right side.true
if the dates are equal; otherwise false
.public static boolean notEquals(@Nonnull JulianDate left, @Nonnull JulianDate right)
Day
(get
) and SecondsOfDay
(get
)
must be identical when converted to a common time standard.
It is highly recommended that you use JulianDate.equalsEpsilon(agi.foundation.time.JulianDate, double)
or
JulianDate.isIdentical(agi.foundation.time.JulianDate)
instead of this method.left
- The date on the left side.right
- The date on the right side.true
if the dates are not equal; otherwise false
.public static boolean lessThan(@Nonnull JulianDate left, @Nonnull JulianDate right)
left
occurs before right
.left
- The date on the left side.right
- The date on the right side.true
if the left
is less than right
; otherwise false
.public static boolean greaterThan(@Nonnull JulianDate left, @Nonnull JulianDate right)
left
occurs after right
.left
- The date on the left side.right
- The date on the right side.true
if the left
is greater than right
; otherwise false
.public static boolean lessThanOrEqual(@Nonnull JulianDate left, @Nonnull JulianDate right)
left
occurs before or at the same time as right
.left
- The date on the left side.right
- The date on the right side.true
if the left
is less than or equal to right
; otherwise false
.public static boolean greaterThanOrEqual(@Nonnull JulianDate left, @Nonnull JulianDate right)
left
occurs after or at the same time as right
.left
- The date on the left side.right
- The date on the right side.true
if the left
is greater than or equal to right
; otherwise false
.public boolean equals(Object obj)
Day
(get
) and SecondsOfDay
(get
)
must be identical when converted to a common time standard.
It is highly recommended that you use JulianDate.equalsEpsilon(agi.foundation.time.JulianDate, double)
or
JulianDate.isIdentical(agi.foundation.time.JulianDate)
instead of this method.equals
in class Object
obj
- The object to compare to this instance.true
if obj
represents the same value as this instance; otherwise false
.Object.hashCode()
,
HashMap
public final boolean equalsType(@Nonnull JulianDate other)
Day
(get
) and SecondsOfDay
(get
)
must be identical when converted to a common time standard.
It is highly recommended that you use JulianDate.equalsEpsilon(agi.foundation.time.JulianDate, double)
or
JulianDate.isIdentical(agi.foundation.time.JulianDate)
instead of this method.equalsType
in interface IEquatable<JulianDate>
other
- The date to compare to this instance.true
if other
represents the same value as this instance; otherwise false
.public final boolean isIdentical(@Nonnull JulianDate other)
JulianDate.equalsType(JulianDate)
, this method will
consider two dates with different time standards to be different,
even if the dates represent the same moment when expressed in the same time standard.other
- The date to compare to this instance.true
if other
is identical to this instance; otherwise false
.public final boolean equalsEpsilon(@Nonnull JulianDate other, double epsilon)
epsilon
seconds of the specified date.
That is, in order for the dates to be considered equal (and for
this function to return true), the absolute value of the difference between them,
in seconds, must be less than or equal to epsilon
.equalsEpsilon
in interface IEquatableEpsilon<JulianDate>
other
- The date to compare to this date.epsilon
- The largest difference between the dates, in seconds, such that they will be considered equal.public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
JulianDate
in the standard format.public final int compareTo(@Nonnull JulianDate other)
compareTo
in interface Comparable<JulianDate>
other
- An object to compare with this instance.Value | Meaning |
---|---|
Less than zero |
This instance is less than other .
|
Zero |
This instance is equal to other .
|
Greater than zero |
This instance is greater than other .
|
@Nonnull public final ZonedDateTime toDateTime()
JulianDate
to a ZonedDateTime
with a default time standard of CoordinatedUniversalTime
(get
) (UTC).ZonedDateTime
.@Nonnull public final ZonedDateTime toDateTime(TimeStandard standard)
JulianDate
to a ZonedDateTime
expressed in the specified time standard.standard
- The time standard in which to express the returned ZonedDateTime
.ZonedDateTime
.@Nonnull public final GregorianDate toGregorianDate()
JulianDate
to a GregorianDate
with a default time standard of CoordinatedUniversalTime
(get
) (UTC).GregorianDate
.ArgumentOutOfRangeException
- Thrown when this date is earlier than 1 AD or later than 9999 AD, which cannot be represented by GregorianDate
.@Nonnull public final GregorianDate toGregorianDate(TimeStandard standard)
JulianDate
to a GregorianDate
expressed in the specified time standard.standard
- The time standard in which to express the returned GregorianDate
.GregorianDate
.ArgumentOutOfRangeException
- Thrown when this date is earlier than 1 AD or later than 9999 AD, which cannot be represented by GregorianDate
.@Nonnull public static JulianDate getCenterOfWindow(@Nonnull JulianDate referenceEpoch, double windowLength, @Nonnull JulianDate date)
windowLength
seconds,
with the first window centered on referenceEpoch
.
Then, identifies which window contains date
and returns the date that is at the center of that window.
This is helpful for computing a discrete value for a range of Julian dates.referenceEpoch
- The Julian date that defines the start of a window.windowLength
- The length of each window, in seconds.date
- The date to find.public static double julianDateToYearFraction(@Nonnull JulianDate julianDate)
julianDate
- The current Julian date.