Class DateTimeFormatterTimestampConverter

java.lang.Object
org.elasticsearch.xpack.core.ml.utils.time.DateTimeFormatterTimestampConverter
All Implemented Interfaces:
TimestampConverter

public class DateTimeFormatterTimestampConverter extends Object implements 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 Details

    • ofPattern

      public static TimestampConverter ofPattern(String pattern, ZoneId defaultTimezone)
      Creates a formatter according to the given pattern
      Parameters:
      pattern - the pattern to be used by the formatter, not null. See DateTimeFormatter for the syntax of the accepted patterns
      defaultTimezone - 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

      public long toEpochSeconds(String timestamp)
      Description copied from interface: TimestampConverter
      Converts the a textual timestamp into an epoch in seconds
      Specified by:
      toEpochSeconds in interface TimestampConverter
      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

      public long toEpochMillis(String timestamp)
      Description copied from interface: TimestampConverter
      Converts the a textual timestamp into an epoch in milliseconds
      Specified by:
      toEpochMillis in interface TimestampConverter
      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