cloud-fan commented on a change in pull request #27915: [WIP][SPARK-31159][SQL]
Rebase date/timestamp from/to Julian calendar in parquet
URL: https://github.com/apache/spark/pull/27915#discussion_r392929992
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -974,4 +974,102 @@ object DateTimeUtils {
}
}.mkString("'")
}
+
+ /**
+ * Converts the given microseconds to a local date-time in UTC time zone in
Proleptic Gregorian
+ * calendar, interprets the result as a local date-time in Julian calendar
in UTC time zone.
+ * And takes microseconds since the epoch from the Julian timestamp.
+ *
+ * @param micros The number of microseconds since the epoch
'1970-01-01T00:00:00Z'.
+ * @return The rebased microseconds since the epoch in Julian calendar.
+ */
+ def rebaseGregorianToJulianMicros(micros: Long): Long = {
+ val ldt =
microsToInstant(micros).atZone(ZoneId.systemDefault).toLocalDateTime
+ val utcCal = new Calendar.Builder()
+ // `gregory` is a hybrid calendar that supports both
+ // the Julian and Gregorian calendar systems
+ .setCalendarType("gregory")
+ .setDate(ldt.getYear, ldt.getMonthValue - 1, ldt.getDayOfMonth)
+ .setTimeOfDay(ldt.getHour, ldt.getMinute, ldt.getSecond)
+ .build()
+ millisToMicros(utcCal.getTimeInMillis) +
ldt.get(ChronoField.MICRO_OF_SECOND)
+ }
+
+ /**
+ * Converts the given microseconds to a local date-time in UTC time zone in
Julian calendar,
+ * interprets the result as a local date-time in Proleptic Gregorian
calendar in UTC time zone.
+ * And takes microseconds since the epoch from the Gregorian timestamp.
+ *
+ * @param micros The number of microseconds since the epoch
'1970-01-01T00:00:00Z'.
+ * @return The rebased microseconds since the epoch in Proleptic Gregorian
calendar.
+ */
+ def rebaseJulianToGregorianMicros(micros: Long): Long = {
+ val utcCal = new Calendar.Builder()
Review comment:
shall we set timezone of it?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]