Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Add more datetime literal format. (#589)
Browse files Browse the repository at this point in the history
Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and yixinglu committed Jul 26, 2021
1 parent c3d7959 commit 3b15cac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/common/time/TimeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <iomanip>
#include <limits>
#include <sstream>
#include <vector>

#include "common/base/Status.h"
Expand Down Expand Up @@ -50,7 +51,11 @@ class TimeUtils {
std::istringstream ss(str);
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%S");
if (ss.fail()) {
return Status::Error();
std::istringstream ss2(str);
ss2 >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
if (ss2.fail()) {
return Status::Error();
}
}
DateTime dt;
dt.year = tm.tm_year + 1900;
Expand Down
14 changes: 14 additions & 0 deletions src/common/time/test/TimeUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ TEST(Time, TimezoneShift) {
}
}

TEST(Time, Parse) {
// datetime
{
auto result = time::TimeUtils::parseDateTime("2019-03-04 22:00:30");
ASSERT_TRUE(result.ok());
EXPECT_EQ(result.value(), DateTime(2019, 3, 4, 22, 0, 30, 0));
}
{
auto result = time::TimeUtils::parseDateTime("2019-03-04T22:00:30");
ASSERT_TRUE(result.ok());
EXPECT_EQ(result.value(), DateTime(2019, 3, 4, 22, 0, 30, 0));
}
}

} // namespace nebula

int main(int argc, char **argv) {
Expand Down

0 comments on commit 3b15cac

Please sign in to comment.