]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/common/test_time.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / test / common / test_time.cc
index c517a61033bffc2db7bb35a09f32d22576280a85..347916114bf398d76ffd8b1545a19590d8f9a1f3 100644 (file)
@@ -18,6 +18,7 @@
 #include "common/ceph_time.h"
 #include "include/rados.h"
 #include "gtest/gtest.h"
+#include "include/stringify.h"
 
 
 using ceph::real_clock;
@@ -176,3 +177,18 @@ TEST(TimePoints, SignedSubtraciton) {
   ASSERT_GT(cmtb - cmta, ceph::signedspan::zero());
   ASSERT_GT((cmtb - cmta).count(), 0);
 }
+
+TEST(TimePoints, stringify) {
+  ceph::real_clock::time_point tp(seconds(1556122013) + nanoseconds(39923122));
+  string s = stringify(tp);
+  ASSERT_EQ(s.size(), strlen("2019-04-24T11:06:53.039923-0500"));
+  ASSERT_TRUE(s[26] == '-' || s[26] == '+');
+  ASSERT_EQ(s.substr(0, 9), "2019-04-2");
+
+  ceph::coarse_real_clock::time_point ctp(seconds(1556122013) +
+                                         nanoseconds(399000000));
+  s = stringify(ctp);
+  ASSERT_EQ(s.size(), strlen("2019-04-24T11:06:53.399000-0500"));
+  ASSERT_TRUE(s[26] == '-' || s[26] == '+');
+  ASSERT_EQ(s.substr(0, 9), "2019-04-2");
+}