Class DateUtils

org.elasticsearch.common.time.DateUtils

public class DateUtils extends
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static <,​>
     
    static <>
     
    static long
     
    static long
     
    static long
     
    static
    The maximum nanosecond resolution date we can properly handle.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static
     instant)
    Returns an instant that is with valid nanosecond resolution.
    static
    dateTimeZoneToZoneId​(org.joda.time.DateTimeZone timeZone)
     
    static
    Returns the current UTC date-time with milliseconds precision.
    static
     clock)
     
    static
     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 performance 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
    toInstant​(long nanoSecondsSinceEpoch)
    convert a long value to a java time instant the long value resembles the nanoseconds since the epoch
    static long
     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
     zoneId)
     

    Methods inherited from class java.lang.

    , , , , , , , , , ,
  • Field Details

    • MAX_MILLIS_BEFORE_9999

      public static final long MAX_MILLIS_BEFORE_9999
      See Also:
      Constant Field Values
    • MAX_MILLIS_BEFORE_MINUS_9999

      public static final long MAX_MILLIS_BEFORE_MINUS_9999
      See Also:
      Constant Field Values
    • DEPRECATED_SHORT_TZ_IDS

      public static final <> DEPRECATED_SHORT_TZ_IDS
    • DEPRECATED_LONG_TIMEZONES

      public static final <,​> DEPRECATED_LONG_TIMEZONES
    • MAX_NANOSECOND_INSTANT

      public static final  MAX_NANOSECOND_INSTANT
      The maximum nanosecond resolution date we can properly handle.
    • MAX_NANOSECOND

      public static final long MAX_NANOSECOND
  • Constructor Details

    • DateUtils

      public DateUtils()
  • Method Details

    • zoneIdToDateTimeZone

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

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

      public static  of( zoneId)
    • toLong

      public static long toLong( 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
    • clampToNanosRange

      public static  clampToNanosRange( instant)
      Returns an instant that is with valid nanosecond resolution. If the parameter is before the valid nanosecond range then this returns the minimum valid for nanosecond resultion. If the parameter is after the valid nanosecond range then this returns the maximum valid for nanosecond resolution.

      Useful for checking if all values for the field are within some range, even if the range's endpoints are not valid nanosecond resolution.

    • toInstant

      public static  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 performance 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  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:
      instance for the current date-time with milliseconds precision in UTC
    • nowWithMillisResolution

      public static  nowWithMillisResolution( clock)