net.sf.marineapi.nmea.util
Class Time

java.lang.Object
  extended by net.sf.marineapi.nmea.util.Time

public class Time
extends Object

Represents a time of day in 24-hour clock, i.e. the UTC time used as default in NMEA 0183. Transmitted by TimeSentence.

Author:
Kimmo Tuukkanen
See Also:
TimeSentence, Date

Constructor Summary
Time()
          Creates a new instance of Time using the current system time.
Time(int hour, int min, double sec)
          Creates a new instance of Time with hours, minutes and seconds.
Time(int hour, int min, double sec, int offsetHrs, int offsetMin)
          Creates a new instance of Time with time zone offsets.
Time(String time)
          Creates a new instance of Time based on given String.
 
Method Summary
 boolean equals(Object obj)
           
 int getHour()
          Get the hour of day.
 long getMilliseconds()
          Get time as milliseconds since beginning of day.
 int getMinutes()
          Get the minute of hour.
 int getOffsetHours()
          Get time zone offset hours.
 int getOffsetMinutes()
          Get time zone offset minutes.
 double getSeconds()
          Get the second of minute.
 int hashCode()
           
 void setHour(int hour)
          Set the hour of day.
 void setMinutes(int minutes)
          Set the minute of hour.
 void setOffsetHours(int hours)
          Set time zone offset hours.
 void setOffsetMinutes(int minutes)
          Set time zone offset minutes.
 void setSeconds(double seconds)
          Set seconds of minute.
 void setTime(Date d)
          Set the time by Date.
 Date toDate(Date d)
          Convert to Date.
 String toISO8601()
          Returns the ISO 8601 representation of time (hh:mm:ss+hh:mm).
 String toString()
          Returns the String representation of Time.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Time

public Time()
Creates a new instance of Time using the current system time.


Time

public Time(String time)
Creates a new instance of Time based on given String. Assumes the hhmmss.sss formatting used in NMEA sentences.

Parameters:
time - Timestamp String

Time

public Time(int hour,
            int min,
            double sec)
Creates a new instance of Time with hours, minutes and seconds.

Parameters:
hour - Hour of day
min - Minute of hour
sec - Second of minute

Time

public Time(int hour,
            int min,
            double sec,
            int offsetHrs,
            int offsetMin)
Creates a new instance of Time with time zone offsets.

Parameters:
hour - Hour of day
min - Minute of hour
sec - Second of minute
offsetHrs - Time zone offset hours
offsetMin - Time zone offset minutes
Method Detail

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getHour

public int getHour()
Get the hour of day.

Returns:
the hour

getMilliseconds

public long getMilliseconds()
Get time as milliseconds since beginning of day.

Returns:
Milliseconds

getMinutes

public int getMinutes()
Get the minute of hour.

Returns:
the minute

getOffsetHours

public int getOffsetHours()
Get time zone offset hours. Defaults to 0 (UTC).


getOffsetMinutes

public int getOffsetMinutes()
Get time zone offset minutes. Defaults to 0 (UTC).


getSeconds

public double getSeconds()
Get the second of minute.

Returns:
the second

hashCode

public int hashCode()
Overrides:
hashCode in class Object

setHour

public void setHour(int hour)
Set the hour of day.

Parameters:
hour - the hour to set
Throws:
IllegalArgumentException - If hour value out of bounds 0..23

setMinutes

public void setMinutes(int minutes)
Set the minute of hour.

Parameters:
minutes - the minute to set
Throws:
IllegalArgumentException - If minutes value out of bounds 0..59

setOffsetHours

public void setOffsetHours(int hours)
Set time zone offset hours.

Parameters:
hours - Offset to set (-13..13)
Throws:
IllegalArgumentException - If offset out of bounds.

setOffsetMinutes

public void setOffsetMinutes(int minutes)
Set time zone offset minutes.

Parameters:
minutes - Offset to set (-59..59)
Throws:
IllegalArgumentException - If offset out of bounds.

setSeconds

public void setSeconds(double seconds)
Set seconds of minute.

Parameters:
seconds - Seconds to set
Throws:
IllegalArgumentException - If seconds out of bounds ( 0 < seconds < 60)

setTime

public void setTime(Date d)
Set the time by Date. The date information of is ignored, only hours, minutes and seconds are relevant. Notice also that time zone offset is not affected by this method because Date does not contain zone offset.

Parameters:
d - Date

toDate

public Date toDate(Date d)
Convert to Date. Notice that time zone information is lost in conversion as Date does not contain time zone.

Parameters:
d - Date that defines year, month and day for time.
Returns:
A Date that is combination of specified Date and Time

toString

public String toString()
Returns the String representation of Time. Formats the time in hhmmss.sss format used in NMEA 0183 sentences. Seconds are presented with three decimals regardless of precision returned by getSeconds().

Overrides:
toString in class Object

toISO8601

public String toISO8601()
Returns the ISO 8601 representation of time (hh:mm:ss+hh:mm).



Copyright (C) 2010-2014 Java Marine API authors. All Rights Reserved.