Package de.elo.utils

Class TimeStamp

java.lang.Object
de.elo.utils.TimeStamp

public class TimeStamp
extends java.lang.Object
This class handles the conversion between different date and time formats. The string representation of TimeStamp is an ISO like format with dots between year, month etc. It is always in UTC.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String DEFAULT_RANGE_DELIM
    This delimiter is used by default to separate date-time values.
  • Constructor Summary

    Constructors 
    Constructor Description
    TimeStamp()
    Default constructor.
    TimeStamp​(int nELODate)
    Constructs object from an ELO date.
    TimeStamp​(long nTimeMillis)
    Constructor to initialize with a special UTC system time.
    TimeStamp​(TimeStamp ts)
    Constructs object from another TimeStamp.
    TimeStamp​(java.lang.String tsStr)
    Constructs object from a time stamp string (ISO date with dots).
    TimeStamp​(java.lang.String sISODate, java.util.Locale locale)
    Constructs object from an ISO date.
    TimeStamp​(java.lang.String sISODate, java.util.TimeZone tz)
    Constructs object from an ISO date.
    TimeStamp​(java.sql.Timestamp sqlTimestamp)
    Constructs aTimeStamp-object from a java.sql.Timestamp.
    TimeStamp​(java.time.LocalDateTime ldt)
    Constructs a TimeStamp from a LocalDateTime object.
    TimeStamp​(java.time.LocalDateTime ldt, java.util.TimeZone tz)
    Constructs a TimeStamp from a LocalDateTime and TimeZone object.
    TimeStamp​(java.util.Date date)
    Constructs an object from a Date object
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String convertISOfromLocaleToLocale​(java.lang.String isoDate, java.util.Locale fromLocale, java.util.Locale toLocale)
    Convert ISO date from one locale into another.
    static java.lang.String convertISOfromLocaleToUTC​(java.lang.String isoDate)
    Convert ISO date measured in the default locale to the corresponding ISO date in UTC.
    static java.lang.String convertISOfromLocaleToUTC​(java.lang.String isoDate, java.util.Locale locale)
    Convert ISO date measured in the specified locale to the corresponding ISO date in UTC.
    static java.lang.String convertISOfromTztoTz​(java.lang.String isoDate, java.util.TimeZone fromTz, java.util.TimeZone toTz)
    Convert ISO date from one timezone into another.
    static java.lang.String convertISOfromTzToUTC​(java.lang.String isoDate, java.util.TimeZone fromTz)
    Convert ISO date from timezone into UTC.
    static java.lang.String convertISOfromUTCtoLocale​(java.lang.String isoDate)
    Convert ISO date measured in UTC to the corresponding ISO date measured in the default locale.
    static java.lang.String convertISOfromUTCtoLocale​(java.lang.String isoDate, java.util.Locale locale)
    Convert ISO date measured in UTC to the corresponding ISO date measured in the specified locale.
    static java.lang.String convertISOfromUTCtoTz​(java.lang.String isoDate, java.util.TimeZone toTz)
    Convert ISO date from UTC timezone into another.
    static int convertToEloDate​(java.lang.String isoDate, java.util.TimeZone tz)
    Converts an ISO date string of given timezone into an ELO date in the default timezone of the VM.
    boolean equals​(java.lang.Object obj)  
    int hashCode()  
    static TimeStamp now()
    Creates a new TimeStamp object initialized with the current time.
    static TimeStamp oldest()
    Creates a new TimeStamp object initialized with the oldest valid time.
    java.util.Date toDate()
    Converts to Date
    int toELODate()
    Converts to ELO date format.
    java.lang.String toISODate()
    Converts to ISO date.
    java.lang.String toISODate​(java.util.Locale locale)
    Converts to ISO date measured in the specified time zone.
    java.lang.String toISODate​(java.util.TimeZone tz)
    Converts to ISO date measured in the specified time zone.
    java.lang.String toISODateUTC()
    Converts to ISO date.
    java.time.LocalDateTime toLocalDateTime()
    Converts to LocalDateTime with UTC as TimeZone
    java.time.LocalDateTime toLocalDateTime​(java.util.TimeZone tz)
    Converts to LocalDateTime with a given TimeZone
    java.sql.Timestamp toSqlTimestamp()  
    java.lang.String toString()
    Returns the string representation of this.
    java.lang.String toString​(java.util.TimeZone tz)
    Convert to string representation in given timezone.
    long toTimeMillis()
    Returns the system time millis (UTC).

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • TimeStamp

      public TimeStamp()
      Default constructor. Initializes the object with the current date.
    • TimeStamp

      public TimeStamp​(long nTimeMillis)
      Constructor to initialize with a special UTC system time.
      Parameters:
      nTimeMillis - UTC milliseconds
    • TimeStamp

      public TimeStamp​(int nELODate)
      Constructs object from an ELO date. ELO date values are always measured in the local time zone of the server.
      Parameters:
      nELODate - proprietary ELO date value
    • TimeStamp

      public TimeStamp​(java.lang.String tsStr)
      Constructs object from a time stamp string (ISO date with dots). Time stamp strings are always measured in the UTC time zone. It's also possible to supply an ISO date (without dots) in tsStr. This ISO date is assumed to be in UTC time zone.
      Parameters:
      tsStr - Time stamp string
    • TimeStamp

      public TimeStamp​(java.lang.String sISODate, java.util.TimeZone tz)
      Constructs object from an ISO date.
      Parameters:
      sISODate - ISO date
      tz - Time zone of sISODate. If null the current default time zone is used.
    • TimeStamp

      public TimeStamp​(java.lang.String sISODate, java.util.Locale locale)
      Constructs object from an ISO date.
      Parameters:
      sISODate - ISO date
      locale - sISODate is assumed to be in the default time zone of this locale. If null the current default time zone is used.
    • TimeStamp

      public TimeStamp​(TimeStamp ts)
      Constructs object from another TimeStamp.
      Parameters:
      ts - Other TimeStamp
    • TimeStamp

      public TimeStamp​(java.sql.Timestamp sqlTimestamp)
      Constructs aTimeStamp-object from a java.sql.Timestamp.
      Parameters:
      sqlTimestamp -
    • TimeStamp

      public TimeStamp​(java.util.Date date)
      Constructs an object from a Date object
      Parameters:
      date - Date object (is cloned)
    • TimeStamp

      public TimeStamp​(java.time.LocalDateTime ldt)
      Constructs a TimeStamp from a LocalDateTime object.
    • TimeStamp

      public TimeStamp​(java.time.LocalDateTime ldt, java.util.TimeZone tz)
      Constructs a TimeStamp from a LocalDateTime and TimeZone object.
      Parameters:
      ldt -
      tz -
  • Method Details

    • now

      public static TimeStamp now()
      Creates a new TimeStamp object initialized with the current time.
      Returns:
      New TimeStamp object
    • oldest

      public static TimeStamp oldest()
      Creates a new TimeStamp object initialized with the oldest valid time.
      Returns:
      New TimeStamp object
    • toString

      public java.lang.String toString()
      Returns the string representation of this.
      Overrides:
      toString in class java.lang.Object
      Returns:
      Time string (with dots) - always measured in UTC
      See Also:
      toString(TimeZone)
    • toString

      public java.lang.String toString​(java.util.TimeZone tz)
      Convert to string representation in given timezone.
      Parameters:
      tz - TimeZone
      Returns:
      String representation, e.g. "2010.09.08.13.14.15"
    • toDate

      public final java.util.Date toDate()
      Converts to Date
      Returns:
      Date object
    • toELODate

      public final int toELODate()
      Converts to ELO date format.
      Returns:
      ELO date. ELO date values are always measured in the local time zone of the server.
    • toISODate

      public final java.lang.String toISODate()
      Converts to ISO date.
      Returns:
      ISO date measured in the default time zone.
      See Also:
      toISODate(TimeZone)
    • toISODateUTC

      public final java.lang.String toISODateUTC()
      Converts to ISO date.
      Returns:
      ISO date measured in the UTC time zone.
      See Also:
      toISODate(TimeZone)
    • toISODate

      public final java.lang.String toISODate​(java.util.TimeZone tz)
      Converts to ISO date measured in the specified time zone.
      Parameters:
      tz - Time zone. If null the default time zone is used
      Returns:
      ISO date
    • toISODate

      public final java.lang.String toISODate​(java.util.Locale locale)
      Converts to ISO date measured in the specified time zone.
      Parameters:
      locale - Locale of returned ISO date. If null the default time zone is used.
      Returns:
      ISO date
    • toLocalDateTime

      public final java.time.LocalDateTime toLocalDateTime()
      Converts to LocalDateTime with UTC as TimeZone
      Returns:
      LocalDateTime
    • toLocalDateTime

      public final java.time.LocalDateTime toLocalDateTime​(java.util.TimeZone tz)
      Converts to LocalDateTime with a given TimeZone
      Parameters:
      tz - - TimeZone to use.
      Returns:
      LocalDateTime
    • toSqlTimestamp

      public final java.sql.Timestamp toSqlTimestamp()
    • toTimeMillis

      public final long toTimeMillis()
      Returns the system time millis (UTC).
      Returns:
      System time millis
    • convertISOfromLocaleToUTC

      public static final java.lang.String convertISOfromLocaleToUTC​(java.lang.String isoDate, java.util.Locale locale)
      Convert ISO date measured in the specified locale to the corresponding ISO date in UTC.
      Parameters:
      isoDate - ISO date
      locale - Locale of isoDate
      Returns:
      UTC date
    • convertISOfromLocaleToUTC

      public static final java.lang.String convertISOfromLocaleToUTC​(java.lang.String isoDate)
      Convert ISO date measured in the default locale to the corresponding ISO date in UTC.
      Parameters:
      isoDate - ISO date
      Returns:
      UTC date
    • convertISOfromUTCtoLocale

      public static final java.lang.String convertISOfromUTCtoLocale​(java.lang.String isoDate, java.util.Locale locale)
      Convert ISO date measured in UTC to the corresponding ISO date measured in the specified locale.
      Parameters:
      isoDate - ISO date in UTC
      locale - Locale of the returned date
      Returns:
      ISO date measured in the specified locale
    • convertISOfromUTCtoLocale

      public static final java.lang.String convertISOfromUTCtoLocale​(java.lang.String isoDate)
      Convert ISO date measured in UTC to the corresponding ISO date measured in the default locale.
      Parameters:
      isoDate - ISO date in UTC
      Returns:
      ISO date measured in the specified locale
    • convertISOfromLocaleToLocale

      public static final java.lang.String convertISOfromLocaleToLocale​(java.lang.String isoDate, java.util.Locale fromLocale, java.util.Locale toLocale)
      Convert ISO date from one locale into another.
      Parameters:
      isoDate - ISO date in UTC
      fromLocale - Locale of isoDate
      toLocale - Locale of the returned date
      Returns:
      ISO date
    • convertISOfromTztoTz

      public static final java.lang.String convertISOfromTztoTz​(java.lang.String isoDate, java.util.TimeZone fromTz, java.util.TimeZone toTz)
      Convert ISO date from one timezone into another.
      Parameters:
      isoDate - ISO date in UTC
      fromTz - Timezone of isoDate
      toTz - Timezone of the returned date
      Returns:
      ISO date
    • convertISOfromUTCtoTz

      public static final java.lang.String convertISOfromUTCtoTz​(java.lang.String isoDate, java.util.TimeZone toTz)
      Convert ISO date from UTC timezone into another.
      Parameters:
      isoDate - ISO date in UTC
      toTz - Timezone of the returned date
      Returns:
      ISO date
    • convertISOfromTzToUTC

      public static final java.lang.String convertISOfromTzToUTC​(java.lang.String isoDate, java.util.TimeZone fromTz)
      Convert ISO date from timezone into UTC.
      Parameters:
      isoDate - ISO date in timezone fromTz
      fromTz - Timezone of ISO date
      Returns:
      UTC
    • convertToEloDate

      public static final int convertToEloDate​(java.lang.String isoDate, java.util.TimeZone tz)
      Converts an ISO date string of given timezone into an ELO date in the default timezone of the VM.
      Parameters:
      isoDate - String
      tz - TimeZone
      Returns:
      int
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object