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

    https://github.com/apache/spark/pull/16308#discussion_r97482071
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DateFunctionsSuite.scala ---
    @@ -103,6 +153,51 @@ class DateFunctionsSuite extends QueryTest with 
SharedSQLContext {
           Row("2015", "2015", "2013"))
       }
     
    +  test("date format with session local timezone") {
    +    val df = Seq((d, sdf.format(d), ts)).toDF("a", "b", "c")
    +
    +    // The child of date_format is implicitly casted to TimestampType with 
session local timezone.
    +    //
    +    // +---+---------------------+-------------+---------------------+
    +    // |   | df                  | timestamp   | date_format         |
    +    // +---+---------------------+-------------+---------------------+
    +    // | a |                16533|1428476400000|"2015-04-08 00:00:00"|
    +    // | b |"2015-04-08 13:10:15"|1428523815000|"2015-04-08 13:10:15"|
    --- End diff --
    
    Do you mean you are wondering why `sdf.format(d)` has the time info 
`13:10:15` ?
    
    If so, `java.sql.Date` DOES have the time info if it was initialized with 
the constructor `Date(long date)` or even if it was initalized with the 
constructor `Date(int year, int month, int day)` or with `Date.valueOf(String 
s)`, it has the time info `00:00:00` of the day in the timezone 
`TimeZone.getDefault()`.
    
    ```scala
    scala> TimeZone.setDefault(TimeZone.getTimeZone("GMT"))
    
    scala> val gmtDate = Date.valueOf("2017-01-24")
    gmtDate: java.sql.Date = 2017-01-24
    
    scala> val gmtTime = gmtDate.getTime
    gmtTime: Long = 1485216000000
    
    scala> TimeZone.setDefault(TimeZone.getTimeZone("PST"))
    
    scala> val pstDate = Date.valueOf("2017-01-24")
    pstDate: java.sql.Date = 2017-01-24
    
    scala> val pstTime = pstDate.getTime
    pstTime: Long = 1485244800000
    
    scala> val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    sdf: java.text.SimpleDateFormat = java.text.SimpleDateFormat@4f76f1a0
    
    scala> sdf.setTimeZone(TimeZone.getTimeZone("GMT"))
    
    scala> sdf.format(gmtTime)
    res12: String = 2017-01-24 00:00:00
    
    scala> sdf.format(pstTime)
    res13: String = 2017-01-24 08:00:00
    
    scala> val d = new Date(sdf.parse("2015-04-08 13:10:15").getTime)
    d: java.sql.Date = 2015-04-08
    
    scala> sdf.format(d)
    res14: String = 2015-04-08 13:10:15
    ```



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to