kiszk commented on a change in pull request #27491: [SPARK-30754][SQL] Reuse 
results of floorDiv in calculations of floorMod in DateTimeUtils
URL: https://github.com/apache/spark/pull/27491#discussion_r376968021
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
 ##########
 @@ -691,11 +691,11 @@ object DateTimeUtils {
   def truncDate(d: SQLDate, level: Int): SQLDate = {
     def truncToYearLevel(divider: Int, adjust: Int): SQLDate = {
       val oldYear = getYear(d)
-      var newYear = Math.floorDiv(oldYear, divider)
-      if (adjust > 0 && Math.floorMod(oldYear, divider) == 0) {
-        newYear -= 1
+      var newYear = Math.floorDiv(oldYear, divider) * divider
 
 Review comment:
   I see. The comment `Returns the year value for the given date. The date is 
expressed in days since 1.1.1970` in `getYear()` means that the value is 
relative based on 1.1.1970. If the year is older than 1.1.1970, the value is 
negative.

----------------------------------------------------------------
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]

Reply via email to