org.enblom.time
Interface TimeOfDay

All Superinterfaces:
Comparable<TimeOfDay>, Serializable

public interface TimeOfDay
extends Comparable<TimeOfDay>, Serializable

Represents a specific time of the day (hours, minutes, seconds, milliseconds) in the range 00:00:00.000 - 23:59:59.000.

These time objects are always immutable - they cannot be changed once created.

The natural order of this class orders times in chronological order, and two instances are considered equal if they represent the same hour, minute, second and millisecond.

Example usage

Create new instances: TimeOfDay.factory.now()
TimeOfDay.factory.getDefault()
TimeOfDay.factory.parse(...)
Formatting: TimeOfDay.iso().formatXXX()
TimeOfDay.eur().formatXXX()
TimeOfDay.us().formatXXX()
Serializing TimeOfDay.serialize()
TimeOfDay.factory.deserialize()

Author:
Andreas Enblom

Field Summary
static TimeOfDayFactory factory
          A default implementation of a TimeOfDayFactory, for creating new instances.
 
Method Summary
 boolean equals(Object other)
           
 TimeOfDayFormatter eur()
          Provides a formatter for this time instance that formats times of day according to some de-facto European standard.
 int hashCode()
           
 int hour()
           
 boolean isAfter(int hours, int minutes)
          Determines if this is after (inclusive) the given time of day.
 boolean isAfter(int hours, int minutes, int seconds)
          Determines if this is after (inclusive) the given time of day.
 boolean isBefore(int hours, int minutes)
          Determines if this is before (exclusive) the given time of day.
 boolean isBefore(int hours, int minutes, int seconds)
          Determines if this is before (exclusive) the given time of day.
 boolean isLaterHourThan(TimeOfDay time)
          Determines whether this is in a later hour than the given time of day.
 boolean isLaterMinuteThan(TimeOfDay time)
          Determines whether this is in a later minute than the given time of day.
 boolean isLaterSecondThan(TimeOfDay time)
          Determines whether this is in a later second than the given time.
 TimeOfDayFormatter iso()
          Provides a formatter for this time instance that formats time of day according to the ISO-8601 standard.
 boolean isSameHourAs(TimeOfDay time)
          Determines whether this is in the same hour as the given time of day.
 boolean isSameMinuteAs(TimeOfDay time)
          Determines whether this is in the same minute (of the same hour) as the given time of day.
 boolean isSameSecondAs(TimeOfDay time)
          Determines whether this is in the same second (of the same minute, and hour) as the given time of day.
 int millis()
           
 int minute()
           
 TimeOfDay plusHours(int offset)
          Adds or subtracts the given number of hours to this time of day.
 TimeOfDay plusMillis(int offset)
          Adds or subtracts the given number of milliseconds to this time of day.
 TimeOfDay plusMinutes(int offset)
          Adds or subtracts the given number of minutes to this time of day.
 TimeOfDay plusSeconds(int offset)
          Adds or subtracts the given number of seconds to this time of day.
 int second()
           
 String serialize()
           
 int toInt()
          Creates an int representation of the time of day, which when written in base 10 is the string hhmmssnnn, where nnn is the milliseconds.
 String toString()
          Overrides Object.toString().
 TimeOfDayFormatter us()
          Provides a formatter for this time instance that formats times of day according to the US standard.
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

factory

static final TimeOfDayFactory factory
A default implementation of a TimeOfDayFactory, for creating new instances. The factory will create serializable instances.

Method Detail

hour

int hour()
Returns:
The hour of the time of day, in the range 0-23.

minute

int minute()
Returns:
The minute of the time of day, in the range 0-59.

second

int second()
Returns:
The second of the time of day, in the range 0-59.

millis

int millis()
Returns:
The millisecond of the time of day, in the range 0-999.

plusHours

TimeOfDay plusHours(int offset)
Adds or subtracts the given number of hours to this time of day. If the resulting time is out of range (for instance because it is past midnight), a runtime exception is thrown.

Parameters:
offset - The offset in hours. Can be positive, zero or negative.
Returns:
The resulting time of day.
Throws:
TimeOutOfRangeException - If the resulting time is out of range.

plusMinutes

TimeOfDay plusMinutes(int offset)
Adds or subtracts the given number of minutes to this time of day. If the resulting time of day is out of range (for instance because it is past midnight), a runtime exception is thrown.

Parameters:
offset - The offset in minutes. Can be positive, zero or negative.
Returns:
The resulting time of day.
Throws:
TimeOutOfRangeException - If the resulting time is out of range.

plusSeconds

TimeOfDay plusSeconds(int offset)
Adds or subtracts the given number of seconds to this time of day. If the resulting time of day is out of range (for instance because it is past midnight), a runtime exception is thrown.

Parameters:
offset - The offset in seconds. Can be positive, zero or negative.
Returns:
The resulting time of day.
Throws:
TimeOutOfRangeException - If the resulting time is out of range.

plusMillis

TimeOfDay plusMillis(int offset)
Adds or subtracts the given number of milliseconds to this time of day. If the resulting time of day is out of range (for instance because it is past midnight), a runtime exception is thrown.

