cloud-fan commented on a change in pull request #28576: URL: https://github.com/apache/spark/pull/28576#discussion_r427337528
########## 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: It's UT, which is whitebox testing. It's clear from the code that the time parsing is unrelated to the value of year ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org