Class DBDateTime

java.lang.Object
com.illumon.iris.db.tables.utils.DBDateTime
All Implemented Interfaces:
DatetimeFilterData.MillisProvider, Externalizable, Serializable, Comparable<DBDateTime>

public final class DBDateTime extends Object implements Comparable<DBDateTime>, Externalizable, DatetimeFilterData.MillisProvider
An object representing a timpoint in Deephaven.

A DBDateTime represents a zone-less, precise timepoint without respect to timezones. The instant is stored as a signed 64-bit long, representing nanoseconds since the epoch (January 1, 1970, 00:00:00 GMT). This provides a range from 1677-09-21T00:12:43.146-775807 UTC to 2262-04-11T23:47:16.854775807 UTC. The minimum long value is reserved for QueryConstants.NULL_LONG and therefore is not permitted as a valid DBDateTime.

See Also:
  • Constructor Details

    • DBDateTime

      public DBDateTime()
      Create a new DBDatetime initialized to the epoch.
    • DBDateTime

      public DBDateTime(long nanos)
      Create a new DBDateTime initialized to the provided nanoseconds since the epoch.
      Parameters:
      nanos - the number of nanoseconds since the epoch
  • Method Details

    • now

      public static DBDateTime now()
      Create a new DBDatetime initialized to the current time.

      The precision of DBDateTime is nanoseconds, but the resolution of the now method is currently microseconds.

      Returns:
      a new DBDateTime initialized to the current time.
    • nowNanos

      public static long nowNanos()
      Return the current time since the epoch in nanoseconds.

      The precision of DBDateTime is nanoseconds, but the resolution of the nowNanos method is currently microseconds.

      Returns:
      the nanoseconds used for new DBDateTime construction.
    • getNanos

      public long getNanos()
      Get this time represented as nanoseconds since the epoch
      Returns:
      the number of nanoseconds since the epoch
    • getMicros

      public long getMicros()
      Get this time represented as microseconds since the epoch
      Returns:
      the number of microseconds since the epoch
    • getMillis

      public long getMillis()
      Get this time represented as milliseconds since the epoch
      Specified by:
      getMillis in interface DatetimeFilterData.MillisProvider
      Returns:
      the number of milliseconds since the epoch
    • getNanosPartial

      public long getNanosPartial()
      Get nanoseconds-of-milliseconds; this number will always be between 0 and 999,999
      Returns:
      the number of nanoseconds after the nearest millisecond.
    • getJodaDateTime

      @Deprecated public org.joda.time.DateTime getJodaDateTime()
      Deprecated.
      use toZonedDateTime() instead
      Convert this DBDateTime to a Joda DateTime. This DBDateTime will be truncated to milliseconds.
      Returns:
      a Joda DateTime representing this DBDateTime
    • getJodaDateTime

      @Deprecated public org.joda.time.DateTime getJodaDateTime(@NotNull DBTimeZone timeZone)
      Deprecated.
      Convert this DBDateTime to a Joda DateTime. This DBDateTime will be truncated to milliseconds.
      Parameters:
      timeZone - the timezone for the created Joda DateTime
      Returns:
      a Joda DateTime representing this DBDateTime
    • toZonedDateTime

      @NotNull public ZonedDateTime toZonedDateTime()
      Get a ZonedDateTime version of this DBDateTime at the system default time zone.
      Returns:
      a ZonedDateTime
    • toZonedDateTime

      @NotNull public ZonedDateTime toZonedDateTime(@NotNull String zone)
      Get a ZonedDateTime version of this DBDateTime at the specified time zone.
      Returns:
      a ZonedDateTime
    • toZonedDateTime

      @NotNull public ZonedDateTime toZonedDateTime(@NotNull DBTimeZone zone)
      Get a ZonedDateTime version of this DBDateTime at the specified time zone.
      Returns:
      a ZonedDateTime
    • toZonedDateTime

      @NotNull public ZonedDateTime toZonedDateTime(@NotNull ZoneId zone)
      Get a ZonedDateTime version of this DBDateTime at the specified time zone.
      Returns:
      a ZonedDateTime
    • toLocalDate

      @NotNull public LocalDate toLocalDate()
      Get a LocalDate representing the date of this DBDateTime at the system default time zone.
      Returns:
      the LocalDate
    • toLocalDate

      @NotNull public LocalDate toLocalDate(@NotNull String zone)
      Get a LocalDate representing the date of this DBDateTime at the specified time zone.
      Returns:
      the LocalDate
    • toLocalDate

      @NotNull public LocalDate toLocalDate(@NotNull DBTimeZone zone)
      Get a LocalDate representing the date of this DBDateTime at the specified time zone.
      Returns:
      the LocalDate
    • toLocalDate

      @NotNull public LocalDate toLocalDate(@NotNull ZoneId zone)
      Get a LocalDate representing the date of this DBDateTime at the specified time zone.
      Returns:
      the LocalDate
    • toLocalTime

      @NotNull public LocalTime toLocalTime()
      Get a LocalTime representing the time of day of this DBDateTime at the system default time zone.
      Returns:
      the LocalTime
    • toLocalTime

      @NotNull public LocalTime toLocalTime(@NotNull String zone)
      Get a LocalTime representing the time of day of this DBDateTime at the specified time zone.
      Returns:
      the LocalTime
    • toLocalTime

      @NotNull public LocalTime toLocalTime(@NotNull DBTimeZone zone)
      Get a LocalTime representing the time of day of this DBDateTime at the specified time zone.
      Returns:
      the LocalTime
    • toLocalTime

      @NotNull public LocalTime toLocalTime(@NotNull ZoneId zone)
      Get a LocalTime representing the time of day of this DBDateTime at the specified time zone.
      Returns:
      the LocalTime
    • getDate

      @Deprecated @NotNull public Date getDate()
      Deprecated.
      use toZonedDateTime() instead.
      Convert this DBDateTime to a Java Date. This DBDateTime will be truncated to milliseconds.
      Returns:
      a Java Date representing this DBDateTime
    • getInstant

      @NotNull public Instant getInstant()
      Convert this DBDateTime to a Java Instant.
      Returns:
      a Java Instant representing this DBDateTime
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(DBDateTime dateTime)
      Specified by:
      compareTo in interface Comparable<DBDateTime>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      @NotNull public String toString(@NotNull DBTimeZone timeZone)
      Convert this DBDateTime into a String using the provided DBTimeZone.

      The date will be formatted as yyyy-MM-DDThh:mm:ss.SSSSSSSSS TZ, for example 2020-05-27T13:37:57.780853000 NY or 2020-05-27T17:37:42.763641000 UTC.

      Parameters:
      timeZone - the timezone for formatting the string
      Returns:
      a String representation of this DBDateTime
    • toDateString

      @NotNull public String toDateString()
      Get the date represented by this DBDateTime in the default DBTimeZone.
      Returns:
      The date (yyyy-MM-dd) represented by this DBDateTime in the default DBTimeZone.
    • toDateString

      @NotNull public String toDateString(@NotNull DBTimeZone timeZone)
      Get the date represented by this DBDateTime in the given DBTimeZone.
      Parameters:
      timeZone - a DBTimeZone
      Returns:
      The date (yyyy-MM-dd) represented by this DBDateTime in the given timeZone.
    • toDateString

      @NotNull public String toDateString(@NotNull org.joda.time.DateTimeZone timeZone)
      Get the date represented by this DBDateTime in the given Joda DateTimeZone in ISO date format yyyy-mm.
      Parameters:
      timeZone - A joda DateTimeZone
      Returns:
      The date (yyyy-MM-dd) represented by this DBDateTime in the given timeZone
    • toDateString

      @NotNull public String toDateString(@NotNull String zoneId)
      Get the date represented by this DBDateTime in the time zone specified by zoneId in ISO date format.
      Parameters:
      zoneId - A java time zone ID string
      Returns:
      The date (yyyy-MM-dd) represented by this DBDateTime in time zone represented by the given zoneId
    • toDateString

      @NotNull public String toDateString(@NotNull ZoneId timeZone)
      Get the date represented by this DBDateTime in the given java ZoneId in ISO date format.
      Parameters:
      timeZone - A java time zone ID.
      Returns:
      The date (yyyy-MM-dd) represented by this DBDateTime in the given timeZone
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException