Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,10 @@ 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.
* TODO: Replace with JSR-310 or similar system - see SPARK-16788
*/
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)
Expand All @@ -875,11 +877,12 @@ object DateTimeUtils {
val hh = seconds / 3600
val mm = seconds / 60 % 60
val ss = seconds % 60
val nano = millisOfDay % 1000 * 1000000

// 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
val ms = millisOfDay % 1000
val calendar = Calendar.getInstance(tz)
calendar.set(year, month - 1, day, hh, mm, ss)
calendar.set(Calendar.MILLISECOND, ms)
val date = calendar.getTime()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unnecessary ... if the intend is to make sure Calendar.computeTime() will be invoked then that will happen when calling calendar.getTimeInMillis() on the next line as well

guess = (millisLocal - calendar.getTimeInMillis()).toInt
}
}
guess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ class DateTimeUtilsSuite extends SparkFunSuite {
val skipped = skipped_days.getOrElse(tz.getID, Int.MinValue)
(-20000 to 20000).foreach { d =>
if (d != skipped) {
assert(millisToDays(daysToMillis(d)) === d)
assert(millisToDays(daysToMillis(d)) === d,
s"Round trip of ${d} did not work in tz ${tz}")
}
}
}
Expand Down