faa.tg.units
Class Time

java.lang.Object
  extended by faa.tg.units.AMeasure
      extended by faa.tg.units.Time
All Implemented Interfaces:
HasText, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<AMeasure>
Direct Known Subclasses:
NasTime, SimulationTime, SystemTime

public class Time
extends AMeasure
implements HasText

 Time represents the object for measuring units of Time.
 
See section 5.6 of the Detailed Design Document for a discussion of design issues.

See the source: Time.java

Version:
$Id: Time.java,v 3.9 2009/01/28 23:58:19 lonnies Exp $
Author:
Tim Kimmet (modeled after Robert G. Oliver's Units Classes)
See Also:
AUnits, AMeasure, Serialized Form

Field Summary
static java.lang.String CVS_VERSION_ID
          The CVS Version ID.
static Time MAX
           
static Time MIN_1
           
static Time MIN_10
           
static Time MIN_5
           
static Time MS_1
           
static Time ONE_MILLISEC
           
static Time ONE_MIN
           
static Time ONE_SEC
           
static Time SEC_1
           
static Time SEC_10
           
static Time SEC_20
           
static Time SEC_5
           
(package private) static long serialVersionUID
           
static java.text.SimpleDateFormat SORT_DATE_FMT
          DateFormat for parsing or writing as: "yyyy/MM/dd_HH:mm:ss".
static java.text.SimpleDateFormat STD_DATE_FMT
          DateFormat for parsing or writing as: "MMM dd, yyyy HH:mm:ss z".
static Time TEN_MIN
           
static Time ZERO
           
 
Fields inherited from class faa.tg.units.AMeasure
DEC0, DEC0_, DEC00, DEC000, DEC1, DEC1_, DEC12, DEC12_, DEC1L, DEC1L_, DEC2, DEC2_, DEC3, DEC3_, DEC4, DEC4_, DEC5, DEC5_, DEC6, DEC6_, DEC7, DEC7_, DEC9, DEC9_, itsValue, TIME_FRACTION
 
Constructor Summary
Time(double value, TimeUnits units)
          Constructor for the Time class.
Time(java.lang.String timeString)
          Constructor for a measure of time.
 
Method Summary
 Time abs()
          This method returns a clone that is the absolute value of this object.
 Time add(Time addend)
          This summation method adds a value with like units.
 double as(TimeUnits theUnits)
          The as method extracts the value from a Measure in specified units.
 boolean eq(Time theMeasure)
          This method provides a test for equality.
 boolean ge(Time theMeasure)
          This method provides a test for less than / equal to.
 boolean gt(Time theMeasure)
          This method provides a test for greater than.
static double hms2sec(java.lang.String timeString)
          Converts the input String in "HH:MM:SS[.SSS]" to a double containing the time in seconds since 00:00:00.
 boolean le(Time theMeasure)
          This method provides a test for greater than / equal to.
 boolean lt(Time theMeasure)
          This method provides a test for less than.
static void main(java.lang.String[] args)
          Main is used for testing only.
static Time now()
           
static double parseSeconds(java.lang.String timeString)
          Converts the input String in "[[H:]MM:]SS[.SSS]" format to a double containing the time in seconds since 00:00:00.
static Time parseTime(java.lang.String timeStr)
          Creates a Time object from a String in a variety of input formats.
 double ratio(Time val)
          This division method produces a dimensionless ratio of like measures.
 Time sub(Time subtrahend)
          This subtraction method subtracts a value with like units.
static Time timeElapsedSince(Time start)
          This method will give you the difference between the start time and now.
 java.lang.String toHhmmString()
          Returns the string representation of this object in the form HHMM (with seconds truncated) which is a NAS representation.
 java.lang.String toHmsString()
          Returns the string representation of this object in the form HH:MM:SS[.SSS] which will display up to thousandths of a second if the time is not a round number.
 java.lang.String toHmsStringInt()
          Returns the string representation of this object in the form HH:MM:SS.
 java.lang.String toString()
          returns a String representation of this object.
 java.lang.String toText()
          Returns the default string representation: "HH:MM:SS[.SSS]".
 
Methods inherited from class faa.tg.units.AMeasure
absoluteValue, add, as, as, clone, compareTo, debug, div, eq, equals, ge, getAUnit, getCanonicalUnit, getCanonicalValue, getInitialUnit, getUnitClass, gt, hashCode, isBetween, le, lt, mul, ratio, sub, toAMeasure, toString, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

CVS_VERSION_ID

public static final java.lang.String CVS_VERSION_ID
The CVS Version ID.

See Also:
Constant Field Values

ZERO

public static final Time ZERO

MS_1

public static final Time MS_1

SEC_1

public static final Time SEC_1

SEC_5

public static final Time SEC_5

SEC_10

public static final Time SEC_10

SEC_20

public static final Time SEC_20

MIN_1

public static final Time MIN_1

MIN_5

public static final Time MIN_5

MIN_10

public static final Time MIN_10

ONE_MILLISEC

public static final Time ONE_MILLISEC

ONE_SEC

public static final Time ONE_SEC

ONE_MIN

public static final Time ONE_MIN

TEN_MIN

public static final Time TEN_MIN

MAX

public static final Time MAX

STD_DATE_FMT

public static final java.text.SimpleDateFormat STD_DATE_FMT
DateFormat for parsing or writing as: "MMM dd, yyyy HH:mm:ss z".


SORT_DATE_FMT

public static final java.text.SimpleDateFormat SORT_DATE_FMT
DateFormat for parsing or writing as: "yyyy/MM/dd_HH:mm:ss".

Constructor Detail

Time

public Time(double value,
            TimeUnits units)
Constructor for the Time class.

Parameters:
value - The magnitude of Time as a double.
units - The units of the value that will be stored (ex: km).

Time

public Time(java.lang.String timeString)
     throws java.lang.NumberFormatException
Constructor for a measure of time. The input is a String in "[[H:]MM:]SS[.SSS]" format.

Parameters:
timeString - Initial time as a String (seconds or HH:MM:SS).
Throws:
java.lang.NumberFormatException - Not numeric and not in [[HH:]MM:]SS[.SSS].
See Also:
parseSeconds(String)
Method Detail

parseSeconds

public static double parseSeconds(java.lang.String timeString)
                           throws java.lang.NumberFormatException
Converts the input String in "[[H:]MM:]SS[.SSS]" format to a double containing the time in seconds since 00:00:00. Accepts more input formats than hms2sec().

Parameters:
timeString - The initial time as a String.
Returns:
Returns double containing the number of seconds since 00:00:00.
Throws:
java.lang.NumberFormatException - Not numeric and not in [[HH:]MM:]SS[.SSS].

parseTime

public static Time parseTime(java.lang.String timeStr)
                      throws java.lang.IllegalArgumentException
Creates a Time object from a String in a variety of input formats.
    HH:MM:SS      MM:SS
    # unitName    #unitName      (for a TimeUnits field name from Units)
    # s       #s        #        (for # in seconds)      

Parameters:
timeStr - Time string in the format "# unitName" or "#" or "#s".
Returns:
Returns the Distance object parsed from the input String.
Throws:
java.lang.NumberFormatException - Number fails to parse after removing unit.
java.lang.IllegalArgumentException - Alphabetic unit found but not valid.

hms2sec

public static double hms2sec(java.lang.String timeString)
Converts the input String in "HH:MM:SS[.SSS]" to a double containing the time in seconds since 00:00:00.

Parameters:
timeString - The initial time in String format (HH:MM:SS[.S*]).
Returns:
Returns a double containing the number of seconds since 00:00:00.
Throws:
java.lang.NumberFormatException - String is not in HH:MM:SS format.

add

public Time add(Time addend)
This summation method adds a value with like units. It overrides the method in the superclass, ensures that a Time is the subtracted value, and does the cast for you.

NOTE: this does not prevent different subclasses of Time from being added. The class of the value returned by the add() is the same as this class (the augend).

Parameters:
addend - The unit of measure to add to this measure.
Returns:
A new Time with the sum of the values.

sub

public Time sub(Time subtrahend)
This subtraction method subtracts a value with like units. It overrides the method in the superclass, ensures that a Time is the subtracted value, and does the cast for you.

NOTE: this does not prevent different subclasses of Time from being subtracted. The class of the value returned by the add() is the same as this class (the minuend).

Parameters:
subtrahend - The unit of measure to subtract from this measure.
Returns:
A new Time with the sum of the values.

now

public static Time now()

timeElapsedSince

public static Time timeElapsedSince(Time start)
This method will give you the difference between the start time and now. Created a start time with new Time(System.currentTimeMillis()) and use it as the start parameter to calculate the time elapsed. This avoids creating an extra Time object and of course dupe code.

Parameters:
start -
Returns:
time passed.

abs

public Time abs()
This method returns a clone that is the absolute value of this object. It also does the cast for you.

Returns:
a clone with the absolute value.

ratio

public double ratio(Time val)
This division method produces a dimensionless ratio of like measures.

Returns:
the ratio of the two measures

eq

public boolean eq(Time theMeasure)
This method provides a test for equality. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns boolean indicating whether values are equal.

lt

public boolean lt(Time theMeasure)
This method provides a test for less than. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns whether this value is less than the given value.

gt

public boolean gt(Time theMeasure)
This method provides a test for greater than. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns whether this value is greater than the given value.

ge

public boolean ge(Time theMeasure)
This method provides a test for less than / equal to. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns result of test for less than or equal to.

le

public boolean le(Time theMeasure)
This method provides a test for greater than / equal to. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns result of test for greater than or equal to.

as

public double as(TimeUnits theUnits)
The as method extracts the value from a Measure in specified units. Override for type safety!

Parameters:
theUnits - the units of the value that will be returned (ex: km)
Returns:
the value of the measure in specified units

toHmsString

public java.lang.String toHmsString()
Returns the string representation of this object in the form HH:MM:SS[.SSS] which will display up to thousandths of a second if the time is not a round number.


toHhmmString

public java.lang.String toHhmmString()
Returns the string representation of this object in the form HHMM (with seconds truncated) which is a NAS representation.


toHmsStringInt

public java.lang.String toHmsStringInt()
Returns the string representation of this object in the form HH:MM:SS. This executes faster than toHmsString().


toString

public java.lang.String toString()
returns a String representation of this object.

Overrides:
toString in class AMeasure
Returns:
A String representing the measure in the canonical unit.
See Also:
AMeasure

toText

public java.lang.String toText()
Returns the default string representation: "HH:MM:SS[.SSS]".

Specified by:
toText in interface HasText

main

public static void main(java.lang.String[] args)
Main is used for testing only.