Class Time

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Date>, Freezable

    public class Time
    extends java.sql.Time
    implements Freezable
    Time with database semantics.

    Differs from java.sql.Time when serialized/deserialized in different timezones. Databases don't provide a date and no timezone for a time, i.e. when sent over wire to different locations a time should always remain the same for all timezones. In java.sql.Time, however, the epochal time is serialized which may lead to a different time when deserialized in another timezone. In Time the effective date is serialized as HHMMSSmmm to provide the same semantics as databases do.

    Furthermore, tentackle times can be frozen, i.e. made immutable.

    Author:
    harald
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Time()
      Creates the current time.
      Time​(long time)
      Constructs a Time object using a milliseconds time value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Time clone()
      static Time createFrozen​(long epoch)
      Creates a frozen time.
      void freeze()
      Makes this object immutable.
      java.util.Calendar getCalendar()
      Gets the calendar for this date.
      void setDate​(int date)
      Deprecated.
      void setHours​(int hours)
      Deprecated.
      void setMinutes​(int minutes)
      Deprecated.
      void setMonth​(int month)
      Deprecated.
      void setSeconds​(int seconds)
      Deprecated.
      void setTime​(long time)
      void setYear​(int year)
      Deprecated.
      • Methods inherited from class java.sql.Time

        getDate, getDay, getMonth, getYear, toInstant, toLocalTime, toString, valueOf, valueOf
      • Methods inherited from class java.util.Date

        after, before, compareTo, equals, from, getHours, getMinutes, getSeconds, getTime, getTimezoneOffset, hashCode, parse, toGMTString, toLocaleString, UTC
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Time

        public Time​(long time)
        Constructs a Time object using a milliseconds time value.
        Parameters:
        time - milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT
      • Time

        public Time()
        Creates the current time.
    • Method Detail

      • createFrozen

        public static Time createFrozen​(long epoch)
        Creates a frozen time.
        Parameters:
        epoch - epochal milliseconds since January 1, 1970, 00:00:00 GMT
        Returns:
        the frozen time
      • clone

        public Time clone()

        Cloned times are always not frozen.

        Overrides:
        clone in class java.util.Date
      • getCalendar

        public java.util.Calendar getCalendar()
        Gets the calendar for this date.
        Returns:
        the calendar
      • freeze

        public void freeze()
        Description copied from interface: Freezable
        Makes this object immutable.
        Specified by:
        freeze in interface Freezable
      • setTime

        public void setTime​(long time)

        Overridden to clear the lazy calendar and check for frozen.

        Overrides:
        setTime in class java.sql.Time
      • setYear

        @Deprecated
        public void setYear​(int year)
        Deprecated.
        Overrides:
        setYear in class java.sql.Time
      • setMonth

        @Deprecated
        public void setMonth​(int month)
        Deprecated.
        Overrides:
        setMonth in class java.sql.Time
      • setDate

        @Deprecated
        public void setDate​(int date)
        Deprecated.
        Overrides:
        setDate in class java.sql.Time
      • setHours

        @Deprecated
        public void setHours​(int hours)
        Deprecated.
        Overrides:
        setHours in class java.util.Date
      • setMinutes

        @Deprecated
        public void setMinutes​(int minutes)
        Deprecated.
        Overrides:
        setMinutes in class java.util.Date
      • setSeconds

        @Deprecated
        public void setSeconds​(int seconds)
        Deprecated.
        Overrides:
        setSeconds in class java.util.Date