Class Timestamp

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

    public class Timestamp
    extends java.sql.Timestamp
    implements Freezable
    Timestamp with UTC option.

    Differs from java.sql.Timestamp when serialized/deserialized in different timezones. By default, if timestamps are serialized and deserialized in different timezones, their representation may differ according to the GMT-offset and/or daylight saving. This is okay for most cases. In some cases, however, a timestamp should not be converted, i.e. regarded as fixed and related to some timezone by convention, for example UTC. This is what the UTC-attribute and the tentackle model's [UTC]-option is provided for.

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

    Author:
    harald
    See Also:
    Serialized Form
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Timestamp clone()
      static Timestamp createFrozen​(long epoch, int nanos)
      Creates a frozen timestamp.
      void freeze()
      Makes this object immutable.
      java.util.Calendar getCalendar()
      Gets the calendar for this date.
      boolean isUTC()
      Gets the UTC flag.
      void setDate​(int date)
      Deprecated.
      void setHours​(int hours)
      Deprecated.
      void setMinutes​(int minutes)
      Deprecated.
      void setMonth​(int month)
      Deprecated.
      void setNanos​(int n)  
      void setSeconds​(int seconds)
      Deprecated.
      void setTime​(long timestamp)
      void setUTC​(boolean utc)
      Sets the UTC flag.
      static void setUTC​(Timestamp timestamp, boolean utc)
      Sets the UTC flag null-safe.
      Method provided to reduce generated code.
      void setYear​(int year)
      Deprecated.
      • Methods inherited from class java.sql.Timestamp

        after, before, compareTo, compareTo, equals, equals, from, getNanos, getTime, hashCode, toInstant, toLocalDateTime, toString, valueOf, valueOf
      • Methods inherited from class java.util.Date

        after, before, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTimezoneOffset, getYear, parse, toGMTString, toLocaleString, UTC
      • Methods inherited from class java.lang.Object

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

      • Timestamp

        public Timestamp​(long time)
        Constructs a Timestamp object using a milliseconds time value. The integral seconds are stored in the underlying date value; the fractional seconds are stored in the nanos field of the Timestamp object.
        Parameters:
        time - milliseconds since January 1, 1970, 00:00:00 GMT. A negative number is the number of milliseconds before January 1, 1970, 00:00:00 GMT.
        See Also:
        Calendar
      • Timestamp

        public Timestamp()
        Creates the current timestamp.
    • Method Detail

      • createFrozen

        public static Timestamp createFrozen​(long epoch,
                                             int nanos)
        Creates a frozen timestamp.
        Parameters:
        epoch - epochal milliseconds since January 1, 1970, 00:00:00 GMT
        nanos - the new fractional seconds component
        Returns:
        the frozen timestamp
      • setUTC

        public static void setUTC​(Timestamp timestamp,
                                  boolean utc)
        Sets the UTC flag null-safe.
        Method provided to reduce generated code.
        Parameters:
        timestamp - the timestamp, may be null
        utc - the UTC flag
      • clone

        public Timestamp clone()

        Cloned timestamps are always not frozen.

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

        public void setUTC​(boolean utc)
        Sets the UTC flag.

        Timestamps with UTC set are serialized and deserialized without timezone.

        Parameters:
        utc - the UTC flag
      • isUTC

        public boolean isUTC()
        Gets the UTC flag.
        Returns:
        true if timestamp is UTC
      • 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 timestamp)

        Overridden to clear the lazy calendar and to check for frozen.

        Overrides:
        setTime in class java.sql.Timestamp
      • setNanos

        public void setNanos​(int n)
        Overrides:
        setNanos in class java.sql.Timestamp
      • setYear

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

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

        @Deprecated
        public void setDate​(int date)
        Deprecated.
        Overrides:
        setDate in class java.util.Date
      • 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