Module org.elasticsearch.xcore
Class DateTimeFormatterTimestampConverter
java.lang.Object
org.elasticsearch.xpack.core.ml.utils.time.DateTimeFormatterTimestampConverter
- All Implemented Interfaces:
TimestampConverter
This class implements TimestampConverter using the DateTimeFormatter
of the Java 8 time API for parsing timestamps and other classes of that API for converting
timestamps to epoch times.
Objects of this class are immutable and thread-safe
-
Method Summary
Modifier and TypeMethodDescriptionstatic TimestampConverterCreates a formatter according to the given patternlongtoEpochMillis(String timestamp) Converts the a textual timestamp into an epoch in millisecondslongtoEpochSeconds(String timestamp) Converts the a textual timestamp into an epoch in seconds
-
Method Details
-
ofPattern
Creates a formatter according to the given pattern- Parameters:
pattern- the pattern to be used by the formatter, not null. SeeDateTimeFormatterfor the syntax of the accepted patternsdefaultTimezone- the timezone to be used for dates without timezone information.- Returns:
- a
TimestampConverter - Throws:
IllegalArgumentException- if the pattern is invalid or cannot produce a full timestamp (e.g. contains a date but not a time)
-
toEpochSeconds
Description copied from interface:TimestampConverterConverts the a textual timestamp into an epoch in seconds- Specified by:
toEpochSecondsin interfaceTimestampConverter- Parameters:
timestamp- the timestamp to convert, not null. The timestamp is expected to be formatted according to the pattern of the formatter. In addition, the pattern is assumed to contain both date and time information.- Returns:
- the epoch in seconds for the given timestamp
-
toEpochMillis
Description copied from interface:TimestampConverterConverts the a textual timestamp into an epoch in milliseconds- Specified by:
toEpochMillisin interfaceTimestampConverter- Parameters:
timestamp- the timestamp to convert, not null. The timestamp is expected to be formatted according to the pattern of the formatter. In addition, the pattern is assumed to contain both date and time information.- Returns:
- the epoch in milliseconds for the given timestamp
-