MaxGekk commented on a change in pull request #28576:
URL: https://github.com/apache/spark/pull/28576#discussion_r427140383



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/util/TimestampFormatterSuite.scala
##########
@@ -291,4 +291,95 @@ class TimestampFormatterSuite extends SparkFunSuite with 
SQLHelper with Matchers
       }
     }
   }
+
+  test("parsing hour with various patterns") {
+    def createFormatter(pattern: String): TimestampFormatter = {
+      // Use `SIMPLE_DATE_FORMAT`, so that the legacy parser also fails with 
invalid value range.
+      TimestampFormatter(pattern, ZoneOffset.UTC, 
LegacyDateFormats.SIMPLE_DATE_FORMAT, false)
+    }
+
+    withClue("HH") {
+      val formatter = createFormatter("yyyy-MM-dd HH")
+
+      val micros1 = formatter.parse("2009-12-12 00")
+      assert(micros1 === TimeUnit.SECONDS.toMicros(
+        LocalDateTime.of(2009, 12, 12, 0, 0, 0).toEpochSecond(ZoneOffset.UTC)))
+
+      val micros2 = formatter.parse("2009-12-12 15")
+      assert(micros2 === TimeUnit.SECONDS.toMicros(
+        LocalDateTime.of(2009, 12, 12, 15, 0, 
0).toEpochSecond(ZoneOffset.UTC)))

Review comment:
       I would propose to improve test coverage and test different years -100, 
0001, 1582, 1900, 1970, 2037, 2100 instead of checking only one year in all 
tests




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to