diff options
-rw-r--r-- | src/mongo/unittest/unittest_helpers.cpp | 5 | ||||
-rw-r--r-- | src/mongo/unittest/unittest_helpers.h | 2 | ||||
-rw-r--r-- | src/mongo/util/time_support.h | 5 | ||||
-rw-r--r-- | src/mongo/util/time_support_test.cpp | 18 |
4 files changed, 23 insertions, 7 deletions
diff --git a/src/mongo/unittest/unittest_helpers.cpp b/src/mongo/unittest/unittest_helpers.cpp index 0ae120f0581..450a1b2146e 100644 --- a/src/mongo/unittest/unittest_helpers.cpp +++ b/src/mongo/unittest/unittest_helpers.cpp @@ -41,9 +41,4 @@ std::ostream& operator<<(std::ostream& s, const Timestamp& ot) { s << ot.toString(); return s; } - -std::ostream& operator<<(std::ostream& s, const Date_t& t) { - s << t.toString(); - return s; -} } diff --git a/src/mongo/unittest/unittest_helpers.h b/src/mongo/unittest/unittest_helpers.h index 0a90ec0cec1..c02d2c35853 100644 --- a/src/mongo/unittest/unittest_helpers.h +++ b/src/mongo/unittest/unittest_helpers.h @@ -37,7 +37,5 @@ class Date_t; // So that you can ASSERT_EQUALS two Timestamps std::ostream& operator<<(std::ostream& s, const Timestamp& ot); -// So that you can ASSERT_EQUALS two Date_ts -std::ostream& operator<<(std::ostream& s, const Date_t& t); } // namespace mongo diff --git a/src/mongo/util/time_support.h b/src/mongo/util/time_support.h index 203001e58fa..d9c1821dd3f 100644 --- a/src/mongo/util/time_support.h +++ b/src/mongo/util/time_support.h @@ -219,6 +219,11 @@ public: return !(*this < other); } + friend std::ostream& operator<<(std::ostream& out, const Date_t& date) { + out << date.toString(); + return out; + } + private: constexpr explicit Date_t(long long m) : millis(m) {} diff --git a/src/mongo/util/time_support_test.cpp b/src/mongo/util/time_support_test.cpp index 24052f3f147..0d7f6b875b9 100644 --- a/src/mongo/util/time_support_test.cpp +++ b/src/mongo/util/time_support_test.cpp @@ -820,6 +820,24 @@ TEST(TimeFormatting, DurationFormatting) { ASSERT_EQUALS("52ms52\xce\xbcs52s", os.str()); } +TEST(TimeFormatting, WriteToStream) { + const std::vector<std::string> dateStrings = { + "1996-04-07T00:00:00.000Z", + "1996-05-02T00:00:00.000Z", + "1997-06-23T07:55:00.000Z", + "2015-05-14T17:28:33.123Z", + "2036-02-29T00:00:00.000Z", + }; + + for (const std::string& isoTimeString : dateStrings) { + const Date_t aDate = unittest::assertGet(dateFromISOString(isoTimeString)); + std::ostringstream testStream; + testStream << aDate; + std::string streamOut = testStream.str(); + ASSERT_EQUALS(aDate.toString(), streamOut); + } +} + TEST(SystemTime, ConvertDateToSystemTime) { const std::string isoTimeString = "2015-05-14T17:28:33.123Z"; const Date_t aDate = unittest::assertGet(dateFromISOString(isoTimeString)); |