Package org.apache.wicket.util.time
Class TimeOfDay
- java.lang.Object
-
- org.apache.wicket.util.value.LongValue
-
- org.apache.wicket.util.time.TimeOfDay
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.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:
valueOf(long)wherelongis milliseconds since midnightvalueOf(String)where theStringis in 'h.mma' formatvalueOf(Calendar, String)where theStringis in 'h.mma' formatvalueOf(Duration)whereDurationis time since midnightvalueOf(Time)whereTimeis some point in time todayvalueOf(Calendar, Time)whereTimeis some point in time todaymilitaryTime(int hour, int minute, int second)for 24-hour timetime(int hour, int minute, Meridian)whereMeridianis AM or PMtime(int hour, int minute, int second, Meridian)whereMeridianis AM or PMnow()to construct the current time of daynow(Calendar)to construct the current time of day using a givenCalendar
If an attempt is made to construct an illegal time of day value (one that is greater than 24 hours worth of milliseconds), an
IllegalArgumentExceptionwill be thrown.Military hours, minutes and seconds of the time of day can be retrieved by calling the
hour,minute, andsecondmethods.The next occurrence of a given
TimeOfDaycan be retrieved by callingnext()ornext(Calendar).- Since:
- 1.2.6
- Author:
- Jonathan Locke
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTimeOfDay.MeridianTypesafe AM/PM enumeration.
-
Field Summary
Fields Modifier and Type Field Description static TimeOfDay.MeridianAMConstant for AM time.static TimeOfDayMIDNIGHTConstant for midnight.static TimeOfDayNOONConstant for noon.static TimeOfDay.MeridianPMConstant for PM time.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanafter(org.apache.wicket.util.time.AbstractTimeValue that)Returnstrueif thisTimevalue is after the givenTimeargument's value.booleanbefore(org.apache.wicket.util.time.AbstractTimeValue that)Returnstrueif thisTimevalue is before the givenTimeargument's value.longgetMilliseconds()Retrieves the number of milliseconds in thisTimevalue.inthour()Retrieves the hour of the day.static TimeOfDaymilitaryTime(int hour, int minute, int second)Retrieves aTimeOfDayvalue on a 24-hour clock.intminute()Retrieves the minute.Timenext()Retrieves the next occurrence of thisTimeOfDayin local time.Timenext(java.util.Calendar calendar)Retrieves the next occurrence of thisTimeOfDayon the givenCalendar.static TimeOfDaynow()Retrieves theTimeOfDayrepresenting 'now'.static TimeOfDaynow(java.util.Calendar calendar)Retrieves theTimeOfDayrepresenting 'now' on the givenCalendar.intsecond()Retrieves the second.static TimeOfDaytime(int hour, int minute, int second, TimeOfDay.Meridian meridian)Retrieves aTimeOfDayon a 12-hour clock.static TimeOfDaytime(int hour, int minute, TimeOfDay.Meridian meridian)Retrieves aTimeOfDayon a 12-hour clock.java.lang.StringtoString()Converts thisTimeto aStringsuitable for use in a file system name.java.lang.StringtoTimeString()Converts thisTimeto a timeStringusing the formatter 'h.mma'.java.lang.StringtoTimeString(java.util.Calendar calendar)Converts thisTimeto aDate Stringusing theDateformatter 'h.mma'.static TimeOfDayvalueOf(long time)Converts alongvalue to aTimeOfDayinstance.static TimeOfDayvalueOf(java.lang.String time)Converts aStringvalue to aTimeOfDayinstance.static TimeOfDayvalueOf(java.util.Calendar calendar, java.lang.String time)Converts a timeStringandCalendarto aTimeOfDayinstance.static TimeOfDayvalueOf(java.util.Calendar calendar, Time time)Converts aTimeinstance andCalendarto aTimeOfDayinstance.static TimeOfDayvalueOf(Duration duration)Converts aDurationinstance to aTimeOfDayinstance.static TimeOfDayvalueOf(Time time)Converts aStringvalue to aTimeOfDayinstance.-
Methods inherited from class org.apache.wicket.util.value.LongValue
compareTo, equals, greaterThan, greaterThan, greaterThanOrEqual, greaterThanOrEqual, hashCode, lessThan, lessThan, lessThanOrEqual, lessThanOrEqual, max, maxNullSafe, min
-
-
-
-
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 aTimeOfDayvalue 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 theTimeOfDayrepresenting 'now'.- Returns:
- the time of day it is now
-
now
public static TimeOfDay now(java.util.Calendar calendar)
Retrieves theTimeOfDayrepresenting 'now' on the givenCalendar.- Parameters:
calendar- theCalendarto 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 aTimeOfDayon 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
TimeOfDayvalue
-
time
public static TimeOfDay time(int hour, int minute, TimeOfDay.Meridian meridian)
Retrieves aTimeOfDayon a 12-hour clock.- Parameters:
hour- the hour (1-12)minute- the minute (0-59)meridian- AM of PM- Returns:
- the
TimeOfDayvalue
-
valueOf
public static TimeOfDay valueOf(java.util.Calendar calendar, java.lang.String time) throws java.text.ParseException
Converts a timeStringandCalendarto aTimeOfDayinstance.- Parameters:
calendar- theCalendarto use when parsing timeStringtime- aStringin 'h.mma' format- Returns:
- the
TimeOfDayon the givenCalendar - Throws:
java.text.ParseException
-
valueOf
public static TimeOfDay valueOf(java.util.Calendar calendar, Time time)
Converts aTimeinstance andCalendarto aTimeOfDayinstance.- Parameters:
calendar- theCalendarto usetime- aTimeinstance- Returns:
- the
TimeOfDayon the givenCalendar
-
valueOf
public static TimeOfDay valueOf(Duration duration)
Converts aDurationinstance to aTimeOfDayinstance.- Parameters:
duration- theDurationto use- Returns:
- the
TimeOfDayof the givenDuration
-
valueOf
public static TimeOfDay valueOf(long time)
Converts alongvalue to aTimeOfDayinstance.- Parameters:
time- the time in milliseconds today- Returns:
- the
TimeOfDay
-
valueOf
public static TimeOfDay valueOf(java.lang.String time) throws java.text.ParseException
Converts aStringvalue to aTimeOfDayinstance.- Parameters:
time- aStringin 'h.mma' format- Returns:
- the
TimeOfDay - Throws:
java.text.ParseException
-
valueOf
public static TimeOfDay valueOf(Time time)
Converts aStringvalue to aTimeOfDayinstance.- Parameters:
time- aTimeto convert toTimeOfDay- Returns:
- the
TimeOfDayin 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 thisTimeOfDayin local time.- Returns:
- the next occurrence of this
TimeOfDayin local time
-
next
public Time next(java.util.Calendar calendar)
Retrieves the next occurrence of thisTimeOfDayon the givenCalendar.- Parameters:
calendar- theCalendarto use- Returns:
- the next occurrence of this
TimeOfDayon the givenCalendar
-
second
public int second()
Retrieves the second.- Returns:
- the second (0-59)
-
toString
public java.lang.String toString()
Converts thisTimeto aStringsuitable for use in a file system name.- Returns:
- this
Timeas a formattedString - See Also:
Object.toString()
-
after
public final boolean after(org.apache.wicket.util.time.AbstractTimeValue that)
Returnstrueif thisTimevalue is after the givenTimeargument's value.- Parameters:
that- theAbstractTimeValueto compare with- Returns:
trueif thisTimevalue is afterthatTimevalue
-
before
public final boolean before(org.apache.wicket.util.time.AbstractTimeValue that)
Returnstrueif thisTimevalue is before the givenTimeargument's value.- Parameters:
that- theAbstractTimeValueto compare with- Returns:
trueif thisTimevalue is beforethatTimevalue
-
toTimeString
public final java.lang.String toTimeString()
Converts thisTimeto a timeStringusing the formatter 'h.mma'.- Returns:
- the
TimeString
-
toTimeString
public final java.lang.String toTimeString(java.util.Calendar calendar)
Converts thisTimeto aDate Stringusing theDateformatter 'h.mma'.- Parameters:
calendar- theCalendarto use in the conversion- Returns:
- the
DateString
-
getMilliseconds
public final long getMilliseconds()
Retrieves the number of milliseconds in thisTimevalue.- Returns:
- the number of milliseconds in this
Timevalue
-
-