Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ dependencies {
compile 'com.carrotsearch:hppc:0.7.1'

// time handling, remove with java 8 time
compile 'joda-time:joda-time:2.9.4'
// joda 2.0 moved to using volatile fields for datetime
// When updating to a new version, make sure to update our copy of BaseDateTime
compile 'org.joda:joda-convert:1.2'
compile 'joda-time:joda-time:2.9.5'

// json and yaml
compile "org.yaml:snakeyaml:${versions.snakeyaml}"
Expand Down
1 change: 0 additions & 1 deletion core/licenses/joda-convert-1.2.jar.sha1

This file was deleted.

202 changes: 0 additions & 202 deletions core/licenses/joda-convert-LICENSE.txt

This file was deleted.

5 changes: 0 additions & 5 deletions core/licenses/joda-convert-NOTICE.txt

This file was deleted.

1 change: 0 additions & 1 deletion core/licenses/joda-time-2.9.4.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions core/licenses/joda-time-2.9.5.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5f01da7306363fad2028b916f3eab926262de928
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

import java.util.ArrayList;
Expand All @@ -41,6 +43,7 @@
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.startsWith;

public class TimeZoneRoundingTests extends ESTestCase {

Expand Down Expand Up @@ -511,6 +514,25 @@ public void testEdgeCasesTransition() {
}
}

/**
* Test that time zones are correctly parsed. There is a bug with
* Joda 2.9.4 (see https://github.com/JodaOrg/joda-time/issues/373)
*/
public void testsTimeZoneParsing() {
final DateTime expected = new DateTime(2016, 11, 10, 5, 37, 59, randomDateTimeZone());

// Formatter used to print and parse the sample date.
// Printing the date works but parsing it back fails
// with Joda 2.9.4
DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ss " + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'"));

String dateTimeAsString = formatter.print(expected);
assertThat(dateTimeAsString, startsWith("2016-11-10T05:37:59 "));

DateTime parsedDateTime = formatter.parseDateTime(dateTimeAsString);
assertThat(parsedDateTime.getZone(), equalTo(expected.getZone()));
}

private static void assertInterval(long rounded, long nextRoundingValue, Rounding rounding, int minutes,
DateTimeZone tz) {
assertInterval(rounded, dateBetween(rounded, nextRoundingValue), nextRoundingValue, rounding, tz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.elasticsearch.test.VersionUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.junit.Before;

import java.io.IOException;
Expand Down Expand Up @@ -354,4 +350,39 @@ public void testEmptyName() throws IOException {
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, defaultMapper.mappingSource().toString());
}

/**
* Test that time zones are correctly parsed by the {@link DateFieldMapper}.
* There is a known bug with Joda 2.9.4 reported in https://github.com/JodaOrg/joda-time/issues/373.
*/
public void testTimeZoneParsing() throws Exception {
final String timeZonePattern = "yyyy-MM-dd" + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'");

String mapping = XContentFactory.jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "date")
.field("format", timeZonePattern)
.endObject()
.endObject()
.endObject().endObject().string();

DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());

final DateTimeZone randomTimeZone = randomBoolean() ? DateTimeZone.forID(randomFrom("UTC", "CET")) : randomDateTimeZone();
final DateTime randomDate = new DateTime(2016, 03, 11, 0, 0, 0, randomTimeZone);

ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
.startObject()
.field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate))
.endObject()
.bytes());

IndexableField[] fields = doc.rootDoc().getFields("field");
assertEquals(2, fields.length);

assertEquals(randomDate.withZone(DateTimeZone.UTC).getMillis(), fields[0].numericValue().longValue());
}
}