MaxGekk commented on a change in pull request #25708: [SPARK-28141][SQL] Support special date values URL: https://github.com/apache/spark/pull/25708#discussion_r322001846
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala ########## @@ -848,4 +852,40 @@ object DateTimeUtils { val sinceEpoch = BigDecimal(timestamp) / MICROS_PER_SECOND + offset new Decimal().set(sinceEpoch, 20, 6) } + + def currentDate(zoneId: ZoneId): SQLDate = localDateToDays(LocalDate.now(zoneId)) + + private val specialDate = """(EPOCH|NOW|TODAY|TOMORROW|YESTERDAY)\p{Blank}*(.*)""".r + /** + * Converts notational shorthands that are converted to ordinary dates. + * @param input - left trimmed string + * @param zoneId - zone identifier used to get the current date. + * @return some of days since the epoch if the conversion completed successfully otherwise None. + */ + def convertSpecialDate(input: String, zoneId: ZoneId): Option[SQLDate] = { + def isValidZoneId(z: String): Boolean = { + z == "" || Try { getZoneId(z) }.isSuccess Review comment: I don't think the reasons from the style guide are applicable here. And code looks slightly ugly. Maybe you have better implementation than: ```scala def isValidZoneId(z: String): Boolean = { if (z == "") return true try { getZoneId(z) true } catch { case NonFatal(_) => false } } ``` ---------------------------------------------------------------- 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 With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org