]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/test_utime.cc
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / test / test_utime.cc
CommitLineData
9f95a23c
TL
1#include "include/utime.h"
2#include "gtest/gtest.h"
3#include "include/stringify.h"
4#include "common/ceph_context.h"
5
20effc67
TL
6using namespace std;
7
9f95a23c
TL
8TEST(utime_t, localtime)
9{
10 utime_t t(1556122013, 839991182);
11 string s = stringify(t);
12 cout << s << std::endl;
13 // time zone may vary where unit test is run, so be cirsumspect...
14 ASSERT_EQ(s.size(), strlen("2019-04-24T11:06:53.839991-0500"));
15 ASSERT_TRUE(s[26] == '-' || s[26] == '+');
16 ASSERT_EQ(s.substr(0, 9), "2019-04-2");
17}
18
19TEST(utime_t, gmtime)
20{
21 utime_t t(1556122013, 39991182);
22 {
23 ostringstream ss;
24 t.gmtime(ss);
25 ASSERT_EQ(ss.str(), "2019-04-24T16:06:53.039991Z");
26 }
27 {
28 ostringstream ss;
29 t.gmtime_nsec(ss);
30 ASSERT_EQ(ss.str(), "2019-04-24T16:06:53.039991182Z");
31 }
32}
33
34TEST(utime_t, asctime)
35{
36 utime_t t(1556122013, 839991182);
37 ostringstream ss;
38 t.asctime(ss);
39 string s = ss.str();
40 ASSERT_EQ(s, "Wed Apr 24 16:06:53 2019");
41}
42
43const char *v[][2] = {
44 { "2019-04-24T16:06:53.039991Z", "2019-04-24T16:06:53.039991Z" },
45 { "2019-04-24 16:06:53.039991Z", "2019-04-24T16:06:53.039991Z" },
46 { "2019-04-24 16:06:53.039991+0000", "2019-04-24T16:06:53.039991Z" },
47 { "2019-04-24 16:06:53.039991-0100", "2019-04-24T17:06:53.039991Z" },
48 { "2019-04-24 16:06:53.039991+0430", "2019-04-24T11:36:53.039991Z" },
49 { "2019-04-24 16:06:53+0000", "2019-04-24T16:06:53.000000Z" },
50 { "2019-04-24T16:06:53-0100", "2019-04-24T17:06:53.000000Z" },
51 { "2019-04-24 16:06:53+0430", "2019-04-24T11:36:53.000000Z" },
52 { "2019-04-24", "2019-04-24T00:00:00.000000Z" },
53 { 0, 0 },
54};
55
56TEST(utime_t, parse_date)
57{
58 for (unsigned i = 0; v[i][0]; ++i) {
59 cout << v[i][0] << " -> " << v[i][1] << std::endl;
60 utime_t t;
61 bool r = t.parse(string(v[i][0]));
62 ASSERT_TRUE(r);
63 ostringstream ss;
64 t.gmtime(ss);
65 ASSERT_EQ(ss.str(), v[i][1]);
66 }
67}