gov.nasa.gsfc.drl.rtstps.core.output.hdf5
Class PDSDate

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.core.output.hdf5.PDSDate
All Implemented Interfaces:
java.lang.Comparable<PDSDate>

public class PDSDate
extends java.lang.Object
implements java.lang.Comparable<PDSDate>

Manipulate a date given a packet time in the following format, calculate year, day, month, day of year, hour, minute and seconds. The 10 lines of code which calculate year, day, month were taken from getCal in TimeDate in the checker package. The day of year tables were taken from http://disc.gsfc.nasa.gov/julian_calendar.shtml Note: much of this was taken from an earlier implementation in CRECBuilder


Field Summary
private  long day
           
private  int[][] dayInLeapYear
           
private  int[][] dayInPerpetual
           
private  long dayOfYear
           
private static long DaysBetweenEpochs
           
private static double EPOCH_DATE
           
private  long hours
           
private static long MicrosPerDay
           
private static long MillisBetweenEpochs
           
private  long milliseconds
           
private static long MillisPerDay
           
private  long minutes
           
private  long month
           
private  long packetTime
           
private  long rawDay
           
private  long rawMicros
           
private  long rawMillis
           
private  long seconds
           
private  long year
           
 
Constructor Summary
PDSDate(int year, int month, int day, int hour, int minute, int second, int milliseconds, int microseconds)
          Rough approximation into Mission Epoch date/time.
PDSDate(long packetTime)
          Constructor, supply a packet time in the following format from epoch 1/1/58.
 
