Class JulianDate

java.lang.Object
jodd.time.JulianDate
All Implemented Interfaces:
Serializable, Cloneable

public class JulianDate extends Object implements Serializable, Cloneable
Julian 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:
  • Field Details

    • 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 Details

    • 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 part
      f - fractional part should be in range [0.0, 1.0)
  • Method Details

    • 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(LocalDateTime localDateTime)
    • of

      public static JulianDate of(LocalDate localDate)
    • of

      public static JulianDate of(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(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 to integer. It is calculated by rounding to the nearest integer.
    • toDouble

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

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

      public String toString()
      Returns string representation of JD.
      Overrides:
      toString in class Object
      Returns:
      Julian date as string
    • toMilliseconds

      public long toMilliseconds()
      Converts to milliseconds.
    • toInstant

      public Instant toInstant()
      Converts to Instant.
    • toLocalDateTime

      public 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(Object object)
      Overrides:
      equals in class Object
    • hashCode

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

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