unified date parser tests in a single test class, added more tests for date processor
This commit is contained in:
parent
b45815da36
commit
7798c6cd49
|
@ -28,6 +28,7 @@ dependencies {
|
|||
// we don't use Maxmind's http service:
|
||||
exclude group: 'com.google.http-client', module: 'google-http-client'
|
||||
}
|
||||
compile 'joda-time:joda-time:2.8.2'
|
||||
testCompile 'org.elasticsearch:geolite2-databases:20151029'
|
||||
testCompile 'org.elasticsearch:securemock:1.1'
|
||||
}
|
||||
|
|
|
@ -21,9 +21,15 @@ package org.elasticsearch.ingest.processor.date;
|
|||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Parser for dates provided as strings. Parses into a joda {@link DateTime} object.
|
||||
* We use our own joda wrapper as we support some formats that are not supported directly by joda.
|
||||
*
|
||||
*/
|
||||
public interface DateParser {
|
||||
|
||||
public long parseMillis(String date);
|
||||
|
||||
public DateTime parseDateTime(String date);
|
||||
/**
|
||||
* Parser the date provided as a string argument into a joda {@link DateTime} object
|
||||
*/
|
||||
DateTime parseDateTime(String date);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class DateParserFactory {
|
||||
|
||||
public static final String ISO8601 = "ISO8601";
|
||||
public static final String UNIX = "UNIX";
|
||||
public static final String UNIX_MS = "UNIX_MS";
|
||||
public static final String TAI64N = "TAI64N";
|
||||
|
||||
public static DateParser createDateParser(String format, DateTimeZone timezone, Locale locale) {
|
||||
switch(format) {
|
||||
case ISO8601:
|
||||
// TODO(talevy): fallback solution for almost ISO8601
|
||||
return new ISO8601DateParser(timezone);
|
||||
case UNIX:
|
||||
return new UnixDateParser(timezone);
|
||||
case UNIX_MS:
|
||||
return new UnixMsDateParser(timezone);
|
||||
case TAI64N:
|
||||
return new TAI64NDateParser(timezone);
|
||||
default:
|
||||
return new JodaPatternDateParser(format, timezone, locale);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,80 +21,75 @@ package org.elasticsearch.ingest.processor.date;
|
|||
|
||||
import org.elasticsearch.ingest.Data;
|
||||
import org.elasticsearch.ingest.processor.Processor;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class DateProcessor implements Processor {
|
||||
|
||||
public static final String TYPE = "date";
|
||||
public static final String DEFAULT_TARGET_FIELD = "@timestamp";
|
||||
static final String DEFAULT_TARGET_FIELD = "@timestamp";
|
||||
|
||||
private final DateTimeZone timezone;
|
||||
private final Locale locale;
|
||||
private final String matchField;
|
||||
private final String targetField;
|
||||
private final List<String> matchFormats;
|
||||
private final List<DateParser> parserList;
|
||||
private final List<DateParser> dateParsers;
|
||||
|
||||
public DateProcessor(String timezone, String locale, String matchField, List<String> matchFormats, String targetField) {
|
||||
this.timezone = (timezone == null) ? DateTimeZone.UTC : DateTimeZone.forID(timezone);
|
||||
this.locale = Locale.forLanguageTag(locale);
|
||||
DateProcessor(DateTimeZone timezone, Locale locale, String matchField, List<String> matchFormats, String targetField) {
|
||||
this.timezone = timezone;
|
||||
this.locale = locale;
|
||||
this.matchField = matchField;
|
||||
this.matchFormats = matchFormats;
|
||||
this.parserList = matchFormats.stream().map(elt -> getParser(elt)).collect(Collectors.toList());
|
||||
this.targetField = (targetField == null) ? DEFAULT_TARGET_FIELD : targetField;
|
||||
this.targetField = targetField;
|
||||
this.dateParsers = new ArrayList<>();
|
||||
for (String matchFormat : matchFormats) {
|
||||
dateParsers.add(DateParserFactory.createDateParser(matchFormat, timezone, locale));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Data data) {
|
||||
String value = (String) data.getProperty(matchField);
|
||||
// TODO(talevy): handle multiple patterns
|
||||
String value = data.getProperty(matchField);
|
||||
// TODO(talevy): handle custom timestamp fields
|
||||
String dateAsISO8601 = parserList.get(0).parseDateTime(value).toString();
|
||||
data.addField(targetField, dateAsISO8601);
|
||||
}
|
||||
|
||||
private DateParser getParser(String format) {
|
||||
if ("ISO8601".equals(format)) {
|
||||
// TODO(talevy): fallback solution for almost ISO8601
|
||||
if (timezone == null) {
|
||||
return new ISO8601DateParser();
|
||||
} else {
|
||||
return new ISO8601DateParser(timezone);
|
||||
}
|
||||
} else if ("UNIX".equals(format)) {
|
||||
return new UnixDateParser(timezone);
|
||||
} else if ("UNIX_MS".equals(format)) {
|
||||
return new UnixMsDateParser(timezone);
|
||||
} else if ("TAI64N".equals(format)) {
|
||||
return new TAI64NDateParser(timezone);
|
||||
} else {
|
||||
if (timezone != null && locale != null) {
|
||||
return new JodaPatternDateParser(format, timezone, locale);
|
||||
} else if (timezone != null) {
|
||||
return new JodaPatternDateParser(format, timezone);
|
||||
} else if (locale != null) {
|
||||
return new JodaPatternDateParser(format, locale);
|
||||
} else {
|
||||
return new JodaPatternDateParser(format);
|
||||
DateTime dateTime = null;
|
||||
Exception lastException = null;
|
||||
for (DateParser dateParser : dateParsers) {
|
||||
try {
|
||||
dateTime = dateParser.parseDateTime(value);
|
||||
} catch(Exception e) {
|
||||
//TODO is there a better way other than catching exception?
|
||||
//try the next parser
|
||||
lastException = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (dateTime == null) {
|
||||
throw new IllegalArgumentException("unable to parse date [" + value + "]", lastException);
|
||||
}
|
||||
|
||||
String dateAsISO8601 = dateTime.toString();
|
||||
data.addField(targetField, dateAsISO8601);
|
||||
}
|
||||
|
||||
public static class Factory implements Processor.Factory {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Processor create(Map<String, Object> config) {
|
||||
//TODO handle default values
|
||||
String timezone = (String) config.get("timezone");
|
||||
String locale = (String) config.get("locale");
|
||||
String timezoneString = (String) config.get("timezone");
|
||||
DateTimeZone timezone = (timezoneString == null) ? DateTimeZone.UTC : DateTimeZone.forID(timezoneString);
|
||||
String localeString = (String) config.get("locale");
|
||||
Locale locale = localeString == null ? Locale.ENGLISH : Locale.forLanguageTag(localeString);
|
||||
String matchField = (String) config.get("match_field");
|
||||
List<String> matchFormats = (List<String>) config.get("match_formats");
|
||||
String targetField = (String) config.get("target_field");
|
||||
if (targetField == null) {
|
||||
targetField = DEFAULT_TARGET_FIELD;
|
||||
}
|
||||
return new DateProcessor(timezone, locale, matchField, matchFormats, targetField);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,16 +29,7 @@ public class ISO8601DateParser implements DateParser {
|
|||
private final DateTimeFormatter formatter;
|
||||
|
||||
public ISO8601DateParser(DateTimeZone timezone) {
|
||||
formatter = ISODateTimeFormat.dateTimeParser().withZone(timezone);
|
||||
}
|
||||
|
||||
public ISO8601DateParser() {
|
||||
formatter = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long parseMillis(String date) {
|
||||
return formatter.parseMillis(date);
|
||||
this.formatter = ISODateTimeFormat.dateTimeParser().withZone(timezone);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,35 +30,12 @@ public class JodaPatternDateParser implements DateParser {
|
|||
|
||||
private final DateTimeFormatter formatter;
|
||||
|
||||
public JodaPatternDateParser(String format) {
|
||||
formatter = DateTimeFormat.forPattern(format)
|
||||
.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear())
|
||||
.withOffsetParsed();
|
||||
}
|
||||
|
||||
public JodaPatternDateParser(String format, DateTimeZone timezone) {
|
||||
formatter = DateTimeFormat.forPattern(format)
|
||||
.withDefaultYear((new DateTime(timezone)).getYear())
|
||||
.withZone(timezone);
|
||||
}
|
||||
|
||||
public JodaPatternDateParser(String format, Locale locale) {
|
||||
formatter = DateTimeFormat.forPattern(format)
|
||||
.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear())
|
||||
.withLocale(locale);
|
||||
}
|
||||
|
||||
public JodaPatternDateParser(String format, DateTimeZone timezone, Locale locale) {
|
||||
formatter = DateTimeFormat.forPattern(format)
|
||||
.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear())
|
||||
.withZone(timezone).withLocale(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long parseMillis(String date) {
|
||||
return formatter.parseMillis(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime parseDateTime(String date) {
|
||||
return formatter.parseDateTime(date);
|
||||
|
|
|
@ -30,9 +30,13 @@ public class TAI64NDateParser implements DateParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long parseMillis(String date) {
|
||||
public DateTime parseDateTime(String date) {
|
||||
return new DateTime(parseMillis(date), timezone);
|
||||
}
|
||||
|
||||
private static long parseMillis(String date) {
|
||||
if (date.startsWith("@")) {
|
||||
date = date.substring(1);
|
||||
date = date.substring(1);
|
||||
}
|
||||
long base = Long.parseLong(date.substring(1, 16), 16);
|
||||
// 1356138046000
|
||||
|
@ -40,9 +44,4 @@ public class TAI64NDateParser implements DateParser {
|
|||
|
||||
return ((base * 1000) - 10000) + (rest/1000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime parseDateTime(String date) {
|
||||
return new DateTime(parseMillis(date), timezone);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,13 +29,12 @@ public class UnixDateParser implements DateParser {
|
|||
this.timezone = timezone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long parseMillis(String date) {
|
||||
return (long) (Float.parseFloat(date) * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime parseDateTime(String date) {
|
||||
return new DateTime(parseMillis(date), timezone);
|
||||
}
|
||||
|
||||
private static long parseMillis(String date) {
|
||||
return (long) (Float.parseFloat(date) * 1000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,13 +29,8 @@ public class UnixMsDateParser implements DateParser {
|
|||
this.timezone = timezone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long parseMillis(String date) {
|
||||
return Long.parseLong(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateTime parseDateTime(String date) {
|
||||
return new DateTime(parseMillis(date), timezone);
|
||||
return new DateTime(Long.parseLong(date), timezone);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class DateParserTests extends ESTestCase {
|
||||
|
||||
public void testJodaPatternParse() {
|
||||
JodaPatternDateParser parser = new JodaPatternDateParser("MMM dd HH:mm:ss Z",
|
||||
DateTimeZone.forOffsetHours(-8), Locale.ENGLISH);
|
||||
|
||||
assertThat(Instant.ofEpochMilli(parser.parseDateTime("Nov 24 01:29:01 -0800").getMillis())
|
||||
.atZone(ZoneId.of("GMT-8"))
|
||||
.format(DateTimeFormatter.ofPattern("MM dd HH:mm:ss", Locale.ENGLISH)),
|
||||
equalTo("11 24 01:29:01"));
|
||||
}
|
||||
|
||||
public void testParseUnixMs() {
|
||||
UnixMsDateParser parser = new UnixMsDateParser(DateTimeZone.UTC);
|
||||
assertThat(parser.parseDateTime("1000500").getMillis(), equalTo(1000500L));
|
||||
}
|
||||
|
||||
public void testUnixParse() {
|
||||
UnixDateParser parser = new UnixDateParser(DateTimeZone.UTC);
|
||||
assertThat(parser.parseDateTime("1000.5").getMillis(), equalTo(1000500L));
|
||||
}
|
||||
|
||||
public void testParseISO8601() {
|
||||
ISO8601DateParser parser = new ISO8601DateParser(DateTimeZone.UTC);
|
||||
assertThat(parser.parseDateTime("2001-01-01T00:00:00-0800").getMillis(), equalTo(978336000000L));
|
||||
}
|
||||
|
||||
public void testParseISO8601Failure() {
|
||||
ISO8601DateParser parser = new ISO8601DateParser(DateTimeZone.UTC);
|
||||
try {
|
||||
parser.parseDateTime("2001-01-0:00-0800");
|
||||
fail("parse should have failed");
|
||||
} catch(IllegalArgumentException e) {
|
||||
//all good
|
||||
}
|
||||
}
|
||||
|
||||
public void testTAI64NParse() {
|
||||
TAI64NDateParser parser = new TAI64NDateParser(DateTimeZone.forOffsetHours(2));
|
||||
String input = "4000000050d506482dbdf024";
|
||||
String expected = "2012-12-22T03:00:46.767+02:00";
|
||||
assertThat(parser.parseDateTime((randomBoolean() ? "@" : "") + input).toString(), equalTo(expected));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Licensed to ElasticSearch and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. ElasticSearch licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.ingest.Data;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class DateProcessorTests extends ESTestCase {
|
||||
|
||||
public void testJodaPattern() {
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.forID("Europe/Amsterdam"), Locale.ENGLISH,
|
||||
"date_as_string", Collections.singletonList("yyyy dd MM hh:mm:ss"), "date_as_date");
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("date_as_string", "2010 12 06 11:05:15");
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("2010-06-12T11:05:15.000+02:00"));
|
||||
}
|
||||
|
||||
public void testJodaPatternMultipleFormats() {
|
||||
List<String> matchFormats = new ArrayList<>();
|
||||
matchFormats.add("yyyy dd MM");
|
||||
matchFormats.add("dd/MM/yyyy");
|
||||
matchFormats.add("dd-MM-yyyy");
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.forID("Europe/Amsterdam"), Locale.ENGLISH,
|
||||
"date_as_string", matchFormats, "date_as_date");
|
||||
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("date_as_string", "2010 12 06");
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||
|
||||
document = new HashMap<>();
|
||||
document.put("date_as_string", "12/06/2010");
|
||||
data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||
|
||||
document = new HashMap<>();
|
||||
document.put("date_as_string", "12-06-2010");
|
||||
data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||
|
||||
document = new HashMap<>();
|
||||
document.put("date_as_string", "2010");
|
||||
data = new Data("index", "type", "id", document);
|
||||
try {
|
||||
dateProcessor.execute(data);
|
||||
fail("processor should have failed due to not supported date format");
|
||||
} catch(IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("unable to parse date [2010]"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testJodaPatternLocale() {
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.forID("Europe/Amsterdam"), Locale.ITALIAN,
|
||||
"date_as_string", Collections.singletonList("yyyy dd MMM"), "date_as_date");
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("date_as_string", "2010 12 giugno");
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("2010-06-12T00:00:00.000+02:00"));
|
||||
}
|
||||
|
||||
public void testJodaPatternDefaultYear() {
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.forID("Europe/Amsterdam"), Locale.ENGLISH,
|
||||
"date_as_string", Collections.singletonList("dd/MM"), "date_as_date");
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("date_as_string", "12/06");
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo(DateTime.now().getYear() + "-06-12T00:00:00.000+02:00"));
|
||||
}
|
||||
|
||||
public void testTAI64N() {
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.forOffsetHours(2), randomLocale(random()),
|
||||
"date_as_string", Collections.singletonList(DateParserFactory.TAI64N), "date_as_date");
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
String dateAsString = (randomBoolean() ? "@" : "") + "4000000050d506482dbdf024";
|
||||
document.put("date_as_string", dateAsString);
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("2012-12-22T03:00:46.767+02:00"));
|
||||
}
|
||||
|
||||
public void testUnixMs() {
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.UTC, randomLocale(random()),
|
||||
"date_as_string", Collections.singletonList(DateParserFactory.UNIX_MS), "date_as_date");
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("date_as_string", "1000500");
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("1970-01-01T00:16:40.500Z"));
|
||||
}
|
||||
|
||||
public void testUnix() {
|
||||
DateProcessor dateProcessor = new DateProcessor(DateTimeZone.UTC, randomLocale(random()),
|
||||
"date_as_string", Collections.singletonList(DateParserFactory.UNIX), "date_as_date");
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("date_as_string", "1000.5");
|
||||
Data data = new Data("index", "type", "id", document);
|
||||
dateProcessor.execute(data);
|
||||
assertThat(data.getProperty("date_as_date"), equalTo("1970-01-01T00:16:40.500Z"));
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class ISO8601DateParserTests extends ESTestCase {
|
||||
|
||||
public void testParseUTC() {
|
||||
ISO8601DateParser parser = new ISO8601DateParser(DateTimeZone.UTC);
|
||||
assertThat(parser.parseMillis("2001-01-01T00:00:00-0800"), equalTo(978336000000L));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testParseFailure() {
|
||||
ISO8601DateParser parser = new ISO8601DateParser(DateTimeZone.UTC);
|
||||
parser.parseMillis("2001-01-0:00-0800");
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class JodaPatternDateParserTests extends ESTestCase {
|
||||
|
||||
public void testParse() {
|
||||
JodaPatternDateParser parser = new JodaPatternDateParser("MMM dd HH:mm:ss Z",
|
||||
DateTimeZone.forOffsetHours(-8), Locale.ENGLISH);
|
||||
|
||||
assertThat(Instant.ofEpochMilli(parser.parseMillis("Nov 24 01:29:01 -0800"))
|
||||
.atZone(ZoneId.of("GMT-8"))
|
||||
.format(DateTimeFormatter.ofPattern("MM dd HH:mm:ss", Locale.ENGLISH)),
|
||||
equalTo("11 24 01:29:01"));
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class TAI64NDateParserTests extends ESTestCase {
|
||||
|
||||
public void testParse() {
|
||||
TAI64NDateParser parser = new TAI64NDateParser(DateTimeZone.forOffsetHours(2));
|
||||
String input = "4000000050d506482dbdf024";
|
||||
String expected = "2012-12-22T03:00:46.767+02:00";
|
||||
assertThat(parser.parseDateTime("@" + input).toString(), equalTo(expected));
|
||||
assertThat(parser.parseDateTime(input).toString(), equalTo(expected));
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class UnixDateParserTests extends ESTestCase {
|
||||
|
||||
public void testParse() {
|
||||
UnixDateParser parser = new UnixDateParser(DateTimeZone.UTC);
|
||||
assertThat(parser.parseMillis("1000.5"), equalTo(1000500L));
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.ingest.processor.date;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class UnixMsDateParserTests extends ESTestCase {
|
||||
|
||||
public void testParse() {
|
||||
UnixMsDateParser parser = new UnixMsDateParser(DateTimeZone.UTC);
|
||||
assertThat(parser.parseMillis("1000500"), equalTo(1000500L));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue