diff --git a/velox/functions/lib/DateTimeFormatter.cpp b/velox/functions/lib/DateTimeFormatter.cpp index 92d233b3f946b..f27ad3bb71415 100644 --- a/velox/functions/lib/DateTimeFormatter.cpp +++ b/velox/functions/lib/DateTimeFormatter.cpp @@ -817,6 +817,12 @@ int32_t parseFromPattern( } cur += size; } else if (curPattern.specifier == DateTimeFormatSpecifier::TIMEZONE) { + // JODA does not support parsing time zone long names, so neither do we for + // consistency. The pattern for a time zone long name is 4 or more 'z's. + VELOX_USER_CHECK_LT( + curPattern.minRepresentDigits, + 4, + "Parsing time zone long names is not supported."); auto size = parseTimezone(cur, end, date); if (size == -1) { return -1; diff --git a/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp b/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp index 530c5fffa4bf3..3695752244205 100644 --- a/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp +++ b/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp @@ -3022,6 +3022,19 @@ TEST_F(DateTimeFunctionsTest, parseDatetime) { parseDatetime( "2024-02-25+06:00:99 America/XYZ", "yyyy-MM-dd+HH:mm:99 ZZZ"), "Invalid date format: '2024-02-25+06:00:99 America/XYZ'"); + + // Test to ensure we do not support parsing time zone long names (to be + // consistent with JODA). + VELOX_ASSERT_THROW( + parseDatetime( + "2024-02-25+06:00:99 Pacific Standard Time", + "yyyy-MM-dd+HH:mm:99 zzzz"), + "Parsing time zone long names is not supported."); + VELOX_ASSERT_THROW( + parseDatetime( + "2024-02-25+06:00:99 Pacific Standard Time", + "yyyy-MM-dd+HH:mm:99 zzzzzzzzzz"), + "Parsing time zone long names is not supported."); } TEST_F(DateTimeFunctionsTest, formatDateTime) {