Github user tarekauel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6981#discussion_r34868858
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
 ---
    @@ -378,4 +395,183 @@ object DateTimeUtils {
         c.set(segments(0), segments(1) - 1, segments(2), 0, 0, 0)
         Some((c.getTimeInMillis / 1000 / 3600 / 24).toInt)
       }
    +
    +  /**
    +   * Returns the hour value of a given timestamp value. The timestamp is 
expressed in microseconds.
    +   */
    +  def getHours(timestamp: Long): Int = {
    +    val localTs = (timestamp / 1000) + defaultTimeZone.getOffset(timestamp 
/ 1000)
    +    ((localTs / 1000 / 3600) % 24).toInt
    +  }
    +
    +  /**
    +   * Returns the minute value of a given timestamp value. The timestamp is 
expressed in
    +   * microseconds.
    +   */
    +  def getMinutes(timestamp: Long): Int = {
    +    val localTs = (timestamp / 1000) + defaultTimeZone.getOffset(timestamp 
/ 1000)
    +    ((localTs / 1000 / 60) % 60).toInt
    +  }
    +
    +  /**
    +   * Returns the second value of a given timestamp value. The timestamp is 
expressed in
    +   * microseconds.
    +   */
    +  def getSeconds(timestamp: Long): Int = {
    +    val localTs = (timestamp / 1000) + defaultTimeZone.getOffset(timestamp 
/ 1000)
    +    ((localTs / 1000) % 60).toInt
    +  }
    +
    +  private[this] def isLeapYear(year: Int): Boolean = {
    +    (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)
    +  }
    +
    +  /**
    +   * Return the number of days since the start of 400 year period.
    +   * The second year of a 400 year period (year 1) starts on day 365.
    +   */
    +  private[this] def yearBoundary(year: Int): Int = {
    +    year * 365 + ((year / 4 ) - (year / 100) + (year / 400))
    +  }
    +
    +  /**
    +   * Calculates the number of years for the given number of days. This 
depends
    +   * on a 400 year period.
    +   * @param days days since the beginning of the 400 year period
    +   * @return number of year
    +   */
    +  private[this] def numYears(days: Int): Int = {
    --- End diff --
    
    Sorry I'm not sure if I got it correct. I should return
    ```
    val boundary = yearBoundary(year)
    if (days > boundary) (year, boundary) else (year - 1, yearBoundary(year - 
1))
    ```
    In order to avoid the call of `yearBoundary` in line the line `val 
dayInYear = daysInThis400 - yearBoundary(years)`. That was your proposal, 
wasn't it?


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

Reply via email to