wicket.util.time
Class Time

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

public final class Time
extends LongValue

An immutable Time class that represents a specific point in time. The underlying representation is a long value which holds a number of milliseconds since January 1, 1970, 0:00 GMT. To represent a time duration, such as "6 seconds", use the Duration class. To represent a time period with a start and end time, use the TimeFrame class. To represent a time of day, use the TimeOfDay class.

Author:
Jonathan Locke
See Also:
Serialized Form

Field Summary
static Time START_OF_UNIX_TIME
          The beginning of UNIX time: January 1, 1970, 0:00 GMT.
 
Fields inherited from class wicket.util.value.LongValue
value
 
Method Summary
 Time add(Duration duration)
          Adds the given duration to this time object, moving the time into the future.
 boolean after(wicket.util.time.AbstractTimeValue that)
           
 boolean before(wicket.util.time.AbstractTimeValue that)
           
 Duration elapsedSince()
           
 Duration fromNow()
          Gets the duration from now to this time value.
 int get(java.util.Calendar calendar, int field)
          Gets the value of a field from the given calendar.
 int get(int field)
          Gets the value of a field.
 int getDayOfMonth()
          Gets the day of month field of the current calendar.
 int getDayOfMonth(java.util.Calendar calendar)
          Gets the day of month field of the given calendar.
 int getHour()
          Gets the hour field of the current calendar.
 int getHour(java.util.Calendar calendar)
          Gets the hour field of the given calendar.
 long getMilliseconds()
           
 int getMinute()
          Gets the minute field of the current calendar.
 int getMinute(java.util.Calendar calendar)
          Gets the minute field of the given calendar.
 int getMonth()
          Gets the month field of the current calendar.
 int getMonth(java.util.Calendar calendar)
          Gets the month field of the given calendar.
 int getSecond()
          Gets the second field of the current calendar.
 int getSecond(java.util.Calendar calendar)
          Gets the second field of the given calendar.
 int getYear()
          Gets the year field of the current calendar.
 int getYear(java.util.Calendar calendar)
          Gets the year field of the given calendar.
static Time milliseconds(long time)
          Gets a Time instance based on the given miliseconds.
static Time now()
          Gets a Time instance based on the current time.
static Time parseDate(java.util.Calendar calendar, java.lang.String string)
          Gets time by parsing 'yyyy.MM.dd' format.
static Time parseDate(java.lang.String string)
          Gets time by parsing 'yyyy.MM.dd' format using a localtime calendar.
 Time subtract(Duration duration)
          Adds the given duration to this time object, moving the time into the future.
 Duration subtract(Time that)
          Subtract time from this and returns the difference as a duration object.
 java.util.Date toDate()
          Gets a Date object for this time object.
 java.lang.String toDateString()
          Converts this time to a date string using the date formatter 'yyyy.MM.dd'.
 java.lang.String toDateString(java.util.Calendar calendar)
          Converts this time to a date string using the formatter 'yyyy.MM.dd'.
 java.lang.String toString()
          Converts this time to a string suitable for use in a filesystem name.
 java.lang.String toString(java.util.Calendar calendar, java.lang.String format)
          Converts this time to a string using the given calendar and format.
 java.lang.String toString(java.lang.String format)
          Converts this time to a string using the given format.
 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 Time valueOf(java.util.Calendar calendar, java.lang.String string)
          Gets time by parsing yyyy.MM.dd-h.mma format.
static Time valueOf(java.util.Calendar calendar, TimeOfDay timeOfDay)
          Gets a Time instance based on the given calendar and TimeOfDay objects.
static Time valueOf(java.util.Date date)
          Gets a Time instance based on the given date object.
static Time valueOf(long time)
          Gets a Time instance based on the given miliseconds.
static Time valueOf(java.lang.String string)
          Gets time by parsing yyyy.MM.dd-h.mma format.
static Time valueOf(java.lang.String string, java.lang.String pattern)
          Gets time by parsing 'pattern' format.
static Time valueOf(TimeOfDay timeOfDay)
          Gets a Time instance based on the given TimeOfDayobject.
 
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

START_OF_UNIX_TIME

public static final Time START_OF_UNIX_TIME
The beginning of UNIX time: January 1, 1970, 0:00 GMT.

Method Detail

milliseconds

public static Time milliseconds(long time)
Gets a Time instance based on the given miliseconds.

Parameters:
time - The time in milliseconds since START_OF_UNIX_TIME
Returns:
The given time

now

public static Time now()
Gets a Time instance based on the current time.

Returns:
The current time

parseDate

public static Time parseDate(java.util.Calendar calendar,
                             java.lang.String string)
                      throws java.text.ParseException
Gets time by parsing 'yyyy.MM.dd' format.

Parameters:
calendar - The calendar to use when parsing date string
string - The string
Returns:
The time
Throws:
java.text.ParseException

parseDate

public static Time parseDate(java.lang.String string)
                      throws java.text.ParseException
Gets time by parsing 'yyyy.MM.dd' format using a localtime calendar.

Parameters:
string - The string
Returns:
The time
Throws:
java.text.ParseException

valueOf

public static Time valueOf(java.util.Calendar calendar,
                           java.lang.String string)
                    throws java.text.ParseException
Gets time by parsing yyyy.MM.dd-h.mma format.

Parameters:
calendar - The calendar to use when parsing the string
string - The string
Returns:
An immutable UNIX time value
Throws:
java.text.ParseException

