Package jodd.time

Class JulianDate

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class JulianDate
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Julian 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 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 a double.
      • 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 part
        f - fractional part should be in range [0.0, 1.0)
        See Also:
        set(int, double)
      • JulianDate

        public JulianDate​(java.math.BigDecimal bd)
        Creates JD from BigDecimal.
    • 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)
      • 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 to integer. It is calculated by rounding to the nearest integer.
      • doubleValue

        public double doubleValue()
        Returns double value of JD. CAUTION: double values may not be suit for precision math due to loss of precision.
      • toBigDecimal

        public java.math.BigDecimal toBigDecimal()
        Returns BigDecimal value of JD.
      • toString

        public java.lang.String toString()
        Returns string representation of JD.
        Overrides:
        toString in class java.lang.Object
        Returns:
        julian integer as string
      • toMilliseconds

        public long toMilliseconds()
        Converts to milliseconds.
      • toLocalDateTime

        public java.time.LocalDateTime toLocalDateTime()
      • 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:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • clone

        protected JulianDate clone()
        Overrides:
        clone in class java.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).