java.lang.Object
org.elasticsearch.xpack.core.common.time.TimeUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field) Check the giventimeValueis a multiple of thebaseUnitstatic voidcheckNonNegativeMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field) Checks that the giventimeValueis a non-negative multiple value of thebaseUnit.static voidcheckPositive(org.elasticsearch.core.TimeValue timeValue, org.elasticsearch.xcontent.ParseField field) Checks that the giventimeValueis positive.static voidcheckPositiveMultiple(org.elasticsearch.core.TimeValue timeValue, TimeUnit baseUnit, org.elasticsearch.xcontent.ParseField field) Checks that the giventimeValueis a positive multiple value of thebaseUnit.static longdateStringToEpoch(String date) Deprecated.static DateparseTimeField(org.elasticsearch.xcontent.XContentParser parser, String fieldName) Deprecated.static InstantparseTimeFieldToInstant(org.elasticsearch.xcontent.XContentParser parser, String fieldName) static longparseToEpochMs(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".
-
Method Details
-
parseTimeField
@Deprecated public static Date parseTimeField(org.elasticsearch.xcontent.XContentParser parser, String fieldName) throws IOException Deprecated.Please useparseTimeFieldToInstant(XContentParser, String)instead.- Throws:
IOException
-
parseTimeFieldToInstant
public static Instant parseTimeFieldToInstant(org.elasticsearch.xcontent.XContentParser parser, String fieldName) throws IOException - Throws:
IOException
-
parseToEpochMs
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.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 usingDateFieldMapper.DEFAULT_DATE_TIME_FORMATTERIf 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 giventimeValueis a non-negative multiple value of thebaseUnit.- 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 giventimeValueis a positive multiple value of thebaseUnit.- 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 giventimeValueis 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 giventimeValueis a multiple of thebaseUnit
-
parseTimeFieldToInstant(XContentParser, String)instead.