edu.nrao.sss.measure
Class JulianDate

java.lang.Object
  extended by edu.nrao.sss.measure.JulianDate
All Implemented Interfaces:
Cloneable, Comparable<JulianDate>

public class JulianDate
extends Object
implements Cloneable, Comparable<JulianDate>

A Julian Date.

Wikipedia's definition:

The Julian day or Julian day number (JDN) is the integer number of days that have elapsed since the initial epoch defined as noon Universal Time (UT) Monday, January 1, 4713 BC in the proleptic Julian calendar...The Julian date (JD) is a continuous count of days and fractions elapsed since the same initial epoch.

As is the case with the Date class, this class models a date/time concept, not a pure date.

Note on the use of the Gregorian Calendar
This class uses java's GregorianCalendar class to handle historical oddities in day tracking. That class sets the year for the switch over from the Julian to the Gregorian calendar as 1582; England and its colonies, including America, did not convert until 1752. That class also uses the Julian calendar for dates prior to the change to the Gregorian, and then a proleptic Julian for dates prior to 1 March 4 AD. What this means for us is that the conversion of a Julian Date to the more familiar form may not produce the expected results for dates prior to 1753. Since our main use for this class is for more recent dates, and since this class is backed by java's standard calendar, we should not be overly concerned with conversion of dates in the distant past.

Note on Precision
The java Date class has a resolution of one millisecond (1ms). This class employs techniques to keep the resolution of this class as close to that of Date as possible. The goal is to make code like this work without complaint.

   Date       origDate  = someFuncThatReturnsDate();
   JulianDate jd1       = new JulianDate(origDate);
   JulianDate jd2       = new JulianDate(jd1.value());
   Date       otherDate = jd2.toDate();
   
   if (!origDate.equals(otherDate))
     complainVigorously();
 

Without taking pains in the class to make certain the above works properly, the two times could have been off by a millisecond.

Version Info:

$Revision: 1578 $
$Date: 2008-09-24 13:34:32 -0600 (Wed, 24 Sep 2008) $
$Author: dharland $ (last person to modify)

Since:
2007-08-01
Author:
David M. Harland

Constructor Summary
JulianDate()
          Creates a new instance for the current time.
JulianDate(BigDecimal julianDate)
          Creates a new instance for the given Julian Date.
JulianDate(Date gregorianCalendarDate)
          Creates a new instance for the given Gregorian calendar date.
JulianDate(int julianDayNumber)
          Creates a new instance for the given Julian Day Number.
JulianDate(String julianDate)
          Creates a new instance for the given Julian Date.
 
Method Summary
 JulianDate add(BigDecimal days)
          Increments this date by the whole and fractional days.
 JulianDate add(TimeDuration duration)
          Increments this date by the given amount of time.
 JulianDate clone()
          Returns a copy of this date.
 int compareTo(JulianDate otherDate)
           
 int dayNumber()
          Returns the Julian Day Number for this date.
 boolean equals(Object o)
          Returns true if o is equal to this Julian date.
 BigDecimal fraction()
          Returns the fractional portion of the value of this date.
 int hashCode()
          Returns a hash code value for this Julian date.
 boolean isAfter(JulianDate other)
          Returns true if this date is later than other.
 boolean isBefore(JulianDate other)
          Returns true if this date is earlier than other.
static JulianDate makeFromMjd(BigDecimal modifiedJulianDate)
          Returns a new JulianDate for the given MJD.
static JulianDate makeFromMjd(String modifiedJulianDate)
          Returns a new JulianDate for the given MJD.
static JulianDate makeMjdZero()
          Returns a new JulianDate whose time is set to the instance that MJD equals zero.
 int modifiedDayNumber()
          Returns the Modified Julian Day Number for this date.
 BigDecimal modifiedFraction()
          Returns the fractional portion of the modified value of this date.
 BigDecimal modifiedValue()
          Returns the real number representation of the Modified Julian Date (MJD) corresponding this date.
 JulianDate set()
          Sets this date to the current time.
 JulianDate set(BigDecimal julianDate)
          Sets this date to the given time.
 JulianDate set(Date gregorianCalendarDate)
          Sets this date to the given time.
 JulianDate set(int julianDayNumber)
          Sets this date to the given time.
 JulianDate set(String julianDate)
          Sets this date to the given time.
 JulianDate setFromMjd(BigDecimal modifiedJulianDate)
          Sets this date to the given time.
 JulianDate setFromMjd(String modifiedJulianDate)
          Sets this date to the given time.
 JulianDate subtract(BigDecimal days)
          Decrements this date by the whole and fractional days.
 JulianDate subtract(TimeDuration duration)
          Decrements this date by the given amount of time.
 Date toDate()
          Returns a date in the Gregorian, Julian, or proleptic Julian calendar corresponding to this date.
 BigDecimal toEpoch()
          Returns the Julian Epoch for this date.
 String toString()
           
 String toString(int minFracDigits, int maxFracDigits)
          Returns a text representation of this Julian Date.
 TimeOfDay toTimeOfDay(TimeZone timeZone)
          Returns the time of day, in the given time zone, for this Julian Date.
 TimeOfDay toTimeOfDayLocal()
          Returns the time of day, in the local time zone, for this Julian Date.
 TimeOfDay toTimeOfDayUtc()
          Returns the UTC time of day for this Julian Date.
 BigDecimal value()
          Returns a real number representation of this date.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JulianDate

