Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duration to string. #3608

Merged
merged 3 commits into from
Dec 31, 2021
Merged
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: 2 additions & 4 deletions src/common/datatypes/Duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ struct Duration {
}

std::string toString() const {
std::stringstream ss;
ss << "P" << months << "M" << days() << "D"
<< "T" << seconds << "S";
return ss.str();
return folly::sformat(
"P{}MT{}.{:0>6}000S", months, seconds + microseconds / 1000000, microseconds % 1000000);
Nicole00 marked this conversation as resolved.
Show resolved Hide resolved
}

folly::dynamic toJson() const {
Expand Down
21 changes: 21 additions & 0 deletions src/common/datatypes/test/ValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,27 @@ TEST(Value, Ctor) {
// Value v2(&tmp);
}

TEST(Value, ToString) {
{
Duration d;
d.addYears(1);
d.addMonths(2);
d.addDays(500);
d.addSeconds(10);
d.addMicroseconds(20);
EXPECT_EQ(d.toString(), "P14MT43200010.000020000S");
}
{
Duration d;
d.addYears(1);
d.addMonths(2);
d.addDays(500);
d.addSeconds(10);
d.addMicroseconds(20000000);
EXPECT_EQ(d.toString(), "P14MT43200030.000000000S");
}
}

} // namespace nebula

int main(int argc, char** argv) {
Expand Down
4 changes: 2 additions & 2 deletions src/storage/test/GetNeighborsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,8 @@ TEST(GetNeighborsTest, TtlTest) {
LOG(INFO) << "colName: " << s;
}
ASSERT_EQ("Tim Duncan", (*resp.vertices_ref()).rows[0].values[0].getStr());
ASSERT_TRUE((*resp.vertices_ref()).rows[0].values[1].empty()); // stat
ASSERT_TRUE((*resp.vertices_ref()).rows[0].values[2].empty()); // expr
ASSERT_TRUE((*resp.vertices_ref()).rows[0].values[1].empty()); // stat
ASSERT_TRUE((*resp.vertices_ref()).rows[0].values[2].empty()); // expr
}
FLAGS_mock_ttl_col = false;
}
Expand Down