From 6acbefe3f7463e48a7721d5bfadaf051be4a0a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 4 Nov 2016 10:42:08 +0100 Subject: [PATCH] Add tests for alternative ways of writing zero offset timezones According to ISO 8601, a time zone offset of zero, can be stated numerically as "+00:00", "+0000", or "00". The Joda library also seems to allow for "-00:00", "-00" and "-0000". This adds some test to the DateMathParserTests that check that we also conform to this. Closes #21320 --- .../common/joda/DateMathParserTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/common/joda/DateMathParserTests.java b/core/src/test/java/org/elasticsearch/common/joda/DateMathParserTests.java index 505196a97f6..ca9a6b3a1ab 100644 --- a/core/src/test/java/org/elasticsearch/common/joda/DateMathParserTests.java +++ b/core/src/test/java/org/elasticsearch/common/joda/DateMathParserTests.java @@ -82,8 +82,24 @@ public class DateMathParserTests extends ESTestCase { // timezone works within date format assertDateMathEquals("2014-05-30T20:21+02:00", "2014-05-30T18:21:00.000"); + // test alternative ways of writing zero offsets, according to ISO 8601 +00:00, +00, +0000 should work. + // joda also seems to allow for -00:00, -00, -0000 + assertDateMathEquals("2014-05-30T18:21+00:00", "2014-05-30T18:21:00.000"); + assertDateMathEquals("2014-05-30T18:21+00", "2014-05-30T18:21:00.000"); + assertDateMathEquals("2014-05-30T18:21+0000", "2014-05-30T18:21:00.000"); + assertDateMathEquals("2014-05-30T18:21-00:00", "2014-05-30T18:21:00.000"); + assertDateMathEquals("2014-05-30T18:21-00", "2014-05-30T18:21:00.000"); + assertDateMathEquals("2014-05-30T18:21-0000", "2014-05-30T18:21:00.000"); + // but also externally assertDateMathEquals("2014-05-30T20:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("+02:00")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("+00:00")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("+00:00")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("+00")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("+0000")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("-00:00")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("-00")); + assertDateMathEquals("2014-05-30T18:21", "2014-05-30T18:21:00.000", 0, false, DateTimeZone.forID("-0000")); // and timezone in the date has priority assertDateMathEquals("2014-05-30T20:21+03:00", "2014-05-30T17:21:00.000", 0, false, DateTimeZone.forID("-08:00"));