o

zio.common

DateTimeUtils

object DateTimeUtils

Helper functions for converting between internal and external date and time representations. Dates are exposed externally as java.sql.Date and are represented internally as the number of dates since the Unix epoch (1970-01-01). Timestamps are exposed externally as java.sql.Timestamp and are stored internally as longs, which are capable of storing timestamps with microsecond precision.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DateTimeUtils
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. type SQLDate = Int
  2. type SQLTimestamp = Long

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final val JULIAN_DAY_OF_EPOCH: Int(2440588)
  5. final val MICROS_PER_DAY: Long
  6. final val MICROS_PER_MILLIS: Long(1000L)
  7. final val MICROS_PER_SECOND: Long
  8. final val MILLIS_PER_DAY: Long
  9. final val MILLIS_PER_SECOND: Long(1000L)
  10. final val MonthOf31Days: Set[Int]
  11. final val NANOS_PER_MICROS: Long(1000L)
  12. final val NANOS_PER_SECOND: Long
  13. final val SECONDS_PER_DAY: Long
  14. val TIMEZONE_OPTION: String
  15. final val TimeZoneGMT: TimeZone
  16. final val TimeZoneUTC: TimeZone
  17. final val YearZero: Int(-17999)
  18. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  19. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  20. def convertTz(ts: SQLTimestamp, fromZone: TimeZone, toZone: TimeZone): SQLTimestamp

    Convert the timestamp ts from one timezone to another.

    Convert the timestamp ts from one timezone to another.

    TODO: Because of DST, the conversion between UTC and human time is not exactly one-to-one mapping, the conversion here may return wrong result, we should make the timestamp timezone-aware.

  21. def dateAddMonths(days: SQLDate, months: Int): SQLDate

    Add date and year-month interval.

    Add date and year-month interval. Returns a date value, expressed in days since 1.1.1970.

  22. def dateToString(days: SQLDate, timeZone: TimeZone): String
  23. def dateToString(days: SQLDate): String
  24. final val daysIn400Years: Int
  25. def daysToMillis(days: SQLDate, timeZone: TimeZone): Long
  26. def daysToMillis(days: SQLDate): Long
  27. def defaultTimeZone(): TimeZone
  28. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  29. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  30. def fromJavaDate(date: Date): SQLDate

    Returns the number of days since epoch from java.sql.Date.

  31. def fromJavaTimestamp(t: Timestamp): SQLTimestamp

    Returns the number of micros since epoch from java.sql.Timestamp.

  32. def fromJulianDay(day: Int, nanoseconds: Long): SQLTimestamp

    Returns the number of microseconds since epoch from Julian day and nanoseconds in a day

  33. def fromMillis(millis: Long): SQLTimestamp
  34. def fromUTCTime(time: SQLTimestamp, timeZone: String): SQLTimestamp

    Returns a timestamp of given timezone from utc timestamp, with the same string representation in their timezone.

  35. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  36. def getDayInYear(date: SQLDate): Int

    Returns the 'day in year' value for the given date.

    Returns the 'day in year' value for the given date. The date is expressed in days since 1.1.1970.

  37. def getDayOfMonth(date: SQLDate): Int

    Returns the 'day of month' value for the given date.

    Returns the 'day of month' value for the given date. The date is expressed in days since 1.1.1970.

  38. def getDayOfWeekFromString(string: String): Int
  39. def getHours(microsec: SQLTimestamp, timeZone: TimeZone): Int

    Returns the hour value of a given timestamp value.

    Returns the hour value of a given timestamp value. The timestamp is expressed in microseconds.

  40. def getHours(microsec: SQLTimestamp): Int

    Returns the hour value of a given timestamp value.

    Returns the hour value of a given timestamp value. The timestamp is expressed in microseconds.

  41. def getLastDayOfMonth(date: SQLDate): SQLDate

    Returns last day of the month for the given date.

    Returns last day of the month for the given date. The date is expressed in days since 1.1.1970.

  42. def getMinutes(microsec: SQLTimestamp, timeZone: TimeZone): Int

    Returns the minute value of a given timestamp value.

    Returns the minute value of a given timestamp value. The timestamp is expressed in microseconds.

  43. def getMinutes(microsec: SQLTimestamp): Int

    Returns the minute value of a given timestamp value.

    Returns the minute value of a given timestamp value. The timestamp is expressed in microseconds.

  44. def getMonth(date: SQLDate): Int

    Returns the month value for the given date.

    Returns the month value for the given date. The date is expressed in days since 1.1.1970. January is month 1.

  45. def getNextDateForDayOfWeek(startDate: SQLDate, dayOfWeek: Int): SQLDate

    Returns the first date which is later than startDate and is of the given dayOfWeek.

    Returns the first date which is later than startDate and is of the given dayOfWeek. dayOfWeek is an integer ranges in [0, 6], and 0 is Thu, 1 is Fri, etc,.

  46. def getQuarter(date: SQLDate): Int

    Returns the quarter for the given date.

    Returns the quarter for the given date. The date is expressed in days since 1.1.1970.

  47. def getSeconds(microsec: SQLTimestamp, timeZone: TimeZone): Int

    Returns the second value of a given timestamp value.

    Returns the second value of a given timestamp value. The timestamp is expressed in microseconds.

  48. def getSeconds(microsec: SQLTimestamp): Int

    Returns the second value of a given timestamp value.

    Returns the second value of a given timestamp value. The timestamp is expressed in microseconds.

  49. def getThreadLocalDateFormat(timeZone: TimeZone): DateFormat
  50. def getThreadLocalTimestampFormat(timeZone: TimeZone): DateFormat
  51. def getTimeZone(timeZoneId: String): TimeZone
  52. def getYear(date: SQLDate): Int

    Returns the year value for the given date.

    Returns the year value for the given date. The date is expressed in days since 1.1.1970.

  53. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  54. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  55. def millisToDays(millisUtc: Long, timeZone: TimeZone): SQLDate
  56. def millisToDays(millisUtc: Long): SQLDate
  57. def monthsBetween(time1: SQLTimestamp, time2: SQLTimestamp, roundOff: Boolean, timeZone: TimeZone): Double

    Returns number of months between time1 and time2.

    Returns number of months between time1 and time2. time1 and time2 are expressed in microseconds since 1.1.1970. If time1 is later than time2, the result is positive.

    If time1 and time2 are on the same day of month, or both are the last day of month, returns, time of day will be ignored.

    Otherwise, the difference is calculated based on 31 days per month. The result is rounded to 8 decimal places if roundOff is set to true.

  58. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  59. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  60. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  61. def parseTruncLevel(format: String): Int

    Returns the truncate level, could be TRUNC_YEAR, TRUNC_MONTH, TRUNC_TO_DAY, TRUNC_TO_HOUR, TRUNC_TO_MINUTE, TRUNC_TO_SECOND, TRUNC_TO_WEEK, TRUNC_TO_QUARTER or TRUNC_INVALID, TRUNC_INVALID means unsupported truncate level.

  62. def splitDate(date: SQLDate): (Int, Int, Int, Int)

    Split date (expressed in days since 1.1.1970) into four fields: year, month (Jan is Month 1), dayInMonth, daysToMonthEnd (0 if it's last day of month).

  63. def stringToDate(s: String): Option[SQLDate]

    Trim and parse a given UTF8 date string to a corresponding Int value.

    Trim and parse a given UTF8 date string to a corresponding Int value. The return type is Option in order to distinguish between 0 and null. The following formats are allowed:

    yyyy yyyy-[m]m yyyy-[m]m-[d]d yyyy-[m]m-[d]d yyyy-[m]m-[d]d * yyyy-[m]m-[d]dT*

  64. def stringToLocalDateTime(s: String): Option[LocalDateTime]
  65. def stringToOffsetDateTime(s: String): Option[OffsetDateTime]
  66. def stringToTimestamp(s: String, timeZone: TimeZone): Option[SQLTimestamp]
  67. def stringToTimestamp(s: String): Option[SQLTimestamp]

    Trim and parse a given UTF8 date string to the corresponding a corresponding Long value.

    Trim and parse a given UTF8 date string to the corresponding a corresponding Long value. The return type is Option in order to distinguish between 0L and null. The following formats are allowed:

    yyyy yyyy-[m]m yyyy-[m]m-[d]d yyyy-[m]m-[d]d yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us] yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m yyyy-[m]m-[d]d [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us] yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m yyyy-[m]m-[d]dT[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us] [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m [h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us] T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]Z T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]-[h]h:[m]m T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m

  68. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  69. def timestampAddInterval(start: SQLTimestamp, months: Int, microseconds: Long, timeZone: TimeZone): SQLTimestamp

    Add timestamp and full interval.

    Add timestamp and full interval. Returns a timestamp value, expressed in microseconds since 1.1.1970 00:00:00.

  70. def timestampAddInterval(start: SQLTimestamp, months: Int, microseconds: Long): SQLTimestamp

    Add timestamp and full interval.

    Add timestamp and full interval. Returns a timestamp value, expressed in microseconds since 1.1.1970 00:00:00.

  71. def timestampToString(us: SQLTimestamp, timeZone: TimeZone): String
  72. def timestampToString(us: SQLTimestamp): String
  73. final val to2001: Int(-11323)
  74. def toJavaDate(daysSinceEpoch: SQLDate): Date

    Returns a java.sql.Date from number of days since epoch.

  75. def toJavaTimestamp(us: SQLTimestamp): Timestamp

    Returns a java.sql.Timestamp from number of micros since epoch.

  76. def toJulianDay(us: SQLTimestamp): (Int, Long)

    Returns Julian day and nanoseconds in a day from the number of microseconds

    Returns Julian day and nanoseconds in a day from the number of microseconds

    Note: support timestamp since 4717 BC (without negative nanoseconds, compatible with Hive).

  77. def toMillis(us: SQLTimestamp): Long
  78. def toString(): String
    Definition Classes
    AnyRef → Any
  79. def toUTCTime(time: SQLTimestamp, timeZone: String): SQLTimestamp

    Returns a utc timestamp from a given timestamp from a given timezone, with the same string representation in their timezone.

  80. final val toYearZero: Int
  81. def truncDate(d: SQLDate, level: Int): SQLDate

    Returns the trunc date from original date and trunc level.

    Returns the trunc date from original date and trunc level. Trunc level should be generated using parseTruncLevel(), should only be 1 or 2.

  82. def truncTimestamp(d: SQLTimestamp, level: Int): SQLTimestamp
  83. def truncTimestamp(t: SQLTimestamp, level: Int, timeZone: TimeZone): SQLTimestamp

    Returns the trunc date time from original date time and trunc level.

    Returns the trunc date time from original date time and trunc level. Trunc level should be generated using parseTruncLevel(), should be between 1 and 8

  84. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  85. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  86. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from AnyRef

Inherited from Any

Ungrouped