Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
NEUpanning committed Mar 3, 2025
1 parent 688d231 commit 2145ac5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions velox/functions/lib/DateTimeFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,8 @@ int32_t parseFromPattern(
++cur;
++count;
}
// If the number of digits is less than 3, a simple formatter interprets
// it as the whole number; otherwise, it pads the number with zeros.
if (type != DateTimeFormatterType::STRICT_SIMPLE &&
type != DateTimeFormatterType::LENIENT_SIMPLE) {
number *= std::pow(10, 3 - count);
Expand Down
5 changes: 5 additions & 0 deletions velox/functions/sparksql/tests/DateTimeFunctionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ TEST_F(DateTimeFunctionsTest, getTimestamp) {
EXPECT_EQ(
getTimestamp("1970-01-01 00:00:00.010", "yyyy-MM-dd HH:mm:ss.SSS"),
Timestamp::fromMillis(10));
// Representing milliseconds with one digit.
EXPECT_EQ(
getTimestamp("1970-01-01 00:00:00.2", "yyyy-MM-dd HH:mm:ss.SSS"),
Timestamp::fromMillis(200));
auto milliSeconds = (6 * 60 * 60 + 10 * 60 + 59) * 1000 + 19;
EXPECT_EQ(
getTimestamp("1970-01-01 06:10:59.019", "yyyy-MM-dd HH:mm:ss.SSS"),
Expand Down Expand Up @@ -856,6 +860,7 @@ TEST_F(DateTimeFunctionsTest, getTimestamp) {
// Unsupported specifier.
EXPECT_EQ(getTimestamp("0", "l"), std::nullopt);

// Representing milliseconds with one digit.
EXPECT_EQ(
getTimestamp("1970-01-01 00:00:00.2", "yyyy-MM-dd HH:mm:ss.SSS"),
Timestamp::fromMillis(2));
Expand Down

0 comments on commit 2145ac5

Please sign in to comment.