valueOf

public static Time valueOf(java.util.Calendar calendar,
                           TimeOfDay timeOfDay)
Gets a Time instance based on the given calendar and TimeOfDay objects.

Parameters:
calendar - The calendar to use
timeOfDay - The time of day
Returns:
A time value for the time of day today

valueOf

public static Time valueOf(java.util.Date date)
Gets a Time instance based on the given date object.

Parameters:
date - A java.util.Date object
Returns:
A corresponding immutable Time object

valueOf

public static Time valueOf(long time)
Gets a Time instance based on the given miliseconds.

Parameters:
time - The time in milliseconds since START_OF_UNIX_TIME
Returns:
A corresponding immutable Time object

valueOf

public static Time valueOf(java.lang.String string)
                    throws java.text.ParseException
Gets time by parsing yyyy.MM.dd-h.mma format.

Parameters:
string - The string
Returns:
The time
Throws:
java.text.ParseException

valueOf

public static Time valueOf(java.lang.String string,
                           java.lang.String pattern)
                    throws java.text.ParseException
Gets time by parsing 'pattern' format.

Parameters:
string - input
pattern - pattern to use
Returns:
Time instance that resulted from parsing the given string
Throws:
java.text.ParseException

valueOf

public static Time valueOf(TimeOfDay timeOfDay)
Gets a Time instance based on the given TimeOfDayobject.

Parameters:
timeOfDay - The time of day in localtime
Returns:
A time value for the time of day today

add

public Time add(Duration duration)
Adds the given duration to this time object, moving the time into the future.

Parameters:
duration - The duration to add
Returns:
This time + duration

elapsedSince

public Duration elapsedSince()
Returns:
Amount of time that has elapsed since this time
Throws:
java.lang.IllegalStateException - Thrown if this time is in the future

fromNow

public Duration fromNow()
Gets the duration from now to this time value. If this time value is in the past, then the Duration returned will be negative. Otherwise, it will be the number of milliseconds from now to this Time.

Returns:
The duration from now to this time value

get

public int get(java.util.Calendar calendar,
               int field)
Gets the value of a field from the given calendar.

Parameters:
calendar - The calendar to use
field - The calendar field to get
Returns:
The field's value for this point in time on the given calendar

get

public int get(int field)
Gets the value of a field.

Parameters:
field - The calendar field to get
Returns:
The field's value (in localtime)

getDayOfMonth

public int getDayOfMonth()
Gets the day of month field of the current calendar.

Returns:
the field value

getDayOfMonth

public int getDayOfMonth(java.util.Calendar calendar)
Gets the day of month field of the given calendar.

Parameters:
calendar - the calendar to get the field value from
Returns:
the field value

getHour

public int getHour()
Gets the hour field of the current calendar.

Returns:
the field value

getHour

public int getHour(java.util.Calendar calendar)
Gets the hour field of the given calendar.

Parameters:
calendar - the calendar to get the field value from
Returns:
the field value

getMinute

public int getMinute()
Gets the minute field of the current calendar.

Returns:
the field value

getMinute

public int getMinute(java.util.Calendar calendar)
Gets the minute field of the given calendar.

Parameters:
calendar - the calendar to get the field value from
Returns:
the field value

getMonth

public int getMonth()
Gets the month field of the current calendar.

Returns:
the field value

getMonth

public int getMonth(java.util.Calendar calendar)
Gets the month field of the given calendar.

Parameters:
calendar - the calendar to get the field value from
Returns:
the field value

getSecond

public int getSecond()
Gets the second field of the current calendar.

Returns:
the field value

getSecond

public int getSecond(java.util.Calendar calendar)
Gets the second field of the given calendar.

Parameters:
calendar - the calendar to get the field value from
Returns:
the field value

getYear

public int getYear()
Gets the year field of the current calendar.

Returns:
the field value

getYear

public int getYear(java.util.Calendar calendar)
Gets the year field of the given calendar.

Parameters:
calendar - the calendar to get the field value from
Returns:
the field value

subtract

public Time subtract(Duration duration)
Adds the given duration to this time object, moving the time into the future.

Parameters:
duration - The duration to add
Returns:
This time - duration

subtract

public Duration subtract(Time that)
Subtract time from this and returns the difference as a duration object.

Parameters:
that - The time to subtract
Returns:
The duration between this and that time

toDate

public java.util.Date toDate()
Gets a Date object for this time object. A new Date object is always returned rather than attempting to cache a date since Date is mutable.

Returns:
This immutable time object as a mutable java.util.Date object

toDateString

public java.lang.String toDateString()
Converts this time to a date string using the date formatter 'yyyy.MM.dd'.

Returns:
The date string

toDateString

public java.lang.String toDateString(java.util.Calendar calendar)
Converts this time to a date string using the formatter 'yyyy.MM.dd'.

Parameters:
calendar - The calendar to use in the conversion
Returns:
The date string

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

toString

public java.lang.String toString(java.util.Calendar calendar,
                                 java.lang.String format)
Converts this time to a string using the given calendar and format.

Parameters:
calendar - the calendar to use
format - the format to use
Returns:
This time as a formatted string

toString

public java.lang.String toString(java.lang.String format)
Converts this time to a string using the given format.

Parameters:
format - the format to use
Returns:
This time as a formatted string

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.