Class DateUtils

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

public class DateUtils extends Object
  • Field Details

    • MAX_MILLIS_BEFORE_9999

      public static final long MAX_MILLIS_BEFORE_9999
      See Also:
    • MAX_MILLIS_BEFORE_MINUS_9999

      public static final long MAX_MILLIS_BEFORE_MINUS_9999
      See Also:
    • DEPRECATED_SHORT_TZ_IDS

      public static final Set<String> DEPRECATED_SHORT_TZ_IDS
    • DEPRECATED_LONG_TIMEZONES

      public static final Map<String,String> DEPRECATED_LONG_TIMEZONES
    • MAX_NANOSECOND_INSTANT

      public static final Instant 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 zoneId)
    • dateTimeZoneToZoneId

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

      public static ZoneId of(String zoneId)
    • toLong

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

      public static Instant clampToNanosRange(Instant instant)
      Returns an instant that is with valid nanosecond resolution. If the parameter is before the valid nanosecond range then this returns the minimum Instant valid for nanosecond resultion. If the parameter is after the valid nanosecond range then this returns the maximum Instant 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 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 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 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 ZonedDateTime nowWithMillisResolution(Clock clock)