wicket.util.time
Class TimeOfDay

java.lang.Object
  extended by wicket.util.value.LongValue
      extended by wicket.util.time.TimeOfDay
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

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 hour(), minute() and second().

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

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 wicket.util.value.LongValue
value
 
Method Summary
 boolean after(wicket.util.time.AbstractTimeValue that)
           
 boolean before(wicket.util.time.AbstractTimeValue that)
           
 long getMilliseconds()
           
 int hour()
          Gets the hour of the day.
static TimeOfDay militaryTime(int hour, int minute, int second)
          Gets a time of day value on a 24 hour clock.
 int minute()
          Gets the minute.
 Time next()
          Gets the next occurrence of this time of day in localtime.
 Time next(java.util.Calendar calendar)
          Gets the next occurence of this time of day on the given calendar.
static TimeOfDay now()
          Gets the time of day it is now.
static TimeOfDay now(java.util.Calendar calendar)
          Gets the time of day it is now on the given calendar.
 int second()
          Gets the second.
static TimeOfDay time(int hour, int minute, int second, TimeOfDay.Meridian meridian)
          Gets a time of day on a 12 hour clock.
static TimeOfDay time(int hour, int minute, TimeOfDay.Meridian meridian)
          Gets a time of day on a 12 hour clock.
 java.lang.String toString()
          Converts this time to a string suitable for use in a filesystem name
 java.lang.String toTimeString()
          Converts this time to a time string using the formatter h.mma
 java.lang.String toTimeString(java.util.Calendar calendar)
          Converts this time to a date string using the date formatter h.mma
static TimeOfDay valueOf(java.util.Calendar calendar, java.lang.String time)
          Converts to TimeOfDay instance.
static TimeOfDay valueOf(java.util.Calendar calendar, Time time)
          Converts to TimeOfDay instance.
static TimeOfDay valueOf(Duration duration)
          Converts to TimeOfDay instance.
static TimeOfDay valueOf(long time)
          Converts to TimeOfDay instance.
static TimeOfDay valueOf(java.lang.String time)
          Converts to TimeOfDay instance.
static TimeOfDay valueOf(Time time)
          Converts to TimeOfDay instance.
 
Methods inherited from class 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)
Gets a time of day 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()
Gets the time of day it is now.

Returns:
The time of day it is now

now

public static TimeOfDay now(java.util.Calendar calendar)
Gets the time of day it is 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)
Gets a time of day on a 12 hour clock.

Parameters:
hour - The hour (1-12)
minute - The minute (0-59)
second - The second (0-59)
meridian - AM/PM
Returns:
The time value

time

public static TimeOfDay time(int hour,
                             int minute,
                             TimeOfDay.Meridian meridian)
Gets a time of day on a 12 hour clock.

Parameters:
hour - The hour (1-12)
minute - The minute (0-59)
meridian - AM/PM
Returns:
The time value

valueOf

public static TimeOfDay valueOf(java.util.Calendar calendar,
                                java.lang.String time)
                         throws java.text.ParseException
Converts to TimeOfDay instance.

Parameters:
calendar - The calendar to use when parsing time string
time - A string in h.mma format
Returns:
The time of day on the given calendar
Throws:
java.text.ParseException

valueOf

public static TimeOfDay valueOf(java.util.Calendar calendar,
                                Time time)
Converts to TimeOfDay instance.

Parameters:
calendar - The calendar to use when converting time value
time - The time to convert to a time of day
Returns:
The time of day for this time

valueOf

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

Parameters:
duration - The duration
Returns:
The time of day for the duration since midnight

valueOf

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

Parameters:
time - The time in milliseconds today
Returns:
The time of day

valueOf

public static TimeOfDay valueOf(java.lang.String time)
                         throws java.text.ParseException
Converts to TimeOfDay instance.

Parameters:
time - A string in h.mma format
Returns:
The time of day on the given calendar
Throws:
java.text.ParseException

valueOf

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

Parameters:
time - Time to convert to time of day
Returns:
The time of day in the current timezone

hour

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

Returns:
The hour of the day (0-23)

minute

public int minute()
Gets the minute.

Returns:
The minute (0-59)

next

public Time next()
Gets the next occurrence of this time of day in localtime.

Returns:
The next occurrence of this time of day in localtime

next

public Time next(java.util.Calendar calendar)
Gets the next occurence of this time of day on the given calendar.

Parameters:
calendar - The calendar to use
Returns:
The next occurrence of this time of day on the given calendar

second

public int second()
Gets the second.

Returns:
The second (0-59)

toString

public java.lang.String toString()
Converts this time to a string suitable for use in a filesystem name

Returns:
This time as a formatted string
See Also:
Object.toString()

after

public final boolean after(wicket.util.time.AbstractTimeValue that)
Parameters:
that - The time to compare with
Returns:
True if this time value is after that time value

before

public final boolean before(wicket.util.time.AbstractTimeValue that)
Parameters:
that - The time to compare with
Returns:
True if this time value is before that time value

toTimeString

public final java.lang.String toTimeString()
Converts this time to a time string using the formatter h.mma

Returns:
The date string

toTimeString

public final java.lang.String toTimeString(java.util.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()
Returns:
Number of milliseconds in this abstract time value


Copyright © 2004-2007 Wicket developers. All Rights Reserved.