|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.JulianDate
public class 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) |
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 |
---|
public JulianDate()
class comments
for an explanation of
the use of the Date
class.
public JulianDate(Date gregorianCalendarDate)
class comments
for an explanation of
the use of the Date
class.
public JulianDate(BigDecimal julianDate)
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.
public JulianDate(String julianDate)
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.
public JulianDate(int julianDayNumber)
Method Detail |
---|
public static JulianDate makeMjdZero()
modifiedValue()
is zero.public static JulianDate makeFromMjd(BigDecimal modifiedJulianDate)
modifiedJulianDate
- the intial MJD for this Julian Date.
public static JulianDate makeFromMjd(String modifiedJulianDate)
modifiedJulianDate
- the intial MJD for this Julian Date.
public JulianDate set()
class comments
for an explanation of
the use of the Date
class.
public JulianDate set(Date gregorianCalendarDate)
class comments
for an explanation of
the use of the Date
class.
gregorianCalendarDate
- the common form of a date.
public JulianDate set(int julianDayNumber)
julianDayNumber
- an integral representation of a Julian Date.
public JulianDate set(BigDecimal julianDate)
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
- a real number representation of a Julian Date.
public JulianDate set(String julianDate)
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
- a real number representation, in text form, of a Julian Date.
public JulianDate setFromMjd(BigDecimal modifiedJulianDate)
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.
modifiedJulianDate
- a real number representation of a Modified Julian Date.
public JulianDate setFromMjd(String modifiedJulianDate)
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.
modifiedJulianDate
- a real number representation, in text form, of a Modified Julian Date.
public JulianDate add(BigDecimal days)
days
.
days
- the number of whole and fractional days to add to this date.
public JulianDate add(TimeDuration duration)
duration
- the amount by which to increment this date.
public JulianDate subtract(BigDecimal days)
days
.
days
- the number of whole and fractional days to subtract
from this date.
public JulianDate subtract(TimeDuration duration)
duration
- the amount by which to decrement this date.
public BigDecimal value()
public int dayNumber()
real number representation
of this date.
public BigDecimal fraction()
For example, if value()
returns 2,456,789.0123,
dayNumber()
will return 2,456,789 and
this method will return 0.0123.
public BigDecimal modifiedValue()
public int modifiedDayNumber()
real number representation
of
the MJD corresponding to this date.
public BigDecimal modifiedFraction()
For example, if modifiedValue()
returns 56,789.0123,
modifiedDayNumber()
will return 56,789 and
this method will return 0.0123.
public boolean isBefore(JulianDate other)
other
.
other
- the date to be tested against this one.
other
.public boolean isAfter(JulianDate other)
other
.
other
- the date to be tested against this one.
other
.public Date toDate()
See the class comments
for more information on
the use of the Gregorian and Julian calendars made by this class.
public BigDecimal toEpoch()
For example, the Julian Epoch for JD 2451545.0 is 2000.0.
public TimeOfDay toTimeOfDayLocal()
public TimeOfDay toTimeOfDayUtc()
public TimeOfDay toTimeOfDay(TimeZone timeZone)
timeZone
- the time zone for which the returne time of day is applicable.
public String toString()
toString
in class Object
public String toString(int minFracDigits, int maxFracDigits)
minFracDigits
- the minimum number of places after the decimal point.maxFracDigits
- the maximum number of places after the decimal point.
public JulianDate clone()
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
public boolean equals(Object o)
o
is equal to this Julian date.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(JulianDate otherDate)
compareTo
in interface Comparable<JulianDate>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |