java.lang.Object
org.elasticsearch.xpack.core.common.time.TimeUtils

public final class TimeUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field)
    Check the given timeValue is a multiple of the baseUnit
    static void
    checkNonNegativeMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field)
    Checks that the given timeValue is a non-negative multiple value of the baseUnit.
    static void
    checkPositive(org.elasticsearch.core.TimeValue timeValue, org.elasticsearch.xcontent.ParseField field)
    Checks that the given timeValue is positive.
    static void
    checkPositiveMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field)
    Checks that the given timeValue is a positive multiple value of the baseUnit.
    static long
    Deprecated.
    static Date
    parseTimeField(org.elasticsearch.xcontent.XContentParser parser, String fieldName)
    Deprecated.
    static Instant
    parseTimeFieldToInstant(org.elasticsearch.xcontent.XContentParser parser, String fieldName)
     
    static long
    Safely parses a string epoch representation to a Long Commonly this function is used for parsing Date fields from doc values requested with the format "epoch_millis".

    Methods inherited from class java.lang.Object

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

    • parseTimeField

      @Deprecated public static Date parseTimeField(org.elasticsearch.xcontent.XContentParser parser, String fieldName) throws IOException
      Deprecated.
      Throws:
      IOException
    • parseTimeFieldToInstant

      public static Instant parseTimeFieldToInstant(org.elasticsearch.xcontent.XContentParser parser, String fieldName) throws IOException
      Throws:
      IOException
    • parseToEpochMs

      public static long parseToEpochMs(String epoch)
      Safely parses a string epoch representation to a Long Commonly this function is used for parsing Date fields from doc values requested with the format "epoch_millis". Since nanosecond support was added epoch_millis timestamps may have a fractional component. We discard this, taking just whole milliseconds. Arguably it would be better to retain the precision here and let the downstream component decide whether it wants the accuracy, but that makes it hard to pass around the value as a number. The double type doesn't have enough digits of accuracy, and obviously long cannot store the fraction. BigDecimal would work, but that isn't supported by the JSON parser if the number gets round-tripped through JSON. So String is really the only format that could be used, but the consumers of time are expecting a number.
      Parameters:
      epoch - The epoch value as a string. This may contain a fractional component.
      Returns:
      The epoch value.
    • dateStringToEpoch

      @Deprecated public static long dateStringToEpoch(String date)
      Deprecated.
      First tries to parse the date first as a Long and convert that to an epoch time. If the long number has more than 10 digits it is considered a time in milliseconds else if 10 or less digits it is in seconds. If that fails it tries to parse the string using DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER If the date string cannot be parsed -1 is returned.
      Returns:
      The epoch time in milliseconds or -1 if the date cannot be parsed.
    • checkNonNegativeMultiple

      public static void checkNonNegativeMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field)
      Checks that the given timeValue is a non-negative multiple value of the baseUnit.
      • 400ms is valid for base unit of seconds
      • 450ms is invalid for base unit of seconds but valid for base unit of milliseconds
    • checkPositiveMultiple

      public static void checkPositiveMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field)
      Checks that the given timeValue is a positive multiple value of the baseUnit.
      • 400ms is valid for base unit of seconds
      • 450ms is invalid for base unit of seconds but valid for base unit of milliseconds
    • checkPositive

      public static void checkPositive(org.elasticsearch.core.TimeValue timeValue, org.elasticsearch.xcontent.ParseField field)
      Checks that the given timeValue is positive.
      • 1s is valid
      • -1s is invalid
    • checkMultiple

      public static void checkMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field)
      Check the given timeValue is a multiple of the baseUnit