Method Summary
private  void calculate()
          Calculate the new year, month, days of year, hours, minutes, seconds, milliseconds...
 int compareTo(PDSDate dateTime)
          public static PDSDate createTimeDate(String dateStr, DateFormat dateFormat, String timeStr, DateFormat timeFormat) throws RtStpsException { //System.out.println("The date strings: " + dateStr + " time:" + timeStr); Calendar dateCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); Date date = dateCal.getTime(); date.setTime(0L); try { // NOTE: If the timezone is set to UTC, this seems to add 5 hrs to the value being parsed // So leaving it off, seems to retrieve the hours as they are specified in the string // date = dateFormat.parse(dateStr); } catch (ParseException e) { throw new RtStpsException(e); } dateCal.setTime(date); Calendar timeCal = Calendar.getInstance(TimeZone.getTimeZone("UTC") ); Date time = timeCal.getTime(); time.setTime(0L); try { // NOTE: If the timezone is set to UTC, this seems to add 5 hrs to the value being parsed // So leaving it off, seems to retrieve the hours as they are specified in the string // time = timeFormat.parse(timeStr); } catch (ParseException e) { throw new RtStpsException(e); } timeCal.setTime(time); // PDSDate(int year, int month, int day, int hour, int minute, int second, int milliseconds) { int year = dateCal.get(Calendar.YEAR); int month = dateCal.get(Calendar.MONTH); int dayOfMonth = dateCal.get(Calendar.DAY_OF_MONTH); int hourOfDay = timeCal.get(Calendar.HOUR_OF_DAY); int minute = timeCal.get(Calendar.MINUTE); int second = timeCal.get(Calendar.SECOND); int milliSecond = timeCal.get(Calendar.MILLISECOND); // PDSDate(int year, int month, int day, int hour, int minute, int second, int milliseconds) { /** System.out.println("year: " + year); System.out.println("month: " + month); System.out.println("dayOfMonth: " + dayOfMonth); System.out.println("hourOfDay: " + hourOfDay); System.out.println("minute: " + minute); System.out.println("second: " + second); System.out.println("milliSecond: " + milliSecond); // PDSDate dateTime = new PDSDate(year, month, dayOfMonth, hourOfDay, minute, second, milliSecond); //SimpleDateFormat df = new SimpleDateFormat(); //System.out.println("Created date/time: " + df.format(dateTime.getDate())); // return dateTime; //}
private  int dayOfYear(int year, int month, int day)
          Calculate the day of the year using the calendar tables.
private  int daysSinceEpoch(int year)
          Count up the days since the epoch per year.
 java.util.Date getDate()
          Return the Java Date, the epoch is converted and the timezone is UTC The returned Date if simply printed will be relative this your timezone.
 long getDayOfMonth()
          Get the calculated day of month
 long getDayOfYear()
          Get the calculated day of the year
 long getHours()
          Get the calculated hours of day
 long getMicroseconds()
          Get any remaining microseconds of millisecond
 long getMicrosSinceEpoch()
          Return the micros since the mission epoch
static long getMicrosSinceEpoch(long packetTime)
          Static variation given a 64-bit mission time (segmented)
 long getMilliseconds()
          Get the calculated milliseconds of second
 long getMinutes()
          Get the calculated minutes of hour
 long getMonth()
          Get the calculated month of the year
 long getPacketTime()
          Return the 64-bit timestamp
 long getRawDay()
          Get the raw day from the packet time
 long getRawMicros()
          Get the raw microseconds from the packet time
 long getRawMillis()
          Get the raw milliseconds from the packet time
 long getSeconds()
          Get the calculated seconds of minute
 long getYear()
          Get the calculated year, four digits
 boolean isLeapYear(int year)
          Determine if this is a leapyear or not
 java.lang.String toRawFields()
          Return just the raw fields
static java.lang.String toRawFields(long packetTime)
          Return just the raw fields, static version
 java.lang.String toString()
          Convert the results to String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EPOCH_DATE

private static final double EPOCH_DATE
See Also:
Constant Field Values

MillisPerDay

private static final long MillisPerDay
See Also:
Constant Field Values

MicrosPerDay

private static final long MicrosPerDay
See Also:
Constant Field Values

DaysBetweenEpochs

private static final long DaysBetweenEpochs
See Also:
Constant Field Values

MillisBetweenEpochs

private static final long MillisBetweenEpochs
See Also:
Constant Field Values

dayInPerpetual

private int[][] dayInPerpetual

dayInLeapYear

private int[][] dayInLeapYear

rawDay

private long rawDay

rawMillis

private long rawMillis

rawMicros

private long rawMicros

year

private long year

month

private long month

day

private long day

hours

private long hours

minutes

private long minutes

seconds

private long seconds

milliseconds

private long milliseconds

dayOfYear

private long dayOfYear

packetTime

private long packetTime
Constructor Detail

PDSDate

public PDSDate(long packetTime)
Constructor, supply a packet time in the following format from epoch 1/1/58.
    Uint16 day since 1/1/1958
    Uint32 millisecond of day
    Uint16 microsecond of millisecond
 

Parameters:
packetTime -

PDSDate

public PDSDate(int year,
               int month,
               int day,
               int hour,
               int minute,
               int second,
               int milliseconds,
               int microseconds)
Rough approximation into Mission Epoch date/time.

Parameters:
year - the year
month - the month, starts at 0 for January
day - the day of month, starts at 1
hour - the hour of day
minute - the minute of the hour
second - the seconds in the minute
milliseconds - the milliseconds of the second
microsecond - of the millis
Method Detail

getPacketTime

public long getPacketTime()
Return the 64-bit timestamp

Returns:
long

getRawDay

public long getRawDay()
Get the raw day from the packet time

Returns:
a long

getRawMillis

public long getRawMillis()
Get the raw milliseconds from the packet time

Returns:
a long

getRawMicros

public long getRawMicros()
Get the raw microseconds from the packet time

Returns:
a long

getMonth

public long getMonth()
Get the calculated month of the year

Returns:
a long

getYear

public long getYear()
Get the calculated year, four digits

Returns:
a long

getDayOfMonth

public long getDayOfMonth()
Get the calculated day of month

Returns:
an integer

getDayOfYear

public long getDayOfYear()
Get the calculated day of the year

Returns:
an integer

getMilliseconds

public long getMilliseconds()
Get the calculated milliseconds of second

Returns:
a long

getMicroseconds

public long getMicroseconds()
Get any remaining microseconds of millisecond

Returns:
a long

getSeconds

public long getSeconds()
Get the calculated seconds of minute

Returns:
a long

getMinutes

public long getMinutes()
Get the calculated minutes of hour

Returns:
a long

getHours

public long getHours()
Get the calculated hours of day

Returns:
a long

getMicrosSinceEpoch

public long getMicrosSinceEpoch()
Return the micros since the mission epoch

Returns:
64 bits of microseconds, signed

getMicrosSinceEpoch

public static long getMicrosSinceEpoch(long packetTime)
Static variation given a 64-bit mission time (segmented)

Parameters:
packetTime - 48 bits of time, 16 bits millis and 16 bits of micros
Returns:
the micros since epoch in a signed 64-bit quantity

isLeapYear

public boolean isLeapYear(int year)
Determine if this is a leapyear or not

Parameters:
year -
Returns:
true if

daysSinceEpoch

private int daysSinceEpoch(int year)
Count up the days since the epoch per year. The leaps year days are added based on the leap year calculation... no provision is made to check that the year given is on or before the epoch year

Parameters:
year - a year since 1958
Returns:
the total days including leap year days since that year

dayOfYear

private int dayOfYear(int year,
                      int month,
                      int day)
Calculate the day of the year using the calendar tables.

Parameters:
month - the month of the year starting at zero for January
day - the day of the month starting at zero for the 1st day
Returns:
the day of the year

getDate

public java.util.Date getDate()
Return the Java Date, the epoch is converted and the timezone is UTC The returned Date if simply printed will be relative this your timezone. To convert to UTC, use the DateFormat classes.

Returns:
the Date in the local time zone, specify the UTC to display it in proper mission time timezone

toRawFields

public java.lang.String toRawFields()
Return just the raw fields


toRawFields

public static java.lang.String toRawFields(long packetTime)
Return just the raw fields, static version


toString

public java.lang.String toString()
Convert the results to String

Overrides:
toString in class java.lang.Object

calculate

private void calculate()
Calculate the new year, month, days of year, hours, minutes, seconds, milliseconds...


compareTo

public int compareTo(PDSDate dateTime)
public static PDSDate createTimeDate(String dateStr, DateFormat dateFormat, String timeStr, DateFormat timeFormat) throws RtStpsException { //System.out.println("The date strings: " + dateStr + " time:" + timeStr); Calendar dateCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); Date date = dateCal.getTime(); date.setTime(0L); try { // NOTE: If the timezone is set to UTC, this seems to add 5 hrs to the value being parsed // So leaving it off, seems to retrieve the hours as they are specified in the string // date = dateFormat.parse(dateStr); } catch (ParseException e) { throw new RtStpsException(e); } dateCal.setTime(date); Calendar timeCal = Calendar.getInstance(TimeZone.getTimeZone("UTC") ); Date time = timeCal.getTime(); time.setTime(0L); try { // NOTE: If the timezone is set to UTC, this seems to add 5 hrs to the value being parsed // So leaving it off, seems to retrieve the hours as they are specified in the string // time = timeFormat.parse(timeStr); } catch (ParseException e) { throw new RtStpsException(e); } timeCal.setTime(time); // PDSDate(int year, int month, int day, int hour, int minute, int second, int milliseconds) { int year = dateCal.get(Calendar.YEAR); int month = dateCal.get(Calendar.MONTH); int dayOfMonth = dateCal.get(Calendar.DAY_OF_MONTH); int hourOfDay = timeCal.get(Calendar.HOUR_OF_DAY); int minute = timeCal.get(Calendar.MINUTE); int second = timeCal.get(Calendar.SECOND); int milliSecond = timeCal.get(Calendar.MILLISECOND); // PDSDate(int year, int month, int day, int hour, int minute, int second, int milliseconds) { /** System.out.println("year: " + year); System.out.println("month: " + month); System.out.println("dayOfMonth: " + dayOfMonth); System.out.println("hourOfDay: " + hourOfDay); System.out.println("minute: " + minute); System.out.println("second: " + second); System.out.println("milliSecond: " + milliSecond); // PDSDate dateTime = new PDSDate(year, month, dayOfMonth, hourOfDay, minute, second, milliSecond); //SimpleDateFormat df = new SimpleDateFormat(); //System.out.println("Created date/time: " + df.format(dateTime.getDate())); // return dateTime; //}

Specified by:
compareTo in interface java.lang.Comparable<PDSDate>