Skip to content

Commit

Permalink
Fix duration to string. (#3608)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and Sophie-Xie authored Dec 31, 2021
1 parent 1339554 commit 0ab305d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
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);
}

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

0 comments on commit 0ab305d

Please sign in to comment.