Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cpp/src/arrow/util/value_parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ static inline bool ParseTimestampStrptime(const char* buf, size_t length,
arrow_vendored::date::sys_days(arrow_vendored::date::year(result.tm_year + 1900) /
(result.tm_mon + 1) / std::max(result.tm_mday, 1));
if (!ignore_time_in_day) {
// Reject leap seconds, which Arrow cannot represent, instead of adding them
// to the time of day (which wraps them into the next minute); consistent
// with the ISO-8601 parser.
if (result.tm_sec >= 60) {
return false;
}
secs += (std::chrono::hours(result.tm_hour) + std::chrono::minutes(result.tm_min) +
std::chrono::seconds(result.tm_sec));
#if !defined(_WIN32) && !defined(_AIX)
Expand Down
6 changes: 5 additions & 1 deletion cpp/src/arrow/util/value_parsing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,11 @@ TEST(TimestampParser, StrptimeParser) {
}

// Unparseable strings
std::vector<std::string> unparseables = {"foo", "5/1/2000", "5/1/2000 12:34:56:6"};
std::vector<std::string> unparseables = {"foo", "5/1/2000", "5/1/2000 12:34:56:6",
// Leap seconds are rejected, as by the
// ISO-8601 parser
"5/31/2000 12:30:60", "5/31/2000 23:59:60",
"5/31/2000 23:59:61"};
for (auto& value : unparseables) {
int64_t dummy;
ASSERT_FALSE((*parser)(value.c_str(), value.size(), TimeUnit::SECOND, &dummy));
Expand Down
9 changes: 9 additions & 0 deletions cpp/src/gandiva/to_date_holder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ TEST_F(TestToDateHolder, TestSimpleDateTime) {
millis_since_epoch =
to_date(&execution_context_, s.data(), (int)s.length(), true, &out_valid);
EXPECT_EQ(millis_since_epoch, 534643200000);

// A leap second does not make the value invalid, as the time is ignored
EXPECT_OK_AND_ASSIGN(auto to_date_holder24,
ToDateHolder::Make("YYYY-MM-DD HH24:MI:SS", 1));
s = std::string("2020-12-31 23:59:60");
millis_since_epoch = (*to_date_holder24)(&execution_context_, s.data(), (int)s.length(),
true, &out_valid);
EXPECT_TRUE(out_valid);
EXPECT_EQ(millis_since_epoch, 1609372800000);
}

TEST_F(TestToDateHolder, TestSimpleDate) {
Expand Down
Loading