Class JulianDate
- java.lang.Object
-
- jodd.time.JulianDate
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class JulianDate extends java.lang.Object implements java.io.Serializable, java.lang.CloneableJulian Date stamp, for high precision calculations. Julian date is a real number and it basically consists of two parts: integer and fraction. Integer part carries date information, fraction carries time information.The Julian day or Julian day number (JDN) is the (integer) number of days that have elapsed since Monday, January 1, 4713 BC in the proleptic Julian calendar 1. That day is counted as Julian day zero. Thus the multiples of 7 are Mondays. Negative values can also be used.
The Julian Date (JD) is the number of days (with decimal fraction of the day) that have elapsed since 12 noon Greenwich Mean Time (UT or TT) of that day. Rounding to the nearest integer gives the Julian day number.
For calculations that will have time precision of 1e-3 seconds, both fraction and integer part must have enough digits in it. The problem is that integer part is big and, on the other hand fractional is small, and since final Julian date is a sum of this two values, some fraction numerals may be lost. Therefore, for higher precision both fractional and integer part of Julian date real number has to be preserved.
This class stores the unmodified fraction part, but not all digits are significant! For 1e-3 seconds precision, only 8 digits after the decimal point are significant.
- See Also:
TimeUtil, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected doublefractionFraction part of the Julian Date (JD).protected intintegerInteger part of the Julian Date (JD).static JulianDateJD_1970Julian Date for 1970-01-01T00:00:00 (Thursday).static JulianDateJD_2001Julian Date for 2001-01-01T00:00:00 (Monday).private static JulianDateJD_MJD_0Julian Date when Modified Julian Date (MJD) is 0.private static JulianDateJD_RJD_0Julian Date when Reduced Julian Date (RJD) is 0.private static JulianDateJD_TJD_0Julian Date when Truncated Julian Date (TJD) is 0.
-
Constructor Summary
Constructors Constructor Description JulianDate(int i, double f)Creates JD from both integer and fractional part using normalization.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JulianDateadd(double delta)Adds a double delta value and returns a new instance.JulianDateadd(JulianDate jds)Adds two JD and returns a new instance.protected JulianDateclone()intdaysBetween(JulianDate otherDate)Calculates the number of days between two dates.intdaysSpan(JulianDate otherDate)Returns span between two days.booleanequals(java.lang.Object object)static JulianDatefromModifiedJulianDate(double mjd)Returns the JD from a Modified Julian Date (MJD), where date starts from midnight rather than noon.static JulianDatefromReducedJulianDate(double rjd)Returns the JD from a Reduced Julian Date (RJD), used by astronomers.static JulianDatefromTruncatedJulianDate(double tjd)Returns the JD from a Truncated Julian Day (TJD), introduced by NASA for the space program.doublegetFraction()Returns the fraction part of Julian Date (JD).intgetInteger()Returns integer part of the Julian Date (JD).intgetJulianDayNumber()Returns JDN.JulianDategetModifiedJulianDate()Returns Modified Julian Date (MJD), where date starts from midnight rather than noon.JulianDategetReducedJulianDate()Returns Reduced Julian Date (RJD), used by astronomers.intgetSignificantFraction()Calculates and returns significant fraction only as an int.JulianDategetTruncatedJulianDate()Returns Truncated Julian Day (TJD), introduced by NASA for the space program.inthashCode()static JulianDatenow()static JulianDateof(double jd)Creates JD from a double value.static JulianDateof(int i, double f)static JulianDateof(int year, int month, int day, int hour, int minute, int second, int millisecond)static JulianDateof(long milliseconds)static JulianDateof(java.math.BigDecimal bd)static JulianDateof(java.time.Instant instant)static JulianDateof(java.time.LocalDate localDate)static JulianDateof(java.time.LocalDateTime localDateTime)JulianDatesub(double delta)Subtracts a double from current instance and returns a new instance.JulianDatesub(JulianDate jds)Subtracts a JD from current instance and returns a new instance.java.math.BigDecimaltoBigDecimal()ReturnsBigDecimalvalue of JD.doubletoDouble()Returnsdoublevalue of JD.java.time.InstanttoInstant()Converts to Instant.java.time.LocalDateTimetoLocalDateTime()Converts to LocalDateTime at UTC.longtoMilliseconds()Converts to milliseconds.java.lang.StringtoString()Returns string representation of JD.
-
-
-
Field Detail
-
JD_1970
public static final JulianDate JD_1970
Julian Date for 1970-01-01T00:00:00 (Thursday).
-
JD_2001
public static final JulianDate JD_2001
Julian Date for 2001-01-01T00:00:00 (Monday).
-
JD_RJD_0
private static final JulianDate JD_RJD_0
Julian Date when Reduced Julian Date (RJD) is 0. RJD = JD − 2400000
-
JD_MJD_0
private static final JulianDate JD_MJD_0
Julian Date when Modified Julian Date (MJD) is 0. MJD = JD − 2400000.5
-
JD_TJD_0
private static final JulianDate JD_TJD_0
Julian Date when Truncated Julian Date (TJD) is 0. TJD began at midnight at the beginning of May 24, 1968 (Friday).
-
integer
protected int integer
Integer part of the Julian Date (JD).
-
fraction
protected double fraction
Fraction part of the Julian Date (JD). Should be always in [0.0, 1.0) range.
-
-
Constructor Detail
-
JulianDate
public JulianDate(int i, double f)Creates JD from both integer and fractional part using normalization. Normalization means that if fractional part is out of range, values will be correctly fixed.- Parameters:
i- integer partf- fractional part should be in range [0.0, 1.0)
-
-
Method Detail
-
of
public static JulianDate of(double jd)
Creates JD from a double value. CAUTION: double values may not be suited for precision math. If precision is needed, consider passing in a BigDecimal instead.
-
of
public static JulianDate of(java.time.LocalDateTime localDateTime)
-
of
public static JulianDate of(java.time.LocalDate localDate)
-
of
public static JulianDate of(java.time.Instant instant)
-
of
public static JulianDate of(long milliseconds)
-
of
public static JulianDate of(int i, double f)
-
of
public static JulianDate of(int year, int month, int day, int hour, int minute, int second, int millisecond)
-
of
public static JulianDate of(java.math.BigDecimal bd)
-
now
public static JulianDate now()
-
getInteger
public int getInteger()
Returns integer part of the Julian Date (JD).
-
getFraction
public double getFraction()
Returns the fraction part of Julian Date (JD). Returned value is always in [0.0, 1.0) range.
-
getSignificantFraction
public int getSignificantFraction()
Calculates and returns significant fraction only as an int.
-
getJulianDayNumber
public int getJulianDayNumber()
Returns JDN. Note that JDN is not equal tointeger. It is calculated by rounding to the nearest integer.
-
toDouble
public double toDouble()
Returnsdoublevalue of JD. CAUTION: double values may not be suited for precision math due to loss of precision.
-
toBigDecimal
public java.math.BigDecimal toBigDecimal()
ReturnsBigDecimalvalue of JD.
-
toString
public java.lang.String toString()
Returns string representation of JD.- Overrides:
toStringin classjava.lang.Object- Returns:
- Julian date as string
-
toMilliseconds
public long toMilliseconds()
Converts to milliseconds.
-
toInstant
public java.time.Instant toInstant()
Converts to Instant.
-
toLocalDateTime
public java.time.LocalDateTime toLocalDateTime()
Converts to LocalDateTime at UTC.
-
add
public JulianDate add(JulianDate jds)
Adds two JD and returns a new instance.
-
add
public JulianDate add(double delta)
Adds a double delta value and returns a new instance.
-
sub
public JulianDate sub(JulianDate jds)
Subtracts a JD from current instance and returns a new instance.
-
sub
public JulianDate sub(double delta)
Subtracts a double from current instance and returns a new instance.
-
daysBetween
public int daysBetween(JulianDate otherDate)
Calculates the number of days between two dates. Returned value is always positive.
-
daysSpan
public int daysSpan(JulianDate otherDate)
Returns span between two days. Returned value may be positive (when this date is after the provided one) or negative (when comparing to future date).
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
clone
protected JulianDate clone()
- Overrides:
clonein classjava.lang.Object
-
getReducedJulianDate
public JulianDate getReducedJulianDate()
Returns Reduced Julian Date (RJD), used by astronomers. RJD = JD − 2400000
-
getModifiedJulianDate
public JulianDate getModifiedJulianDate()
Returns Modified Julian Date (MJD), where date starts from midnight rather than noon. MJD = JD − 2400000.5
-
getTruncatedJulianDate
public JulianDate getTruncatedJulianDate()
Returns Truncated Julian Day (TJD), introduced by NASA for the space program. TJD began at midnight at the beginning of May 24, 1968 (Friday).
-
fromReducedJulianDate
public static JulianDate fromReducedJulianDate(double rjd)
Returns the JD from a Reduced Julian Date (RJD), used by astronomers. RJD = JD − 2400000
-
fromModifiedJulianDate
public static JulianDate fromModifiedJulianDate(double mjd)
Returns the JD from a Modified Julian Date (MJD), where date starts from midnight rather than noon. MJD = JD − 2400000.5
-
fromTruncatedJulianDate
public static JulianDate fromTruncatedJulianDate(double tjd)
Returns the JD from a Truncated Julian Day (TJD), introduced by NASA for the space program. TJD began at midnight at the beginning of May 24, 1968 (Friday).
-
-