Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/6983#discussion_r66847192
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala
---
@@ -48,4 +49,41 @@ class DateTimeUtilsSuite extends SparkFunSuite {
val t2 = DateTimeUtils.toJavaTimestamp(DateTimeUtils.fromJulianDay(d1,
ns1))
assert(t.equals(t2))
}
+
+ test("SPARK-6785: java date conversion before and after epoch") {
+ def checkFromToJavaDate(d1: Date): Unit = {
+ val d2 = DateTimeUtils.toJavaDate(DateTimeUtils.fromJavaDate(d1))
+ assert(d2.toString === d1.toString)
--- End diff --
Per the
[Javadoc](https://docs.oracle.com/javase/6/docs/api/java/sql/Date.html) for
`java.sql.Date`:
> To conform with the definition of SQL DATE, the millisecond values
wrapped by a java.sql.Date instance must be 'normalized' by setting the hours,
minutes, seconds, and milliseconds to zero in the particular time zone with
which the instance is associated.
Given this, I'd assume that the value returned by
`Date.valueOf("1970-01-01").getTime` is the canonical timestamp value for the
date "1970-01-01" in the caller's JVM and that a roundtrip conversion would
therefore return that exact timestamp.
For `new Date(df1.parse("1970-01-01 00:00:01").getTime)`, on the other
hand, I think that the timestamp isn't normalized and thus I'm not sure that
this is considered a "valid" `java.sql.Date` instance.
Basically I'm assuming that there'd only be one canonical `java.sql.Date`
representation for a given date within a single JVM.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]