gov.lanl.Utility
Class DateTime

java.lang.Object
  |
  +--gov.lanl.Utility.DateTime
All Implemented Interfaces:
java.lang.Cloneable

public class DateTime
extends java.lang.Object
implements java.lang.Cloneable

Provides a date/time class to support the data in the TeleMed server Date and time are saved together as a double, with the integer part the Julian date, and the fractional part the time in hours (24 hour standard) divided by 24, down to seconds. ALWAYS GMT! Thus every time stamp in the TeleMed data base has date and time.

The julian conversions are modelled after "Numerical Recipes.." by Press, Teukolsky, Vettering, and Flannery; Cambridge University Press

Modified for PIDS time stamp

 

Constructor Summary
DateTime()
          Create a DateTime object with the current date time return DateTime initialized to the current date and time
DateTime(java.util.Calendar inCalendar)
          Create a DateTime object from a Calendar object
DateTime(int julian)
          Create a DateTime object with the requested julian date
DateTime(int yr, int mo, int da)
          Create a DateTime object with the requested values, 0 for rest
DateTime(int yr, int mo, int da, int hr, int mn, int sc)
          Create a DateTime object with the requested values
 
Method Summary
 void advance(int n)
          Deprecated. Replaced by advanceDays
 void advanceDays(int n)
          Advances this DateTime by n days
 void advanceHours(int hr)
          Advances this DateTime by hr hours
 void advanceMins(int min)
          Advances this DateTime by min minutes
 void advanceSecs(int sec)
          Advances this DateTime by min minutes
 java.lang.Object clone()
           
 int daysBetween(gov.lanl.Utility.DateTime other)
          positive if this is later than the parameter
 void fromJulian(double injulian)
          Converts a TeleMed julian (both date & time) to a DateTime The DataTime object exists and its values are changed
 void fromPIDTime(long thepidtime)
          Converts from PID time to the DateTime class
 int getDay()
           
 int getHour()
           
 int getMin()
           
 int getMonth()
           
 int getSecs()
           
 int getYear()
           
 boolean isValid()
           
 java.util.Calendar makeGMTCalendar()
          Creates a calendar object using GMT timezone
 java.util.Calendar makeLocalCalendar()
          Creates a calendar object using Local timezone
 double toJulian()
           
 long toPIDTime()
          Converts the DateTime to PID time
 int weekday()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateTime

public DateTime()
Create a DateTime object with the current date time return DateTime initialized to the current date and time


DateTime

public DateTime(int yr,
                int mo,
                int da,
                int hr,
                int mn,
                int sc)
Create a DateTime object with the requested values

Throws:
java.lang.IllegalArgumentException - if something wrong in date
Parameters:
yr - year (full year, e.g., 1997)
mo - month ( 1-12)
da - date (1-31)
hr - hour of day (0-23)
mn - minute of hour (0-59)
sc - second of minute (0-59)

DateTime

public DateTime(int yr,
                int mo,
                int da)
Create a DateTime object with the requested values, 0 for rest

Throws:
java.lang.IllegalArgumentException - if something wrong in date
Parameters:
yr - year (full year, e.g., 1997)
mo - month ( 1-12)
da - date (1-31)

DateTime

public DateTime(java.util.Calendar inCalendar)
Create a DateTime object from a Calendar object

Parameters:
inCalendar - is the incomming calendar object

DateTime

public DateTime(int julian)
Create a DateTime object with the requested julian date

Throws:
java.lang.IllegalArgumentException - if something wrong
Parameters:
julian - the date time in our julian expanded format, i.e. date/time
Method Detail

advance

public void advance(int n)
Deprecated. Replaced by advanceDays

Advances this DateTime by n days

Parameters:
n - the number of days by which to change this day, + or -

advanceDays

public void advanceDays(int n)
Advances this DateTime by n days

Parameters:
n - the number of days by which to change this day, + or -

advanceHours

public void advanceHours(int hr)
Advances this DateTime by hr hours

Parameters:
hr - is the number of hours to add

advanceMins

public void advanceMins(int min)
Advances this DateTime by min minutes

Parameters:
min - is the number of minutes to add

advanceSecs

public void advanceSecs(int sec)
Advances this DateTime by min minutes

Parameters:
sec - is the number of minutes to add

getDay

public int getDay()
Returns:
day of the month as an int, 1-31

getMonth

public int getMonth()
Returns:
month as an int, 1-12

getYear

public int getYear()
Returns:
year as an int, all digits

getHour

public int getHour()
Returns:
hour as an int

getMin

public int getMin()
Returns:
minutes as an int

getSecs

public int getSecs()
Returns:
seconds as an int

weekday

public int weekday()
Returns:
the weekday (0-6, Sunday-Saturday)

daysBetween

public int daysBetween(gov.lanl.Utility.DateTime other)
positive if this is later than the parameter

Parameters:
other - any date
Returns:
the number of days between this and the parameter

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object
Returns:
a copy of this object

isValid

public boolean isValid()
Returns:
true if this is a valid DateTime

toJulian

public double toJulian()
Returns:
the julian day as the integer part and the 24hr time as fractional

2440000 was 5/23/68 a Thursday


fromJulian

public void fromJulian(double injulian)
Converts a TeleMed julian (both date & time) to a DateTime The DataTime object exists and its values are changed

Parameters:
injulian - the TeleMed julian daytime number

fromPIDTime

public void fromPIDTime(long thepidtime)
Converts from PID time to the DateTime class

Parameters:
thepidtime - the pid time as a long, has both date and time

toPIDTime

public long toPIDTime()
Converts the DateTime to PID time

Returns:
the PID time as a long, both date and time

makeGMTCalendar

public java.util.Calendar makeGMTCalendar()
Creates a calendar object using GMT timezone

Returns:
a Calendar with GMT time zone set properly

makeLocalCalendar

public java.util.Calendar makeLocalCalendar()
Creates a calendar object using Local timezone

Returns:
a Calendar with Local time zone set properly