Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add back tests and add some more notes
  • Loading branch information
holdenk committed Jul 30, 2016
commit 8670bb62a57cabe8a1a6bbab32330f3dc71f9977
Original file line number Diff line number Diff line change
Expand Up @@ -877,11 +877,17 @@ object DateTimeUtils {
val hh = seconds / 3600
val mm = seconds / 60 % 60
val ss = seconds % 60
val ms = millisOfDay % 1000
val calendar = Calendar.getInstance(tz)

calendar.set(year, month, day, hh, mm, ss)
calendar.getTime() // Set the timezone info
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

// TODO decide between return the offset from the calendar:
guess = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)
// And returning the difference between timestamps (end up broken in different ways)
// This way appears to return a non-DST value even when in DST - but our round trips tests
// will work.
// guess = (millisLocal - calendar.getTimeInMillis()).toInt
}
}
guess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,29 @@ class DateTimeUtilsSuite extends SparkFunSuite {
}
}

test("daysToMillis and millisToDays") {
// There are some days are skipped entirely in some timezone, skip them here.
val skipped_days = Map[String, Int](
"Kwajalein" -> 8632,
"Pacific/Apia" -> 15338,
"Pacific/Enderbury" -> 9131,
"Pacific/Fakaofo" -> 15338,
"Pacific/Kiritimati" -> 9131,
"Pacific/Kwajalein" -> 8632,
"MIT" -> 15338)
for (tz <- DateTimeTestUtils.ALL_TIMEZONES) {
DateTimeTestUtils.withDefaultTimeZone(tz) {
val skipped = skipped_days.getOrElse(tz.getID, Int.MinValue)
(-20000 to 20000).foreach { d =>
if (d != skipped) {
assert(millisToDays(daysToMillis(d)) === d,
s"Round trip of ${d} did not work in tz ${tz}")
}
}
}
}
}

test("convert TZ with boundary time pacific") {
val tz = TimeZone.getTimeZone("America/Los_Angeles")
val boundaryDates = List(
Expand Down