]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/test_utime.cc
1 #include "include/utime.h"
2 #include "gtest/gtest.h"
3 #include "include/stringify.h"
4 #include "common/ceph_context.h"
6 TEST(utime_t
, localtime
)
8 utime_t
t(1556122013, 839991182);
9 string s
= stringify(t
);
10 cout
<< s
<< std::endl
;
11 // time zone may vary where unit test is run, so be cirsumspect...
12 ASSERT_EQ(s
.size(), strlen("2019-04-24T11:06:53.839991-0500"));
13 ASSERT_TRUE(s
[26] == '-' || s
[26] == '+');
14 ASSERT_EQ(s
.substr(0, 9), "2019-04-2");
19 utime_t
t(1556122013, 39991182);
23 ASSERT_EQ(ss
.str(), "2019-04-24T16:06:53.039991Z");
28 ASSERT_EQ(ss
.str(), "2019-04-24T16:06:53.039991182Z");
32 TEST(utime_t
, asctime
)
34 utime_t
t(1556122013, 839991182);
38 ASSERT_EQ(s
, "Wed Apr 24 16:06:53 2019");
41 const char *v
[][2] = {
42 { "2019-04-24T16:06:53.039991Z", "2019-04-24T16:06:53.039991Z" },
43 { "2019-04-24 16:06:53.039991Z", "2019-04-24T16:06:53.039991Z" },
44 { "2019-04-24 16:06:53.039991+0000", "2019-04-24T16:06:53.039991Z" },
45 { "2019-04-24 16:06:53.039991-0100", "2019-04-24T17:06:53.039991Z" },
46 { "2019-04-24 16:06:53.039991+0430", "2019-04-24T11:36:53.039991Z" },
47 { "2019-04-24 16:06:53+0000", "2019-04-24T16:06:53.000000Z" },
48 { "2019-04-24T16:06:53-0100", "2019-04-24T17:06:53.000000Z" },
49 { "2019-04-24 16:06:53+0430", "2019-04-24T11:36:53.000000Z" },
50 { "2019-04-24", "2019-04-24T00:00:00.000000Z" },
54 TEST(utime_t
, parse_date
)
56 for (unsigned i
= 0; v
[i
][0]; ++i
) {
57 cout
<< v
[i
][0] << " -> " << v
[i
][1] << std::endl
;
59 bool r
= t
.parse(string(v
[i
][0]));
63 ASSERT_EQ(ss
.str(), v
[i
][1]);