Skip to content

Commit a5701c8

Browse files
committed
Update Joda Time to version 2.9.5 (#21468)
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)
1 parent db796fc commit a5701c8

File tree

8 files changed

+62
-220
lines changed

8 files changed

+62
-220
lines changed

core/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ dependencies {
6262
compile 'com.carrotsearch:hppc:0.7.1'
6363

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

7067
// json and yaml
7168
compile "org.yaml:snakeyaml:${versions.snakeyaml}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5f01da7306363fad2028b916f3eab926262de928

core/src/test/java/org/elasticsearch/common/rounding/TimeZoneRoundingTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.joda.time.DateTime;
3131
import org.joda.time.DateTimeConstants;
3232
import org.joda.time.DateTimeZone;
33+
import org.joda.time.format.DateTimeFormat;
34+
import org.joda.time.format.DateTimeFormatter;
3335
import org.joda.time.format.ISODateTimeFormat;
3436

3537
import java.util.ArrayList;
@@ -41,6 +43,7 @@
4143
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4244
import static org.hamcrest.Matchers.lessThan;
4345
import static org.hamcrest.Matchers.lessThanOrEqualTo;
46+
import static org.hamcrest.Matchers.startsWith;
4447

4548
/**
4649
*/
@@ -513,6 +516,25 @@ public void testEdgeCasesTransition() {
513516
}
514517
}
515518

519+
/**
520+
* Test that time zones are correctly parsed. There is a bug with
521+
* Joda 2.9.4 (see https://github.com/JodaOrg/joda-time/issues/373)
522+
*/
523+
public void testsTimeZoneParsing() {
524+
final DateTime expected = new DateTime(2016, 11, 10, 5, 37, 59, randomDateTimeZone());
525+
526+
// Formatter used to print and parse the sample date.
527+
// Printing the date works but parsing it back fails
528+
// with Joda 2.9.4
529+
DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ss " + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'"));
530+
531+
String dateTimeAsString = formatter.print(expected);
532+
assertThat(dateTimeAsString, startsWith("2016-11-10T05:37:59 "));
533+
534+
DateTime parsedDateTime = formatter.parseDateTime(dateTimeAsString);
535+
assertThat(parsedDateTime.getZone(), equalTo(expected.getZone()));
536+
}
537+
516538
private static void assertInterval(long rounded, long nextRoundingValue, Rounding rounding, int minutes,
517539
DateTimeZone tz) {
518540
assertInterval(rounded, dateBetween(rounded, nextRoundingValue), nextRoundingValue, rounding, tz);

core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,15 @@
2525
import org.elasticsearch.cluster.metadata.IndexMetaData;
2626
import org.elasticsearch.common.compress.CompressedXContent;
2727
import org.elasticsearch.common.settings.Settings;
28-
import org.elasticsearch.common.xcontent.ToXContent;
29-
import org.elasticsearch.common.xcontent.XContentBuilder;
3028
import org.elasticsearch.common.xcontent.XContentFactory;
3129
import org.elasticsearch.index.IndexService;
32-
import org.elasticsearch.index.mapper.DocumentMapper;
33-
import org.elasticsearch.index.mapper.DocumentMapperParser;
34-
import org.elasticsearch.index.mapper.FieldMapper;
35-
import org.elasticsearch.index.mapper.MapperParsingException;
36-
import org.elasticsearch.index.mapper.ParsedDocument;
3730
import org.elasticsearch.plugins.Plugin;
3831
import org.elasticsearch.test.ESSingleNodeTestCase;
3932
import org.elasticsearch.test.InternalSettingsPlugin;
4033
import org.elasticsearch.test.VersionUtils;
34+
import org.joda.time.DateTime;
35+
import org.joda.time.DateTimeZone;
36+
import org.joda.time.format.DateTimeFormat;
4137
import org.junit.Before;
4238

4339
import java.io.IOException;
@@ -354,4 +350,39 @@ public void testEmptyName() throws IOException {
354350
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
355351
assertEquals(mapping, defaultMapper.mappingSource().toString());
356352
}
353+
354+
/**
355+
* Test that time zones are correctly parsed by the {@link DateFieldMapper}.
356+
* There is a known bug with Joda 2.9.4 reported in https://github.com/JodaOrg/joda-time/issues/373.
357+
*/
358+
public void testTimeZoneParsing() throws Exception {
359+
final String timeZonePattern = "yyyy-MM-dd" + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'");
360+
361+
String mapping = XContentFactory.jsonBuilder().startObject()
362+
.startObject("type")
363+
.startObject("properties")
364+
.startObject("field")
365+
.field("type", "date")
366+
.field("format", timeZonePattern)
367+
.endObject()
368+
.endObject()
369+
.endObject().endObject().string();
370+
371+
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
372+
assertEquals(mapping, mapper.mappingSource().toString());
373+
374+
final DateTimeZone randomTimeZone = randomBoolean() ? DateTimeZone.forID(randomFrom("UTC", "CET")) : randomDateTimeZone();
375+
final DateTime randomDate = new DateTime(2016, 03, 11, 0, 0, 0, randomTimeZone);
376+
377+
ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
378+
.startObject()
379+
.field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate))
380+
.endObject()
381+
.bytes());
382+
383+
IndexableField[] fields = doc.rootDoc().getFields("field");
384+
assertEquals(2, fields.length);
385+
386+
assertEquals(randomDate.withZone(DateTimeZone.UTC).getMillis(), fields[0].numericValue().longValue());
387+
}
357388
}

distribution/licenses/joda-convert-1.2.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

distribution/licenses/joda-convert-LICENSE.txt

Lines changed: 0 additions & 202 deletions
This file was deleted.

distribution/licenses/joda-convert-NOTICE.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

distribution/licenses/joda-time-2.9.4.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)