Skip to content

Commit f23b545

Browse files
author
Davies Liu
committed
more acurate
1 parent ac3d2b5 commit f23b545

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,18 @@ object DateTimeUtils {
857857
var guess = tz.getRawOffset
858858
// the actual offset should be calculated based on milliseconds in UTC
859859
var actual = tz.getOffset(millisLocal - guess)
860-
// At the start of DST, the local time is forwarded by an hour, so it's OK to get the
861-
// local time bigger than current one after an round trip (local -> UTC -> local).
862-
// At the end of DST, the local time is backwarded by an hour, actual offset will be
863-
// less than guess, we should decrease the guess and try again.
864-
while (actual < guess) {
860+
if (actual != guess) {
861+
// try with the result as guess
865862
guess = actual
866863
actual = tz.getOffset(millisLocal - guess)
864+
// At the start of DST, the local time is forwarded by an hour, so it's OK to get the
865+
// local time bigger than current one after an round trip (local -> UTC -> local).
866+
// At the end of DST, the local time is backwarded by an hour, actual offset will be
867+
// less than guess, we should decrease the guess and try again.
868+
while (actual < guess) {
869+
guess = actual
870+
actual = tz.getOffset(millisLocal - guess)
871+
}
867872
}
868873
guess
869874
}

0 commit comments

Comments
 (0)