Class TimeT

java.lang.Object
llnl.gnem.core.util.TimeT
All Implemented Interfaces:
Serializable, Comparable

public class TimeT extends Object implements Comparable, Serializable
The TimeT class is a representation of epoch time (seconds before or after January 1, 1970 00:00:00.0). Internally, the time is stored as a long representing milliseconds (seconds * 1000) and an int representing microseconds. There is no time zone manipulation within this class; all times are considered to be GMT.
Author:
Doug Dodge
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final double
     
    static final int
    Number of seconds in a day
    static final int
    Number of seconds in an hour
    static final int
    Number of seconds in a minute
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default Constructor for the TimeT object.
    TimeT(double epochtime)
    Constructor for the TimeT object that takes a double epoch time.
    TimeT(int year, int month, int day, int hour, int minute, double second)
    Constructor for the TimeT object that takes numerical values for year, month, day, hour, minute, and second.
    TimeT(int year, int jday, int hour, int min, int sec, int msec)
    Constructor for the TimeT object that takes all int values for year, day of year, hour, minute, second, and millisecond.
    TimeT(int year, int month, int day, int hour, int minute, int sec, int msec)
    Constructor for the TimeT object that takes all int values for year, month, day, hour, minute, second, and millisecond.
    TimeT(long epochInMilliseconds)
    Constructor for a TimeT that takes a long holding the number of milliseconds relative to 1970/01/01 00:00:00.0
    TimeT(String stringSpecifier)
     
    TimeT(String timeString, String formatString)
    Constructor for the TimeT object that takes a String representation of the time and a String specifying the format for the time string.
    TimeT(Date date)
     
    TimeT(TimeT other)
    Copy constructor for the TimeT object
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double v)
    Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input double (interpreted as an Epoch time).
    add(TimeT other)
    Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input object.
    int
     
    long
    Return the Epoch time expressed in milliseconds relative to 1970/01/01 00:00:00.0
    static int
    EpochToJdate(double time)
     
    static String
    EpochToString(double time)
     
    static String
    EpochToString2(double time, String format)
     
    boolean
    Return true if the input Object is a TimeT object and if its millisecond and microsecond fields match those from this Object.
    boolean
    ge(TimeT T)
    Return true if this epoch time is greater than or equal to the input epoch time
    int
     
    int
     
     
    static Date
    getDateFrom(String timeString, String formatString)
     
    int
    Gets the dayOfMonth attribute of the TimeT object
    int
    Gets the dayOfYear attribute of the TimeT object
    double
    Gets the epochTime ( time in seconds relative to 1970/01/01 00:00:00.0 )of the TimeT object
    double
     
    int
    Gets the hour attribute of the TimeT object
    int
    Gets the jdate attribute of the TimeT object.
    int
     
    static int
    getMaxDaysOfMonth(int year, int month)
    Gets the MaxDaysOfMonth attribute of the TimeT object
    long
    returns the epochtime in milliseconds
    int
    Gets the minute attribute of the TimeT object
    int
    Gets the month attribute of the TimeT object
    static int
     
    int
     
    int
     
    double
    Gets the second attribute of the TimeT object
    static TimeT
     
    int
     
    int
    Gets the year attribute of the TimeT object
    boolean
    gt(TimeT T)
    Return true if this epoch time is greater than the input epoch time
    int
    Returns a hash code based on the microseconds and milliseconds fields of the object.
    boolean
     
    static boolean
    isLeapYear(int year)
    Determines if the given year is a leap year.
    static double
    jdateToEpoch(int jdate)
     
    static TimeT
    jdateToTimeT(int jdate)
     
    boolean
    le(TimeT T)
    Return true if this epoch time is less than or equal to the input epoch time
    boolean
    lt(TimeT T)
    Return true if this epoch time is less than the input epoch time
    void
    Use the object's toString method to print into a PrintStream
    Round the epoch time to the nearest whole day.
    Round the epoch time to the nearest whole hour.
    Round the epoch time to the nearest whole minute.
    Round the epoch time to the nearest whole second.
    subtract(double v)
     
    subtract(TimeT other)
    Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.
    double
    Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.
    static long
    toMilliseconds(double seconds)
     
    Return a String representation of the time based on the default Time format String.
    toString(String format)
    Return a String representation of the time based on the supplied string template

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • TimeT

      public TimeT()
      Default Constructor for the TimeT object. Gets the system time and converts it to GMT time. That time is used to initialize the TimeT object.
    • TimeT

      public TimeT(int year, int month, int day, int hour, int minute, double second)
      Constructor for the TimeT object that takes numerical values for year, month, day, hour, minute, and second.
      Parameters:
      year - The year (including century, e.g. 1999)
      month - Month of the year January = 1, ... December = 12
      day - Day of the month 0 LT day LTEQ daysInMonth( year, month );
      hour - An integer value from 0 - 23. Note: If hour is outside those bounds, day, month, and year may be changed to force hour into its bounds.
      minute - An integer value from 0 - 59. As with hour, out of range values may force a cascading change of other fields.
      second - A double value from 0 - 59.999999
    • TimeT

      public TimeT(int year, int month, int day, int hour, int minute, int sec, int msec)
      Constructor for the TimeT object that takes all int values for year, month, day, hour, minute, second, and millisecond.
      Parameters:
      year - The year (including century, e.g. 1999)
      month - Month of the year January = 1, ... December = 12
      day - Day of the month 0 LT day LTEQ daysInMonth( year, month );
      hour - An int val ue from 0 - 23. Note: If hour is outside those bounds, day, month, and year may be changed to force hour into its bounds. @param minute An int value from 0 - 59. As with hour, out of range values may force a cascading change of other fields. @param sec An int value from 0 - 59 @param msec A n int value from 0 to 999
    • TimeT

      public TimeT(int year, int jday, int hour, int min, int sec, int msec)
      Constructor for the TimeT object that takes all int values for year, day of year, hour, minute, second, and millisecond.
      Parameters:
      year - The year (including century, e.g. 1999)
      jday - day of the year ( 1 - 365 or 366 in leap years)
      hour - An int value from 0 - 23. Note: If hour is outside those bounds, day, month, and year may be changed to force hour into its bounds.
      sec - An int value from 0 - 59
      msec - An int value from 0 to 999
      min - Description of the Parameter
    • TimeT

      public TimeT(double epochtime)
      Constructor for the TimeT object that takes a double epoch time.
      Parameters:
      epochtime - A double value holding the number of seconds relative to 1970/01/01 00:00:00.0
    • TimeT

      public TimeT(long epochInMilliseconds)
      Constructor for a TimeT that takes a long holding the number of milliseconds relative to 1970/01/01 00:00:00.0
      Parameters:
      epochInMilliseconds - the number of milliseconds relative to 1970/01/01 00:00:00.0
    • TimeT

      public TimeT(String timeString, String formatString) throws ParseException
      Constructor for the TimeT object that takes a String representation of the time and a String specifying the format for the time string.
      Parameters:
      timeString - A String representation of the time, e.g. "1994/02/24 06:17:12.234"
      formatString -

      A format String that specifies how to interpret the time String. The format String must follow the rules of SimpleDateFormat. You must not attempt to specify seconds to more than 1 millisecond of precision. Doing so, will result in an incorrect parse. For example a time String of "12.12345" with a format String of "ss.SSSSS" will result in seconds interpreted as 12.345.

      The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):

      Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996; 96 M Month in year Month July; Jul; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d Day in month Number 10 F Day of week in month Number 2 E Day in week Text Tuesday; Tue a Am/pm marker Text PM H Hour in day (0-23) Number 0 k Hour in day (1-24) Number 24 K Hour in am/pm (0-11) Number 0 h Hour in am/pm (1-12) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time; PST; GMT-08:00 Z Time zone RFC 822 time zone -0800

      Pattern letters are usually repeated, as their number determines the exact presentation: Text: For formatting, if the number of pattern letters is 4 or more, the full form is used; otherwise a short or abbreviated
      Throws:
      ParseException - This exception is thrown if the format String is incompatible with the time String or uses invalid format codes.
      See Also:
    • TimeT

      public TimeT(String stringSpecifier)
    • TimeT

      public TimeT(Date date)
    • TimeT

      public TimeT(TimeT other)
      Copy constructor for the TimeT object
      Parameters:
      other -
  • Method Details

    • add

      public TimeT add(TimeT other)
      Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input object.
      Parameters:
      other -
      Returns:
      A TimeT object whose Epoch time is the sum of the two input Epoch times.
    • subtract

      public TimeT subtract(TimeT other)
      Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.
      Parameters:
      other -
      Returns:
      Resulting epoch time as a double
    • subtractD

      public double subtractD(TimeT other)
      Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.
      Parameters:
      other -
      Returns:
      Resulting epoch time as a double
    • add

      public TimeT add(double v)
      Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input double (interpreted as an Epoch time).
      Parameters:
      v - Some number of seconds.
      Returns:
      A TimeT object whose Epoch time is the sum of the two input Epoch times.
    • subtract

      public TimeT subtract(double v)
      Parameters:
      v - Time in seconds
      Returns:
    • epochAsLong

      public long epochAsLong()
      Return the Epoch time expressed in milliseconds relative to 1970/01/01 00:00:00.0
      Returns:
      The milliseconds relative to 1970/01/01 00:00:00.0
    • getEpochTime

      public double getEpochTime()
      Gets the epochTime ( time in seconds relative to 1970/01/01 00:00:00.0 )of the TimeT object
      Returns:
      The epochTime value
    • getYear

      public int getYear()
      Gets the year attribute of the TimeT object
      Returns:
      An int value representing the year ( including the century )
    • getDayOfYear

      public int getDayOfYear()
      Gets the dayOfYear attribute of the TimeT object
      Returns:
      The dayOfYear value ( 1-365 or 1-366 in a leap year )
    • getJDay

      public int getJDay()
      Returns:
      The day of the year
    • getJdate

      public int getJdate()
      Gets the jdate attribute of the TimeT object. Jdate is the year * 1000 + the DayOfYear, e.g. for the 23rd day of the year 1995 the Jdate is 1995023.
      Returns:
      The jdate value
    • getMonth

      public int getMonth()
      Gets the month attribute of the TimeT object
      Returns:
      The month value (1 - 12)
    • getDayOfMonth

      public int getDayOfMonth()
      Gets the dayOfMonth attribute of the TimeT object
      Returns:
      The dayOfMonth value ( 1 - DaysInMonth( year, month )
    • getHour

      public int getHour()
      Gets the hour attribute of the TimeT object
      Returns:
      The hour value ( 0 - 23 )
    • getMinute

      public int getMinute()
      Gets the minute attribute of the TimeT object
      Returns:
      The minute value ( 0 - 59 )
    • getSecond

      public double getSecond()
      Gets the second attribute of the TimeT object
      Returns:
      The second value ( 0 - 59.999999 )
    • getCalendarSecond

      public int getCalendarSecond()
    • getCalendarMilliSecond

      public int getCalendarMilliSecond()
    • getSec

      public int getSec()
      Returns:
      The integer seconds
    • getMsec

      public int getMsec()
      Returns:
      Fractional seconds times 1000
    • getMilliseconds

      public long getMilliseconds()
      returns the epochtime in milliseconds
      Returns:
      the epoch time in millliseconds
    • roundToSec

      public TimeT roundToSec()
      Round the epoch time to the nearest whole second.
      Returns:
    • roundToMin

      public TimeT roundToMin()
      Round the epoch time to the nearest whole minute.
      Returns:
    • roundToHour

      public TimeT roundToHour()
      Round the epoch time to the nearest whole hour.
      Returns:
    • roundToDay

      public TimeT roundToDay()
      Round the epoch time to the nearest whole day.
      Returns:
    • lt

      public boolean lt(TimeT T)
      Return true if this epoch time is less than the input epoch time
      Parameters:
      T - A TimeT object
      Returns:
      boolean (true if this epoch time is less than the input epoch time, false otherwise)
    • gt

      public boolean gt(TimeT T)
      Return true if this epoch time is greater than the input epoch time
      Parameters:
      T - A TimeT object
      Returns:
      boolean (true if this epoch time is greater than the input epoch time, false otherwise)
    • le

      public boolean le(TimeT T)
      Return true if this epoch time is less than or equal to the input epoch time
      Parameters:
      T - A TimeT object
      Returns:
      boolean (true if this epoch time is less than or equal to the input epoch time, false otherwise)
    • ge

      public boolean ge(TimeT T)
      Return true if this epoch time is greater than or equal to the input epoch time
      Parameters:
      T - A TimeT object
      Returns:
      boolean (true if this epoch time is greater than or equal to the input epoch time, false otherwise)
    • print

      public void print(PrintStream ps)
      Use the object's toString method to print into a PrintStream
      Parameters:
      ps - The input PrintStream
    • getDate

      public Date getDate()
    • toString

      public String toString(String format)
      Return a String representation of the time based on the supplied string template
      Parameters:
      format - A SimpleDateFormat format String. Note: currently TimeString cannot display seconds to a precision better than 1 millisecond, so do not attempt to use more than 3 'S' specifiers. Using more than 3 will cause the fractional seconds value to be zero-padded on the left. For example, if the seconds value is 23.1234 and you use a format specifier that includes 'ss.SSSS', the corresponding part of the output string will be '23.0123'.
      Returns:
      A String representation of the time.
      See Also:
    • toString

      public String toString()
      Return a String representation of the time based on the default Time format String.
      Overrides:
      toString in class Object
      Returns:
      A String representation of the time.
    • equals

      public boolean equals(Object o)
      Return true if the input Object is a TimeT object and if its millisecond and microsecond fields match those from this Object. Note that equals does not compare the format field, so two TimeT objects can compare true even when their default formats differ.
      Overrides:
      equals in class Object
      Parameters:
      o - Input Object putatively a TimeT
      Returns:
      true if o is a TimeT with matching fields.
    • hashCode

      public int hashCode()
      Returns a hash code based on the microseconds and milliseconds fields of the object.
      Overrides:
      hashCode in class Object
      Returns:
      An int hash code value.
    • compareTo

      public int compareTo(Object o)
      Specified by:
      compareTo in interface Comparable
    • toMilliseconds

      public static long toMilliseconds(double seconds)
    • getDateFrom

      public static Date getDateFrom(String timeString, String formatString) throws ParseException
      Throws:
      ParseException
    • getTimeFromDateString

      public static TimeT getTimeFromDateString(String dateStr)
    • getMonthFromString

      public static int getMonthFromString(String month)
    • getMaxDaysOfMonth

      public static int getMaxDaysOfMonth(int year, int month)
      Gets the MaxDaysOfMonth attribute of the TimeT object
      Parameters:
      year - The year containing the month to process.
      month - The month for which days is to be obtained.
      Returns:
      The MaxDaysOfMonth value ( )
    • isLeapYear

      public static boolean isLeapYear(int year)
      Determines if the given year is a leap year.
      Parameters:
      year - An integer value including the century, e.g. 1999
      Returns:
      True if the year is a leap year.
    • EpochToString

      public static String EpochToString(double time)
    • EpochToString2

      public static String EpochToString2(double time, String format)
    • EpochToJdate

      public static int EpochToJdate(double time)
    • jdateToEpoch

      public static double jdateToEpoch(int jdate)
    • jdateToTimeT

      public static TimeT jdateToTimeT(int jdate)
    • getFractionalYear

      public double getFractionalYear()
    • isLeapYear

      public boolean isLeapYear()
    • getWeek

      public int getWeek()