org.apache.wicket.util.time
Class TimeOfDay

java.lang.Object
  extended by org.apache.wicket.util.value.LongValue
      extended by org.apache.wicket.util.time.TimeOfDay
All Implemented Interfaces:
Serializable, Comparable<LongValue>

public final class TimeOfDay
extends LongValue

An immutable time of day value represented as milliseconds since the most recent midnight.

Values can be constructed using various factory methods:

If an attempt is made to construct an illegal time of day value (one that is greater than 24 hours worth of milliseconds), an IllegalArgumentException will be thrown.

Military hours, minutes and seconds of the time of day can be retrieved by calling the hour, minute, and second methods.

The next occurrence of a given TimeOfDay can be retrieved by calling next() or next(Calendar).

Since:
1.2.6
Author:
Jonathan Locke
See Also:
Serialized Form

Nested Class Summary
static class TimeOfDay.Meridian
          Typesafe AM/PM enumeration.
 
Field Summary
static TimeOfDay.Meridian AM
          Constant for AM time.
static TimeOfDay MIDNIGHT
          Constant for midnight.
static TimeOfDay NOON
          Constant for noon.
static TimeOfDay.Meridian PM
          Constant for PM time.
 
Fields inherited from class org.apache.wicket.util.value.LongValue
value
 
Method Summary
 boolean after(org.apache.wicket.util.time.AbstractTimeValue that)
          Returns true if this Time value is after the given Time argument's value.
 boolean before(org.apache.wicket.util.time.AbstractTimeValue that)
          Returns true if this Time value is before the given Time argument's value.
 long getMilliseconds()
          Retrieves the number of milliseconds in this Time value.
 int hour()
          Retrieves the hour of the day.
static TimeOfDay militaryTime(int hour, int minute, int second)
          Retrieves a TimeOfDay value on a 24-hour clock.
 int minute()
          Retrieves the minute.
 Time next()
          Retrieves the next occurrence of this TimeOfDay in local time.
 Time next(Calendar calendar)
          Retrieves the next occurrence of this TimeOfDay on the given Calendar.
static TimeOfDay now()
          Retrieves the TimeOfDay representing 'now'.
static TimeOfDay now(Calendar calendar)
          Retrieves the TimeOfDay representing 'now' on the given Calendar.
 int second()
          Retrieves the second.
static TimeOfDay time(int hour, int minute, int second, TimeOfDay.Meridian meridian)
          Retrieves a TimeOfDay on a 12-hour clock.
static TimeOfDay time(int hour, int minute, TimeOfDay.Meridian meridian)
          Retrieves a TimeOfDay on a 12-hour clock.
 String toString()
          Converts this Time to a String suitable for use in a file system name.
 String toTimeString()
          Converts this Time to a time String using the formatter 'h.mma'.
 String toTimeString(Calendar calendar)
          Converts this Time to a Date String using the Date formatter 'h.mma'.
static TimeOfDay valueOf(Calendar calendar, String time)
          Converts a time String and Calendar to a TimeOfDay instance.
static TimeOfDay valueOf(Calendar calendar, Time time)
          Converts a Time instance and Calendar to a TimeOfDay instance.
static TimeOfDay valueOf(Duration duration)
          Converts a Duration instance to a TimeOfDay instance.
static TimeOfDay valueOf(long time)
          Converts a long value to a TimeOfDay instance.
static TimeOfDay valueOf(String time)
          Converts a String value to a TimeOfDay instance.
static TimeOfDay valueOf(Time time)
          Converts a String value to a TimeOfDay instance.
 
Methods inherited from class org.apache.wicket.util.value.LongValue
compareTo, equals, greaterThan, greaterThan, hashCode, lessThan, lessThan
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

AM

public static final TimeOfDay.Meridian AM
Constant for AM time.


MIDNIGHT

public static final TimeOfDay MIDNIGHT
Constant for midnight.


PM

public static final TimeOfDay.Meridian PM
Constant for PM time.


NOON

public static final TimeOfDay NOON
Constant for noon.

Method Detail

militaryTime

public static TimeOfDay militaryTime(int hour,
                                     int minute,
                                     int second)
Retrieves a TimeOfDay value on a 24-hour clock.

Parameters:
hour - the hour (0-23)
minute - the minute (0-59)
second - the second (0-59)
Returns:
the time of day

