Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -320,16 +320,17 @@ object DateTimeUtils {
Calendar.getInstance(
TimeZone.getTimeZone(f"GMT${timeZone.get.toChar}${segments(7)}%02d:${segments(8)}%02d"))
}
c.set(Calendar.MILLISECOND, 0)

if (justTime) {
c.set(Calendar.HOUR, segments(3))
c.set(Calendar.HOUR_OF_DAY, segments(3))
c.set(Calendar.MINUTE, segments(4))
c.set(Calendar.SECOND, segments(5))
} else {
c.set(segments(0), segments(1) - 1, segments(2), segments(3), segments(4), segments(5))
}

Some(c.getTimeInMillis / 1000 * 1000000 + segments(6))
Some(c.getTimeInMillis * 1000 + segments(6))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why you have changed this. I divided by 1000 first in order to remove the call of c.set(Calendar.MILLISECOND, 0) in Line 323. But I am fine with this, I guess it's a personal preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

divide by 1000 is not right when c.getTimeInMillis is negative.
I'm really confused why jenkins didn't report test error for this case...

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't get this. Why is divide by 1000 a problem, if the date is before 1.1.1970? It's a long value and the last three digits are the millis. In order to cut them off, I divide by 1000. This has no impact on the sign or anything else, does it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's say now is a second before 1970-1-1:

val c = Calendar.getInstance(TimeZone.getTimeZone("GMT"))
c.set(1969, 11, 31, 23, 59, 59)
c.getTimeInMillis // something bigger than -1000, maybe -700
c.getTimeInMillis / 1000 * 1000000 == 0
c.set(Calendar.MILLISECOND, 0)
c.getTimeInMillis // exactly -1000
c.getTimeInMillis * 1000 == -1000000

In the test case we were testing "1969-12-31 16:00:00", so if the time zone in jenkins test environment is less than GMT-8, c.getTimeInMillis will be positive and this bug will be hidden.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it! Thanks for the explanation.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,17 @@ class DateTimeUtilsSuite extends SparkFunSuite {
UTF8String.fromString("2015-03-18T12:03:17.12312+7:30")).get ===
c.getTimeInMillis * 1000 + 120)

c = Calendar.getInstance()
c.set(Calendar.HOUR_OF_DAY, 18)
c.set(Calendar.MINUTE, 12)
c.set(Calendar.SECOND, 15)
c.set(Calendar.MILLISECOND, 0)
assert(DateTimeUtils.stringToTimestamp(
UTF8String.fromString("18:12:15")).get ===
c.getTimeInMillis * 1000)

c = Calendar.getInstance(TimeZone.getTimeZone("GMT+07:30"))
c.set(Calendar.HOUR, 18)
c.set(Calendar.HOUR_OF_DAY, 18)
c.set(Calendar.MINUTE, 12)
c.set(Calendar.SECOND, 15)
c.set(Calendar.MILLISECOND, 123)
Expand All @@ -253,7 +262,7 @@ class DateTimeUtilsSuite extends SparkFunSuite {
c.getTimeInMillis * 1000 + 120)

c = Calendar.getInstance(TimeZone.getTimeZone("GMT+07:30"))
c.set(Calendar.HOUR, 18)
c.set(Calendar.HOUR_OF_DAY, 18)
c.set(Calendar.MINUTE, 12)
c.set(Calendar.SECOND, 15)
c.set(Calendar.MILLISECOND, 123)
Expand Down