Parameters:
offset - The offset in millis. Can be positive, zero or negative.
Returns:
The resulting time of day.
Throws:
TimeOutOfRangeException - If the resulting time is out of range.

isAfter

boolean isAfter(int hours,
                int minutes)
Determines if this is after (inclusive) the given time of day.

Parameters:
hours - The hour part of the time of day to compare to, in the range 0-23.
minutes - The minute part of the time of day to compare to, in the range 0-59.
Returns:
Whether this is after the given time of day.

isAfter

boolean isAfter(int hours,
                int minutes,
                int seconds)
Determines if this is after (inclusive) the given time of day.

Parameters:
hours - The hour part of the time of day to compare to, in the range 0-23.
minutes - The minute part of the time of day to compare to, in the range 0-59.
seconds - The second part of the time of day to compare to, in the range 0-59.
Returns:
Whether this is after the given time of day.

isBefore

boolean isBefore(int hours,
                 int minutes)
Determines if this is before (exclusive) the given time of day.

Parameters:
hours - The hour part of the time of day to compare to, in the range 0-23.
minutes - The minute part of the time of day to compare to, in the range 0-59.
Returns:
Whether this is before the given time of day.

isBefore

boolean isBefore(int hours,
                 int minutes,
                 int seconds)
Determines if this is before (exclusive) the given time of day.

Parameters:
hours - The hour part of the time of day to compare to, in the range 0-23.
minutes - The minute part of the time of day to compare to, in the range 0-59.
seconds - The second part of the time of day to compare to, in the range 0-59.
Returns:
Whether this is before the given time of day.

isLaterHourThan

boolean isLaterHourThan(TimeOfDay time)
Determines whether this is in a later hour than the given time of day.

Parameters:
time - The time of day to compare to.
Returns:
Whether this is in a later hour than the given time of day.

isSameHourAs

boolean isSameHourAs(TimeOfDay time)
Determines whether this is in the same hour as the given time of day.

Parameters:
time - The time of day to compare to.
Returns:
Whether this is in the same hour as the given time of day.

isLaterMinuteThan

boolean isLaterMinuteThan(TimeOfDay time)
Determines whether this is in a later minute than the given time of day. A minute of a later hour or day is always considered to be later, e.g. 10:12 is a later minute than 9:13.

Parameters:
time - The time of day to compare to.
Returns:
Whether this is in a later minute than the given time of day.

isSameMinuteAs

boolean isSameMinuteAs(TimeOfDay time)
Determines whether this is in the same minute (of the same hour) as the given time of day.

Parameters:
time - The time of day to compare to.
Returns:
Whether this is in the same minute as the given time of day.

isLaterSecondThan

boolean isLaterSecondThan(TimeOfDay time)
Determines whether this is in a later second than the given time. A second of a later minute or hour is always considered to be later, e.g. 10:13:15 is a later second than 10:12:25 and than 9:14:25.

Parameters:
time - The time of day to compare to.
Returns:
Whether this is in a later second than the given time of day.

isSameSecondAs

boolean isSameSecondAs(TimeOfDay time)
Determines whether this is in the same second (of the same minute, and hour) as the given time of day.

Parameters:
time - The time of day to compare to.
Returns:
Whether this is in the same second as the given time of day.

hashCode

int hashCode()
Overrides:
hashCode in class Object

equals

boolean equals(Object other)
Overrides:
equals in class Object

iso

TimeOfDayFormatter iso()
Provides a formatter for this time instance that formats time of day according to the ISO-8601 standard.

See also eur() and us(). Incidentally, the three formatting standards ISO, EUR and US coincide for times of day, but they are still kept separate to follow the pattern of Time and DayDate formatters.

Returns:
A formatter for this time that uses the ISO-8601 standard.

eur

TimeOfDayFormatter eur()
Provides a formatter for this time instance that formats times of day according to some de-facto European standard.

See also iso() and us(). Incidentally, the three formatting standards ISO, EUR and US coincide for times of day, but they are still kept separate to follow the pattern of Time and DayDate formatters.

Returns:
A formatter for this time that uses some de-facto European standard.

us

TimeOfDayFormatter us()
Provides a formatter for this time instance that formats times of day according to the US standard.

See also iso() and eur(). Incidentally, the three formatting standards ISO, EUR and US coincide for times of day, but they are still kept separate to follow the pattern of Time and DayDate formatters.

Returns:
A formatter for this time that uses the US standard.

serialize

String serialize()
Returns:
The time of day on the format hhmmssnnn, where nnn is the milliseconds.

toString

String toString()
Overrides Object.toString().

Overrides:
toString in class Object
Returns:
The time of day on the format hh:mm:ss.nnn, where nnn is the milliseconds.

toInt

int toInt()
Creates an int representation of the time of day, which when written in base 10 is the string hhmmssnnn, where nnn is the milliseconds. E.g, the time 16:42:14.308 is represented as the integer 164214308. Note that the maximum value is 235959999, which is a valid int.

Returns:
The int representation.


Copyright © 2013. All Rights Reserved.