public JulianDate()
Creates a new instance for the current time. See the class comments for an explanation of the use of the Date class.


JulianDate

public JulianDate(Date gregorianCalendarDate)
Creates a new instance for the given Gregorian calendar date. See the class comments for an explanation of the use of the Date class.


JulianDate

public JulianDate(BigDecimal julianDate)
Creates a new instance for the given Julian Date.

The actual value used by this object may differ from the parameter value by as much as 10-7. This is because this class attempts to mimic the millisecond resolution of java's Date class. See the class comments for a longer explanation.


JulianDate

public JulianDate(String julianDate)
Creates a new instance for the given Julian Date.

The actual value used by this object may differ from the parameter value by as much as 10-7. This is because this class attempts to mimic the millisecond resolution of java's Date class. See the class comments for a longer explanation.

Since:
2008-08-14

JulianDate

public JulianDate(int julianDayNumber)
Creates a new instance for the given Julian Day Number.

Method Detail

makeMjdZero

public static JulianDate makeMjdZero()
Returns a new JulianDate whose time is set to the instance that MJD equals zero.

Returns:
a JulianDate where the modifiedValue() is zero.
Since:
2008-09-23

makeFromMjd

public static JulianDate makeFromMjd(BigDecimal modifiedJulianDate)
Returns a new JulianDate for the given MJD.

Parameters:
modifiedJulianDate - the intial MJD for this Julian Date.
Returns:
a new JulianDate for the given MJD.
Since:
2008-09-23

makeFromMjd

public static JulianDate makeFromMjd(String modifiedJulianDate)
Returns a new JulianDate for the given MJD.

Parameters:
modifiedJulianDate - the intial MJD for this Julian Date.
Returns:
a new JulianDate for the given MJD.
Since:
2008-09-23

set

public JulianDate set()
Sets this date to the current time. See the class comments for an explanation of the use of the Date class.


set

public JulianDate set(Date gregorianCalendarDate)
Sets this date to the given time. See the class comments for an explanation of the use of the Date class.

Parameters:
gregorianCalendarDate - the common form of a date.
Returns:
this date.

set

public JulianDate set(int julianDayNumber)
Sets this date to the given time.

Parameters:
julianDayNumber - an integral representation of a Julian Date.
Returns:
this date.

set

public JulianDate set(BigDecimal julianDate)
Sets this date to the given time.

The actual value used by this object may differ from the parameter value by as much as 10-7. This is because this class attempts to mimic the millisecond resolution of java's Date class. See the class comments for a longer explanation.

Parameters:
julianDate - a real number representation of a Julian Date.
Returns:
this date.

set

public JulianDate set(String julianDate)
Sets this date to the given time.

The actual value used by this object may differ from the parameter value by as much as 10-7. This is because this class attempts to mimic the millisecond resolution of java's Date class. See the class comments for a longer explanation.

Parameters:
julianDate - a real number representation, in text form, of a Julian Date.
Returns:
this date.
Since:
2008-08-14

setFromMjd

public JulianDate setFromMjd(BigDecimal modifiedJulianDate)
Sets this date to the given time.

The actual value used by this object may differ from the parameter value by as much as 10-7. This is because this class attempts to mimic the millisecond resolution of java's Date class. See the class comments for a longer explanation.

Parameters:
modifiedJulianDate - a real number representation of a Modified Julian Date.
Returns:
this date.
Since:
2008-09-23

setFromMjd

public JulianDate setFromMjd(String modifiedJulianDate)
Sets this date to the given time.

The actual value used by this object may differ from the parameter value by as much as 10-7. This is because this class attempts to mimic the millisecond resolution of java's Date class. See the class comments for a longer explanation.

