Skip to content

Commit 3efd3f6

Browse files
committed
Supports parsing dates with UTC as zone-id
Such as: `2031-12-03T10:15:30.123456789Z[UTC]`
1 parent 3d75f22 commit 3efd3f6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

server/src/main/java/org/elasticsearch/common/time/Iso8601Parser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ private ZoneId parseZoneId(CharSequence str, int pos) {
450450

451451
boolean positive;
452452
switch (first) {
453-
case '+' -> positive = true;
453+
case '+', 'Z' -> positive = true;
454454
case '-' -> positive = false;
455455
default -> {
456456
// non-trivial zone offset, fallback on the built-in java zoneid parser
@@ -462,6 +462,9 @@ private ZoneId parseZoneId(CharSequence str, int pos) {
462462
}
463463
}
464464
pos++; // read the + or -
465+
if (str.charAt(pos) == '[' && str.charAt(len - 1) == ']') {
466+
return parseRawZoneId(str, pos);
467+
}
465468

466469
Integer hours = parseInt(str, pos, pos += 2);
467470
if (hours == null || hours > 23) return null;

server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ public void testParsingDateTimeWithZoneId() {
615615
formatter.format(formatter.parse("2031-12-03T10:15:30.123456789+01:00:00[Europe/Paris]"));
616616
formatter.format(formatter.parse("2031-12-03T10:15:30.123456789+01:00:00[PST]"));
617617
formatter.format(formatter.parse("2031-12-03T10:15:30.123456789+01:00:00[EST]"));
618+
formatter.format(formatter.parse("2031-12-03T10:15:30.123456789Z[UTC]"));
618619
}
619620

620621
public void testRoundupFormatterWithEpochDates() {

0 commit comments

Comments
 (0)