now

public static TimeOfDay now()
Retrieves the TimeOfDay representing 'now'.

Returns:
the time of day it is now

now

public static TimeOfDay now(Calendar calendar)
Retrieves the TimeOfDay representing 'now' on the given Calendar.

Parameters:
calendar - the Calendar to use
Returns:
the time of day it is now on the given Calendar

time

public static TimeOfDay time(int hour,
                             int minute,
                             int second,
                             TimeOfDay.Meridian meridian)
Retrieves a TimeOfDay on a 12-hour clock.

Parameters:
hour - the hour (1-12)
minute - the minute (0-59)
second - the second (0-59)
meridian - AM or PM
Returns:
the TimeOfDay value

time

public static TimeOfDay time(int hour,
                             int minute,
                             TimeOfDay.Meridian meridian)
Retrieves a TimeOfDay on a 12-hour clock.

Parameters:
hour - the hour (1-12)
minute - the minute (0-59)
meridian - AM of PM
Returns:
the TimeOfDay value

valueOf

public static TimeOfDay valueOf(Calendar calendar,
                                String time)
                         throws ParseException
Converts a time String and Calendar to a TimeOfDay instance.

Parameters:
calendar - the Calendar to use when parsing time String
time - a String in 'h.mma' format
Returns:
the TimeOfDay on the given Calendar
Throws:
ParseException

valueOf

public static TimeOfDay valueOf(Calendar calendar,
                                Time time)
Converts a Time instance and Calendar to a TimeOfDay instance.

Parameters:
calendar - the Calendar to use
time - a Time instance
Returns:
the TimeOfDay on the given Calendar

valueOf

public static TimeOfDay valueOf(Duration duration)
Converts a Duration instance to a TimeOfDay instance.

Parameters:
duration - the Duration to use
Returns:
the TimeOfDay of the given Duration

valueOf

public static TimeOfDay valueOf(long time)
Converts a long value to a TimeOfDay instance.

Parameters:
time - the time in milliseconds today
Returns:
the TimeOfDay

valueOf

public static TimeOfDay valueOf(String time)
                         throws ParseException
Converts a String value to a TimeOfDay instance.

Parameters:
time - a String in 'h.mma' format
Returns:
the TimeOfDay
Throws:
ParseException

valueOf

public static TimeOfDay valueOf(Time time)
Converts a String value to a TimeOfDay instance.

Parameters:
time - a Time to convert to TimeOfDay
Returns:
the TimeOfDay in the current time zone

hour

public int hour()
Retrieves the hour of the day.

Returns:
the hour (0-23) of this TimeOfDay

minute

public int minute()
Retrieves the minute.

Returns:
the minute (0-59) of this TimeOfDay

next

public Time next()
Retrieves the next occurrence of this TimeOfDay in local time.

Returns:
the next occurrence of this TimeOfDay in local time

next

public Time next(Calendar calendar)
Retrieves the next occurrence of this TimeOfDay on the given Calendar.

Parameters:
calendar - the Calendar to use
Returns:
the next occurrence of this TimeOfDay on the given Calendar

second

public int second()
Retrieves the second.

Returns:
the second (0-59)

toString

public String toString()
Converts this Time to a String suitable for use in a file system name.

Returns:
this Time as a formatted String
See Also:
Object.toString()

after

public final boolean after(org.apache.wicket.util.time.AbstractTimeValue that)
Returns true if this Time value is after the given Time argument's value.

Parameters:
that - the AbstractTimeValue to compare with
Returns:
true if this Time value is after that Time value

before

public final boolean before(org.apache.wicket.util.time.AbstractTimeValue that)
Returns true if this Time value is before the given Time argument's value.

Parameters:
that - the AbstractTimeValue to compare with
Returns:
true if this Time value is before that Time value

toTimeString

public final String toTimeString()
Converts this Time to a time String using the formatter 'h.mma'.

Returns:
the Time String

toTimeString

public final String toTimeString(Calendar calendar)
Converts this Time to a Date String using the Date formatter 'h.mma'.

Parameters:
calendar - the Calendar to use in the conversion
Returns:
the Date String

getMilliseconds

public final long getMilliseconds()
Retrieves the number of milliseconds in this Time value.

Returns:
the number of milliseconds in this Time value


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.