Class 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) where long is milliseconds since midnight
    • valueOf(String) where the String is in 'h.mma' format
    • valueOf(Calendar, String) where the String is in 'h.mma' format
    • valueOf(Duration) where Duration is time since midnight
    • valueOf(Time) where Time is some point in time today
    • valueOf(Calendar, Time) where Time is some point in time today
    • militaryTime(int hour, int minute, int second) for 24-hour time
    • time(int hour, int minute, Meridian) where Meridian is AM or PM
    • time(int hour, int minute, int second, Meridian) where Meridian is AM or PM
    • now() to construct the current time of day
    • now(Calendar) to construct the current time of day using a given Calendar

    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

      Nested Classes 
      Modifier and Type Class Description
      static class  TimeOfDay.Meridian
      Typesafe AM/PM enumeration.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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​(java.util.Calendar calendar)
      Retrieves the next occurrence of this TimeOfDay on the given Calendar.
      static TimeOfDay now()
      Retrieves the TimeOfDay representing 'now'.
      static TimeOfDay now​(java.util.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.
      java.lang.String toString()
      Converts this Time to a String suitable for use in a file system 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​(long time)
      Converts a long value to a TimeOfDay instance.
      static TimeOfDay valueOf​(java.lang.String time)
      Converts a String value to a TimeOfDay instance.
      static TimeOfDay valueOf​(java.util.Calendar calendar, java.lang.String time)
      Converts a time String and Calendar to a TimeOfDay instance.
      static TimeOfDay valueOf​(java.util.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​(Time time)
      Converts a String value to a TimeOfDay instance.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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​(java.util.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​(java.util.Calendar calendar,
                                        java.lang.String time)
                                 throws java.text.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:
        java.text.ParseException
      • valueOf

        public static TimeOfDay valueOf​(java.util.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​(java.lang.String time)
                                 throws java.text.ParseException
        Converts a String value to a TimeOfDay instance.
        Parameters:
        time - a String in 'h.mma' format
        Returns:
        the TimeOfDay
        Throws:
        java.text.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​(java.util.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 java.lang.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 java.lang.String toTimeString()
        Converts this Time to a time String using the formatter 'h.mma'.
        Returns:
        the Time 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()
        Retrieves the number of milliseconds in this Time value.
        Returns:
        the number of milliseconds in this Time value