Parameters:
modifiedJulianDate - a real number representation, in text form, of a Modified Julian Date.
Returns:
this date.
Since:
2008-09-23

add

public JulianDate add(BigDecimal days)
Increments this date by the whole and fractional days.

Parameters:
days - the number of whole and fractional days to add to this date.
Returns:
this date, after the addition.

add

public JulianDate add(TimeDuration duration)
Increments this date by the given amount of time.

Parameters:
duration - the amount by which to increment this date.
Returns:
this date, after the addition.

subtract

public JulianDate subtract(BigDecimal days)
Decrements this date by the whole and fractional days.

Parameters:
days - the number of whole and fractional days to subtract from this date.
Returns:
this date, after the subtraction.

subtract

public JulianDate subtract(TimeDuration duration)
Decrements this date by the given amount of time.

Parameters:
duration - the amount by which to decrement this date.
Returns:
this date, after the subtraction.

value

public BigDecimal value()
Returns a real number representation of this date.

Returns:
a real number representation of this date.

dayNumber

public int dayNumber()
Returns the Julian Day Number for this date. This is the integer portion of the real number representation of this date.

Returns:
the Julian Day Number for this date.

fraction

public BigDecimal fraction()
Returns the fractional portion of the value of this date.

For example, if value() returns 2,456,789.0123, dayNumber() will return 2,456,789 and this method will return 0.0123.

Returns:
the fractional portion of the value of this date.

modifiedValue

public BigDecimal modifiedValue()
Returns the real number representation of the Modified Julian Date (MJD) corresponding this date. The MJD is 2,400,000.5 days less than the JD.

Returns:
the modified julian date.

modifiedDayNumber

public int modifiedDayNumber()
Returns the Modified Julian Day Number for this date. This is the integer portion of the real number representation of the MJD corresponding to this date.

Returns:
the Julian Day Number for this date.

modifiedFraction

public BigDecimal modifiedFraction()
Returns the fractional portion of the modified value of this date.

For example, if modifiedValue() returns 56,789.0123, modifiedDayNumber() will return 56,789 and this method will return 0.0123.

Returns:
the fractional portion of the modified value of this date.

isBefore

public boolean isBefore(JulianDate other)
Returns true if this date is earlier than other.

Parameters:
other - the date to be tested against this one.
Returns:
true if this date is earlier than other.

isAfter

public boolean isAfter(JulianDate other)
Returns true if this date is later than other.

Parameters:
other - the date to be tested against this one.
Returns:
true if this date is later than other.

toDate

public Date toDate()
Returns a date in the Gregorian, Julian, or proleptic Julian calendar corresponding to this date. The date returned is a copy of the one used internally by this object, so subsequent changes to it will not be reflected herein.

See the class comments for more information on the use of the Gregorian and Julian calendars made by this class.

Returns:
a date in the proleptic Gregorian calendar.

toEpoch

public BigDecimal toEpoch()
Returns the Julian Epoch for this date.

For example, the Julian Epoch for JD 2451545.0 is 2000.0.

Returns:
the Julian Epoch for this date.
Since:
2008-09-19

toTimeOfDayLocal

public TimeOfDay toTimeOfDayLocal()
Returns the time of day, in the local time zone, for this Julian Date.

Returns:
the time of day, in the local time zone, for this Julian Date.
Since:
2008-08-14

toTimeOfDayUtc

public TimeOfDay toTimeOfDayUtc()
Returns the UTC time of day for this Julian Date.

Returns:
the UTC time of day for this Julian Date.
Since:
2008-08-14

toTimeOfDay

public TimeOfDay toTimeOfDay(TimeZone timeZone)
Returns the time of day, in the given time zone, for this Julian Date.

Parameters:
timeZone - the time zone for which the returne time of day is applicable.
Returns:
the time of day, in the given time zone, for this Julian Date.
Since:
2008-08-14

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(int minFracDigits,
                       int maxFracDigits)
Returns a text representation of this Julian Date.

Parameters:
minFracDigits - the minimum number of places after the decimal point.
maxFracDigits - the maximum number of places after the decimal point.
Returns:
a text representation of this Julian Date.

clone

public JulianDate clone()
Returns a copy of this date.

If anything goes wrong during the cloning procedure, a RuntimeException will be thrown.

Overrides:
clone in class Object

equals

public boolean equals(Object o)
Returns true if o is equal to this Julian date.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for this Julian date.

Overrides:
hashCode in class Object

compareTo

public int compareTo(JulianDate otherDate)
Specified by:
compareTo in interface Comparable<JulianDate>


Copyright © 2009. All Rights Reserved.