There is an issue with DateTimeUtils.daysToMillis implementation. It affects DateTimeUtils.toJavaDate and ultimately CatalystTypeConverter, i.e the conversion of date stored as Int days from epoch in InternalRow to java.sql.Date of Row returned to user.
The issue can be reproduced with this test (all the following tests are in my defalut timezone Europe/Moscow):
For example, for 4108 day of epoch, the correct date should be 1981-04-01
There was previous unsuccessful attempt to work around the problem in
SPARK-11415. It seems that issue involves flaws in java date implementation and I don't see how it can be fixed without third-party libraries.
I was not able to identify the library of choice for Spark. The following implementation uses JSR-310
that produces correct results: