-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-16774][SQL] Fix use of deprecated timestamp constructor & improve timezone handling #14398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
7c0fd8d
634a05e
6233b4c
e4508e3
0385d8b
5e80a8d
c01db02
ec75f73
7c28252
8670bb6
1109275
671f7be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ import javax.xml.bind.DatatypeConverter | |
|
|
||
| import scala.annotation.tailrec | ||
|
|
||
| import sun.util.calendar.CalendarSystem | ||
|
|
||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
||
| /** | ||
|
|
@@ -852,8 +854,9 @@ object DateTimeUtils { | |
|
|
||
| /** | ||
| * Lookup the offset for given millis seconds since 1970-01-01 00:00:00 in given timezone. | ||
| * TODO: Improve handling of normalization differences. | ||
| */ | ||
| private def getOffsetFromLocalMillis(millisLocal: Long, tz: TimeZone): Long = { | ||
| private[sql] def getOffsetFromLocalMillis(millisLocal: Long, tz: TimeZone): Long = { | ||
| var guess = tz.getRawOffset | ||
| // the actual offset should be calculated based on milliseconds in UTC | ||
| val offset = tz.getOffset(millisLocal - guess) | ||
|
|
@@ -875,11 +878,20 @@ object DateTimeUtils { | |
| val hh = seconds / 3600 | ||
| val mm = seconds / 60 % 60 | ||
| val ss = seconds % 60 | ||
| val nano = millisOfDay % 1000 * 1000000 | ||
| val millis = millisOfDay % 1000 | ||
| // Choose calendar based on java.util.Date getCalendarSystem | ||
| val calendar = if (year >= 1582) { | ||
| CalendarSystem.getGregorianCalendar() | ||
|
||
| } else { | ||
| CalendarSystem.forName("julian") | ||
| } | ||
|
|
||
| // create a Timestamp to get the unix timestamp (in UTC) | ||
| val timestamp = new Timestamp(year - 1900, month - 1, day, hh, mm, ss, nano) | ||
| guess = (millisLocal - timestamp.getTime).toInt | ||
| // create a CalendarDate in the provided timezone | ||
| val date = calendar.newCalendarDate(tz). | ||
| setDate(year, month, day). | ||
| setTimeOfDay(hh, mm, ss, millis) | ||
| calendar.getTime(date) // Set the timezone info | ||
| guess = date.getZoneOffset() | ||
| } | ||
| } | ||
| guess | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using
java.util.Calendarright -- I presume anysun.classes are not for use by applications.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable - will also allow us to hide the julian calendar usage for old dates.