Class DateUtils

java.lang.Object
org.elasticsearch.common.time.DateUtils

public class DateUtils
extends java.lang.Object
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.util.Map<java.lang.String,​java.lang.String> DEPRECATED_LONG_TIMEZONES  
    static java.util.Set<java.lang.String> DEPRECATED_SHORT_TZ_IDS  
  • Constructor Summary

    Constructors 
    Constructor Description
    DateUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.time.ZoneId dateTimeZoneToZoneId​(org.joda.time.DateTimeZone timeZone)  
    static java.time.ZonedDateTime nowWithMillisResolution()
    Returns the current UTC date-time with milliseconds precision.
    static java.time.ZonedDateTime nowWithMillisResolution​(java.time.Clock clock)  
    static java.time.ZoneId of​(java.lang.String zoneId)  
    static long roundFloor​(long utcMillis, long unitMillis)
    Rounds the given utc milliseconds sicne the epoch down to the next unit millis Note: This does not check for correctness of the result, as this only works with units smaller or equal than a day In order to ensure the performane of this methods, there are no guards or checks in it
    static long roundMonthOfYear​(long utcMillis)
    Round down to the beginning of the month of the year of the specified time
    static long roundQuarterOfYear​(long utcMillis)
    Round down to the beginning of the quarter of the year of the specified time
    static long roundWeekOfWeekYear​(long utcMillis)
    Round down to the beginning of the week based on week year of the specified time
    static long roundYear​(long utcMillis)
    Round down to the beginning of the year of the specified time
    static java.time.Instant toInstant​(long nanoSecondsSinceEpoch)
    convert a long value to a java time instant the long value resembles the nanoseconds since the epoch
    static long toLong​(java.time.Instant instant)
    convert a java time instant to a long value which is stored in lucene the long value resembles the nanoseconds since the epoch
    static long toMilliSeconds​(long nanoSecondsSinceEpoch)
    Convert a nanosecond timestamp in milliseconds
    static long toNanoSeconds​(long milliSecondsSinceEpoch)
    Convert a nanosecond timestamp in milliseconds
    static org.joda.time.DateTimeZone zoneIdToDateTimeZone​(java.time.ZoneId zoneId)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • zoneIdToDateTimeZone

      public static org.joda.time.DateTimeZone zoneIdToDateTimeZone​(java.time.ZoneId zoneId)
    • dateTimeZoneToZoneId

      public static java.time.ZoneId dateTimeZoneToZoneId​(org.joda.time.DateTimeZone timeZone)
    • of

      public static java.time.ZoneId of​(java.lang.String zoneId)
    • toLong

      public static long toLong​(java.time.Instant instant)
      convert a java time instant to a long value which is stored in lucene the long value resembles the nanoseconds since the epoch
      Parameters:
      instant - the instant to convert
      Returns:
      the nano seconds and seconds as a single long
    • toInstant

      public static java.time.Instant toInstant​(long nanoSecondsSinceEpoch)
      convert a long value to a java time instant the long value resembles the nanoseconds since the epoch
      Parameters:
      nanoSecondsSinceEpoch - the nanoseconds since the epoch
      Returns:
      the instant resembling the specified date
    • toNanoSeconds

      public static long toNanoSeconds​(long milliSecondsSinceEpoch)
      Convert a nanosecond timestamp in milliseconds
      Parameters:
      milliSecondsSinceEpoch - the millisecond since the epoch
      Returns:
      the nanoseconds since the epoch
    • toMilliSeconds

      public static long toMilliSeconds​(long nanoSecondsSinceEpoch)
      Convert a nanosecond timestamp in milliseconds
      Parameters:
      nanoSecondsSinceEpoch - the nanoseconds since the epoch
      Returns:
      the milliseconds since the epoch
    • roundFloor

      public static long roundFloor​(long utcMillis, long unitMillis)
      Rounds the given utc milliseconds sicne the epoch down to the next unit millis Note: This does not check for correctness of the result, as this only works with units smaller or equal than a day In order to ensure the performane of this methods, there are no guards or checks in it
      Parameters:
      utcMillis - the milliseconds since the epoch
      unitMillis - the unit to round to
      Returns:
      the rounded milliseconds since the epoch
    • roundQuarterOfYear

      public static long roundQuarterOfYear​(long utcMillis)
      Round down to the beginning of the quarter of the year of the specified time
      Parameters:
      utcMillis - the milliseconds since the epoch
      Returns:
      The milliseconds since the epoch rounded down to the quarter of the year
    • roundMonthOfYear

      public static long roundMonthOfYear​(long utcMillis)
      Round down to the beginning of the month of the year of the specified time
      Parameters:
      utcMillis - the milliseconds since the epoch
      Returns:
      The milliseconds since the epoch rounded down to the month of the year
    • roundYear

      public static long roundYear​(long utcMillis)
      Round down to the beginning of the year of the specified time
      Parameters:
      utcMillis - the milliseconds since the epoch
      Returns:
      The milliseconds since the epoch rounded down to the beginning of the year
    • roundWeekOfWeekYear

      public static long roundWeekOfWeekYear​(long utcMillis)
      Round down to the beginning of the week based on week year of the specified time
      Parameters:
      utcMillis - the milliseconds since the epoch
      Returns:
      The milliseconds since the epoch rounded down to the beginning of the week based on week year
    • nowWithMillisResolution

      public static java.time.ZonedDateTime nowWithMillisResolution()
      Returns the current UTC date-time with milliseconds precision. In Java 9+ (as opposed to Java 8) the Clock implementation uses system's best clock implementation (which could mean that the precision of the clock can be milliseconds, microseconds or nanoseconds), whereas in Java 8 System.currentTimeMillis() is always used. To account for these differences, this method defines a new Clock which will offer a value for ZonedDateTime.now() set to always have milliseconds precision.
      Returns:
      ZonedDateTime instance for the current date-time with milliseconds precision in UTC
    • nowWithMillisResolution

      public static java.time.ZonedDateTime nowWithMillisResolution​(java.time.Clock clock)