Skip to content

Commit

Permalink
Fix datetime parsing for half day when hour is not specified (#8349)
Browse files Browse the repository at this point in the history
Summary:
In both Spark and Presto, half day specifier (AM or PM) takes effect even when
hour is not specified. For example, parsing ("2018-04-28 59:30PM",
"yyyy-MM-dd mm:ss a") returns the timestamp of 2018-04-28 12:59:30, but
Velox returns 2018-04-28 00:59:30, which has 12-hour difference.

Pull Request resolved: #8349

Reviewed By: xiaoxmeng

Differential Revision: D52693228

Pulled By: mbasmanova

fbshipit-source-id: 9454e4a95d64e095ed55bdece6af307029c02bf8
  • Loading branch information
PHILO-HE authored and facebook-github-bot committed Jan 11, 2024
1 parent ffe0d67 commit 265cd94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion velox/functions/lib/DateTimeFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct Date {

bool isClockHour = false; // Whether most recent hour specifier is clockhour
bool isHourOfHalfDay =
false; // Whether most recent hour specifier is of half day.
true; // Whether most recent hour specifier is of half day.

std::vector<int32_t> dayOfMonthValues;
std::vector<int32_t> dayOfYearValues;
Expand Down
11 changes: 11 additions & 0 deletions velox/functions/lib/tests/DateTimeFormatterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,17 @@ TEST_F(JodaDateTimeFormatterTest, parseHalfOfDay) {
EXPECT_EQ(
util::fromTimestampString("1970-01-01 12:00:00"),
parseJoda("1 AM 12", "h a H").timestamp);

// Half of day still has effect even though hour or clockhour is not provided.
EXPECT_EQ(
util::fromTimestampString("1970-01-01 12:00:00"),
parseJoda("PM", "a").timestamp);
EXPECT_EQ(
util::fromTimestampString("1970-01-01 12:11:11"),
parseJoda("11:11 PM", "mm:ss a").timestamp);
EXPECT_EQ(
util::fromTimestampString("2018-04-28 12:59:30"),
parseJoda("2018-04-28 59:30 PM", "yyyy-MM-dd mm:ss a").timestamp);
}

TEST_F(JodaDateTimeFormatterTest, parseMinute) {
Expand Down

0 comments on commit 265cd94

Please sign in to comment.