|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.TimeOfDay
public class TimeOfDay
A time of day.
This class represents the time of day in hours, minutes, and seconds, without regard to any particular date. The default length of a day is 24 hours, or 86,400 seconds. However, clients may create days whose lengths are equal to any positive number of seconds.
Rollover
Many operations on a time-of-day object can lead to a time that is less
than zero or greater than the length of the day. These operations may
choose not to raise an exception, but to instead roll past midnight in
either direction. For example, using a 24-hour day, the add
methods might take a time of 22:00:00 and an addend of 5 hours 43
minutes to give a new time of day of 03:43:00. In general, rollover
is the preferred behavior for methods of this class.
Start of Day vs. End of Day
Related to rollover is the representation of an end-of-day time.
If we use a 24-hour day, midnight can be represented by both
00:00:00.0 and 24:00:00.0. In general this class represents
midnight only by 00:00:00.0. For example the following
method call, myTime.set(24, 0, 0.0);
, will result in a time
of day that behaves as a beginning-of-day value, not as an
end-of-day value. Likewise, any addition or subtraction that
lands exactly on 24:00:00.0 will behave like 00:00:00.0.
There is, however, one way to set an end-of-day value, and that
is by calling the setToEndOfDay
method. After a call
to this method, the time of day will act like an end-of-day value
and will have a text representation of 24:00:00.0.
Version Info:
$Revision: 1707 $ |
$Date: 2008-11-14 10:23:59 -0700 (Fri, 14 Nov 2008) $ |
$Author: dharland $ |
Field Summary | |
---|---|
static BigDecimal |
SIDEREAL_DAY_LENGTH
The length of a sidereal day, in SI seconds. |
static BigDecimal |
STANDARD_DAY_LENGTH
The popular notion that a day is 24 hours long. |
Constructor Summary | |
---|---|
TimeOfDay()
Creates instance whose length of day is the standard twenty four hours. |
|
TimeOfDay(BigDecimal secondsInOneDay)
Creates instance whose length of day is given by secondsInDay . |
Method Summary | |
---|---|
TimeOfDay |
add(BigDecimal value,
TimeUnits units)
Adds the given amount of time to this time of day. |
TimeOfDay |
add(String value,
TimeUnits units)
Adds the given amount of time to this time of day. |
TimeOfDay |
add(TimeDuration duration)
Adds the given amount of time to this time of day. |
TimeOfDay |
clone()
Returns a time of day that is equal to this one. |
int |
compareTo(TimeOfDay other)
Compares this time of day to other for order. |
boolean |
equals(Object o)
Returns true if o is equal to this time of day. |
int |
getHourOfDay()
Returns the hour of the day. |
TimeDuration |
getLengthOfDay()
Returns the length of day on which this time of day is based. |
BigDecimal |
getMilliOfSecond()
Returns the number of milliseconds in this time of day's seconds. |
int |
getMinuteOfHour()
Returns the minute of this time of day's hour. |
BigDecimal |
getSecondOfMinute()
Returns the second of this time of day's minute. |
int |
getSecondOfMinuteWhole()
Returns the whole number of seconds of this time of day's minute. |
TimeDuration |
getTimeSinceMidnight()
Returns the amount of time that has elapsed from midnight until this time of day. |
TimeDuration |
getTimeUntilMidnight()
Returns the amount of time that will elapse from this time of day until midnight. |
int |
hashCode()
Returns a hash code value for this time of day. |
boolean |
isAfter(TimeOfDay other)
Returns true if this time of day is later than other . |
boolean |
isBefore(TimeOfDay other)
Returns true if this time of day is earlier than other . |
boolean |
isInDefaultState()
Returns true if this time of day is in its default state, no matter how it got there. |
static TimeOfDay |
parse(String timeText)
Creates a new time of day based on timeText . |
static TimeOfDay |
parse(String timeText,
BigDecimal secondsInOneDay)
Creates a new time of day by parsing timeText . |
void |
set(BigDecimal secondOfDay)
Sets the time of day to the given seconds-of-day. |
void |
set(int hourOfDay,
int minuteOfHour,
BigDecimal secondOfMinute)
Sets the time of day. |
void |
set(int hourOfDay,
int minuteOfHour,
String secondOfMinute)
Sets the time of day. |
void |
set(String timeText)
Sets the value and units of this time of day based on timeText . |
void |
setToEndOfDay()
Sets this time of day to the end of the day. |
TimeOfDay |
subtract(BigDecimal value,
TimeUnits units)
Subtracts the given amount of time from this time of day. |
TimeOfDay |
subtract(String value,
TimeUnits units)
Subtracts the given amount of time from this time of day. |
TimeOfDay |
subtract(TimeDuration duration)
Subtracts the given amount of time from this time of day. |
TimeDuration |
timeUntil(TimeOfDay other)
Returns the amount of time until this time of day equals other . |
Angle |
toAngle()
Creates an angular representation of this time of day. |
BigDecimal |
toFractionOfDay()
Returns the time of day as a fraction of the length of day. |
String |
toString()
Creates a text representation of this time of day. |
String |
toString(int minFracDigits,
int maxFracDigits)
Creates a text representation of this time of day. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final BigDecimal STANDARD_DAY_LENGTH
public static final BigDecimal SIDEREAL_DAY_LENGTH
Constructor Detail |
---|
public TimeOfDay()
public TimeOfDay(BigDecimal secondsInOneDay)
secondsInDay
.
The time of day is 00:00:00.0.
secondsInOneDay
- the number of seconds in one day.Method Detail |
---|
public static TimeOfDay parse(String timeText)
timeText
.
The parsed text can be in any of the forms supported by
Longitude.parse(String)
. The most commonly used
forms are hh:mm:ss.s and 99h 99m 99.9s.
timeText
- the text to be parsed and converted into a time of day.
If this value is null or "" (the empty
string), a new time corresponding to the start of the
day is returned.
timeText
.
IllegalArgumentException
- if timeText
cannot be parsed.parse(String, BigDecimal)
public static TimeOfDay parse(String timeText, BigDecimal secondsInOneDay)
timeText
.
The parsed text can be in any of the forms supported by
Longitude.parse(String)
. The most commonly used
forms are hh:mm:ss.s and 99h 99m 99.9s.
timeText
- the text to be parsed and converted into a time of day.
If this value is null or "" (the empty
string), a new time corresponding to the start of the
day is returned.secondsInOneDay
- the length of a day, in seconds. This class has two
constants that express time in SI seconds,
STANDARD_DAY_LENGTH
and
SIDEREAL_DAY_LENGTH
, that my be used here.
timeText
.
IllegalArgumentException
- if timeText
cannot be parsed.public void set(int hourOfDay, int minuteOfHour, BigDecimal secondOfMinute)
While there are no restrictions on the values of the individual parameters, their combination must result in a positive finite number of seconds.
hourOfDay
- meant to represent the hour of the day. Typically this
is a value in the range [0,23].minuteOfHour
- meant to represent the minute of an hour. Typically
this is a value in the range [0,59].secondOfMinute
- meant to represent the second of a minute.
Typically this is a value in the range [0.0,60.0).
IllegalArgumentException
- if the number of seconds calculated from
the parameters is negative, infinite, or not a number.public void set(int hourOfDay, int minuteOfHour, String secondOfMinute)
While there are no restrictions on the values of the individual parameters, their combination must result in a positive finite number of seconds.
hourOfDay
- meant to represent the hour of the day. Typically this
is a value in the range [0,23].minuteOfHour
- meant to represent the minute of an hour. Typically
this is a value in the range [0,59].secondOfMinute
- meant to represent the second of a minute.
Typically this is a value in the range [0.0,60.0).
IllegalArgumentException
- if the number of seconds calculated from
the parameters is negative, infinite, or not a number.public void set(BigDecimal secondOfDay)
The secondOfDay
parameter must be a non-negative finite value.
If it is greater than the length of a day, it will be rolled passed
as many midnights as it takes to make it less than the length of a
day.
secondOfDay
- the number of seconds that have elapsed since
midnight to the desired time of day.
IllegalArgumentException
- if secondOfDay
is negative,
infinite, or not a number.public void setToEndOfDay()
This end-of-day value can be reached in no other way. It can not be set by the other setters, and it can not be reached via addition or subtraction.
After this method has been called, this time of day behaves like an end-of-day value. All other values will be before, and less than, this value. Note that any non-negative increment to this time of day -- even an increment of zero -- will result in rollover.
public void set(String timeText)
timeText
.
See parse(String)
for the expected format of
timeText
.
If the parsing fails, this time of day will be kept in its current state.
timeText
- a string that will be converted into
a time of day.
IllegalArgumentException
- if timeText
is not in
the expected form.public int getHourOfDay()
getTimeSinceMidnight().toUnits(TimeUnits.HOUR);which would return 12.58244138888889.
public int getMinuteOfHour()
getTimeSinceMidnight().toUnits(TimeUnits.MINUTE);which would return 754.9464833333333.
public BigDecimal getSecondOfMinute()
getTimeSinceMidnight().toUnits(TimeUnits.SECOND);which would return 45,296.789, and to:
getSecondOfMinuteWhole();which would return 56;
public int getSecondOfMinuteWhole()
getTimeSinceMidnight().toUnits(TimeUnits.SECOND);which would return 45,296.789, and to:
getSecondOfMinute();which would return 56.789;
public BigDecimal getMilliOfSecond()
public TimeDuration getTimeSinceMidnight()
public TimeDuration getTimeUntilMidnight()
public boolean isBefore(TimeOfDay other)
other
.
other
- the time to be tested against this one.
other
.public boolean isAfter(TimeOfDay other)
other
.
other
- the time to be tested against this one.
other
.public boolean isInDefaultState()
A time of day is in its default state if both its current time
and the length of its day are the same as those of a time of day
newly created via the no-argument constructor
.
public TimeDuration timeUntil(TimeOfDay other)
other
.
If the other time of day is equal to this one, the duration returned will have a length of zero. If the other time is later than this one, the duration will be a simple subtraction of this from other. If the other time, though, is earlier than this one, the duration will represent the distance from this time, through midnight, to the other time traveling forward in time. That is, the direction of time is always from this one to the other, even if that represents a longer duration than traversing time in the opposite direction.
Note that the other time must have the same length of day as this one.
other
- the time of day to be reached from this one.
other
.
IllegalArgumentException
- if other
's length of day is not
equal to this object's length of day.public BigDecimal toFractionOfDay()
public TimeDuration getLengthOfDay()
public TimeOfDay add(String value, TimeUnits units)
value
- an amount of time.units
- the units in which value
is expressed.
IllegalArgumentException
- if value
is infinite.public TimeOfDay add(BigDecimal value, TimeUnits units)
value
- an amount of time.units
- the units in which value
is expressed.
IllegalArgumentException
- if value
is infinite.public TimeOfDay add(TimeDuration duration)
duration
- a length of time.
IllegalArgumentException
- if duration
's value is
infinite or NaN.public TimeOfDay subtract(String value, TimeUnits units)
value
- an amount of time.units
- the units in which value
is expressed.
IllegalArgumentException
- if value
is infinite.public TimeOfDay subtract(BigDecimal value, TimeUnits units)
value
- an amount of time.units
- the units in which value
is expressed.
IllegalArgumentException
- if value
is infinite.public TimeOfDay subtract(TimeDuration duration)
duration
- a length of time.
IllegalArgumentException
- if duration
's value is
infinite.public Angle toAngle()
public String toString()
parse(String)
.
toString
in class Object
toString(int, int)
public String toString(int minFracDigits, int maxFracDigits)
parse(String)
.
minFracDigits
- the minimum number of places after the decimal point
for the seconds field.maxFracDigits
- the maximum number of places after the decimal point
for the seconds field.public TimeOfDay clone()
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
public boolean equals(Object o)
o
is equal to this time of day.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(TimeOfDay other)
other
for order.
One time is deemed to be "less than" the other if it is proportionately closer to the beginning of its day than the other.
compareTo
in interface Comparable<TimeOfDay>
other
- the time to which this one is compared.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |