Skip to content

Commit

Permalink
Update Joda Time to version 2.9.5 (#21468)
Browse files Browse the repository at this point in the history
This commit updates JodaTime to version 2.9.5 that contain a fix for a bug when parsing time zones (see JodaOrg/joda-time#332, JodaOrg/joda-time#386 and JodaOrg/joda-time#373).

It also remove the joda-convert dependency that seems to be unused.

closes #20911

Here is the changelog for 2.9.5:
```
Changes in 2.9.5
----------------
 - Add Norwegian period translations [#378]

 - Add Duration.dividedBy(long,RoundingMode) [#69, #379]

 - DateTimeZone data updated to version 2016i

 - Fixed bug where clock read twice when comparing two nulls in DateTimeComparator [#404]

 - Fixed minor issues with historic time-zone data [#373]

 - Fix bug in time-zone binary search [#332, #386]
  The fix in v2.9.2 caused problems when the time-zone being parsed
  was not the last element in the input string. New approach uses a
  different approach to the problem.

 - Update tests for JDK 9 [#394]

 - Close buffered reader correctly in zone info compiler [#396]

 - Handle locale correctly zone info compiler [#397]
```

(cherry picked from commit 2e53190)
  • Loading branch information
tlrx committed Nov 10, 2016
1 parent 5de4853 commit 6cd0c73
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 220 deletions.
5 changes: 1 addition & 4 deletions core/build.gradle
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
@@ -0,0 +1 @@
5f01da7306363fad2028b916f3eab926262de928
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;

/**
*/
Expand Down Expand Up @@ -513,6 +516,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
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());
}
}

0 comments on commit 6cd0c73

Please sign in to comment.