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 consist 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).
-
Constructor Summary
Constructors Constructor Description JulianDate(double jd)Creates JD from adouble.JulianDate(int i, double f)Creates JD from both integer and fractional part using normalization.JulianDate(java.math.BigDecimal bd)Creates JD fromBigDecimal.
-
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.doubledoubleValue()Returnsdoublevalue of JD.booleanequals(java.lang.Object object)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 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.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.java.time.LocalDateTimetoLocalDateTime()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).
-
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(double jd)
Creates JD from adouble.
-
JulianDate
public JulianDate(int i, double f)Creates JD from both integer and fractional part using normalization. Normalization occurs when fractional part is out of range.- Parameters:
i- integer partf- fractional part should be in range [0.0, 1.0)- See Also:
set(int, double)
-
JulianDate
public JulianDate(java.math.BigDecimal bd)
Creates JD fromBigDecimal.
-
-
Method Detail
-
of
public static JulianDate of(double value)
-
of
public static JulianDate of(java.time.LocalDateTime localDateTime)
-
of
public static JulianDate of(java.time.LocalDate localDate)
-
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)
-
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.
-
doubleValue
public double doubleValue()
Returnsdoublevalue of JD. CAUTION: double values may not be suit 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 integer as string
-
toMilliseconds
public long toMilliseconds()
Converts to milliseconds.
-
toLocalDateTime
public java.time.LocalDateTime toLocalDateTime()
-
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. RJD = 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).
-
-