diff --git a/src/main/java/org/elasticsearch/common/rounding/TimeZoneRounding.java b/src/main/java/org/elasticsearch/common/rounding/TimeZoneRounding.java index 90835930afa..02a9725b37b 100644 --- a/src/main/java/org/elasticsearch/common/rounding/TimeZoneRounding.java +++ b/src/main/java/org/elasticsearch/common/rounding/TimeZoneRounding.java @@ -125,7 +125,7 @@ public abstract class TimeZoneRounding extends Rounding { long timeLocal = utcMillis; timeLocal = timeZone.convertUTCToLocal(utcMillis); long rounded = field.roundFloor(timeLocal); - return timeZone.convertLocalToUTC(rounded, true, utcMillis); + return timeZone.convertLocalToUTC(rounded, false, utcMillis); } @Override @@ -139,7 +139,7 @@ public abstract class TimeZoneRounding extends Rounding { long timeLocal = time; timeLocal = timeZone.convertUTCToLocal(time); long nextInLocalTime = durationField.add(timeLocal, 1); - return timeZone.convertLocalToUTC(nextInLocalTime, true); + return timeZone.convertLocalToUTC(nextInLocalTime, false); } @Override @@ -184,7 +184,7 @@ public abstract class TimeZoneRounding extends Rounding { long timeLocal = utcMillis; timeLocal = timeZone.convertUTCToLocal(utcMillis); long rounded = Rounding.Interval.roundValue(Rounding.Interval.roundKey(timeLocal, interval), interval); - return timeZone.convertLocalToUTC(rounded, true); + return timeZone.convertLocalToUTC(rounded, false); } @Override @@ -198,7 +198,7 @@ public abstract class TimeZoneRounding extends Rounding { long timeLocal = time; timeLocal = timeZone.convertUTCToLocal(time); long next = timeLocal + interval; - return timeZone.convertLocalToUTC(next, true); + return timeZone.convertLocalToUTC(next, false); } @Override diff --git a/src/test/java/org/elasticsearch/common/rounding/TimeZoneRoundingTests.java b/src/test/java/org/elasticsearch/common/rounding/TimeZoneRoundingTests.java index 95223cccb96..0a6d8f980d3 100644 --- a/src/test/java/org/elasticsearch/common/rounding/TimeZoneRoundingTests.java +++ b/src/test/java/org/elasticsearch/common/rounding/TimeZoneRoundingTests.java @@ -280,6 +280,23 @@ public class TimeZoneRoundingTests extends ElasticsearchTestCase { equalTo(tzRounding.round(time("2014-08-11T17:00:00", JERUSALEM_TIMEZONE)))); } + /** + * test for #10025, strict local to UTC conversion can cause joda exceptions + * on DST start + */ + @Test + public void testLenientConversionDST() { + DateTimeZone tz = DateTimeZone.forID("America/Sao_Paulo"); + long start = time("2014-10-18T20:50:00.000", tz); + long end = time("2014-10-19T01:00:00.000", tz); + Rounding tzRounding = new TimeZoneRounding.TimeUnitRounding(DateTimeUnit.MINUTES_OF_HOUR, tz); + Rounding dayTzRounding = new TimeZoneRounding.TimeIntervalRounding(60000, tz); + for (long time = start; time < end; time = time + 60000) { + assertThat(tzRounding.nextRoundingValue(time), greaterThan(time)); + assertThat(dayTzRounding.nextRoundingValue(time), greaterThan(time)); + } + } + private DateTimeUnit randomTimeUnit() { byte id = (byte) randomIntBetween(1, 8); return DateTimeUnit.resolve(id);