leventov closed pull request #6344: Fix a bug which druid's parsing formatted time field in a non-zero time zone URL: https://github.com/apache/incubator-druid/pull/6344
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/java-util/src/main/java/org/apache/druid/java/util/common/DateTimes.java b/java-util/src/main/java/org/apache/druid/java/util/common/DateTimes.java index 74e221cb9a2..1cef517cbdb 100644 --- a/java-util/src/main/java/org/apache/druid/java/util/common/DateTimes.java +++ b/java-util/src/main/java/org/apache/druid/java/util/common/DateTimes.java @@ -51,18 +51,13 @@ public static DateTimeZone inferTzfromString(String tzId) } } - /** - * Simple wrapper class to enforce UTC Chronology in formatter. Specifically, it will use - * {@link DateTimeFormatter#withChronology(Chronology)} to set the chronology to - * {@link ISOChronology#getInstanceUTC()} on the wrapped {@link DateTimeFormatter}. - */ - public static class UtcFormatter + public abstract static class Formatter { - private final DateTimeFormatter innerFormatter; + private DateTimeFormatter innerFormatter; - private UtcFormatter(final DateTimeFormatter innerFormatter) + public Formatter(DateTimeFormatter innerFormatter) { - this.innerFormatter = innerFormatter.withChronology(ISOChronology.getInstanceUTC()); + this.innerFormatter = innerFormatter; } public DateTime parse(final String instant) @@ -76,6 +71,31 @@ public String print(final DateTime instant) } } + /** + * Simple wrapper class to enforce UTC Chronology in formatter. Specifically, it will use + * {@link DateTimeFormatter#withChronology(Chronology)} to set the chronology to + * {@link ISOChronology#getInstanceUTC()} on the wrapped {@link DateTimeFormatter}. + */ + public static class UtcFormatter extends Formatter + { + private UtcFormatter(final DateTimeFormatter innerFormatter) + { + super(innerFormatter.withChronology(ISOChronology.getInstanceUTC())); + } + } + + + /** + * System Formatter wrapper with JVM's timezone, if user does't specify in jvm.config, system's timezone will be used + */ + public static class SysFormatter extends Formatter + { + public SysFormatter(DateTimeFormatter innerFormatter) + { + super(innerFormatter.withChronology(ISOChronology.getInstance(DateTimeZone.getDefault()))); + } + } + /** * Creates a {@link UtcFormatter} that wraps around a {@link DateTimeFormatter}. * diff --git a/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java b/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java index 38f12060942..2628a8239fd 100644 --- a/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java +++ b/java-util/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java @@ -86,7 +86,7 @@ }; } else { try { - final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format)); + final DateTimes.SysFormatter formatter = new DateTimes.SysFormatter(DateTimeFormat.forPattern(format)); return input -> { Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp"); return formatter.parse(ParserUtils.stripQuotes(input)); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org