]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/date_time/test/posix_time/testtime_formatters.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / date_time / test / posix_time / testtime_formatters.cpp
CommitLineData
7c673cae
FG
1/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
2 * Use, modification and distribution is subject to the
3 * Boost Software License, Version 1.0. (See accompanying
4 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5 * Author: Jeff Garland, Bart Garst
6 */
7
8#include "boost/date_time/posix_time/posix_time.hpp"
9#include "../testfrmwk.hpp"
10
11fdf7f2
TL
11#define CHECK_ROUNDTRIP(_PT) check_equal("from_iso_string(to_iso_string()) roundtrip of \"" + to_iso_string(_PT) + "\"", from_iso_string(to_iso_string(_PT)), _PT)
12
7c673cae
FG
13int
14main()
15{
16
17 using namespace boost::posix_time;
18 using namespace boost::gregorian;
19 date d1(2002,Jan,1);
20 std::string d1_string("2002-Jan-01");
21 std::string t1_string("01:02:03");
22 std::string t1_result = d1_string + " " + t1_string;
23 ptime t1(d1,time_duration(1,2,3)); //2002-Jan-1 01:02:03
24 std::cout << to_simple_string(t1) << std::endl;
25 check("simple: " + t1_result, t1_result == to_simple_string(t1));
26 std::string iso_result = "20020101T010203";
27 check("iso: " + iso_result, iso_result == to_iso_string(t1));
28 std::string iso_ext_result = "2002-01-01T01:02:03";
29 check("iso ext: " + iso_ext_result, iso_ext_result == to_iso_extended_string(t1));
30
11fdf7f2 31 CHECK_ROUNDTRIP(t1);
7c673cae 32
7c673cae
FG
33 if (time_duration::resolution() == boost::date_time::milli) {
34 ptime t4(d1,hours(1)+minutes(2)+seconds(3)+millisec(4));
35 std::string r3 = to_simple_string(t4);
36 check("simple subsecond: "+r3 ,
37 std::string("2002-Jan-01 01:02:03.004000") == r3);
11fdf7f2 38 CHECK_ROUNDTRIP(t4);
7c673cae
FG
39 }
40
7c673cae
FG
41
42 if (time_duration::resolution() == boost::date_time::micro) {
43 ptime t3(d1,hours(1)+minutes(2)+seconds(3)+microsec(4));
44 std::string result = to_simple_string(t3);
45 check("microsecond: "+result ,
46 std::string("2002-Jan-01 01:02:03.000004") == to_simple_string(t3));
47
48 time_duration td2 = hours(-12)+minutes(4)+seconds(2)+microsec(1);
49 // time_duration td2 = hours(-12)+minutes(4)+seconds(2)+millisec(1);
50 std::string r2 = to_simple_string(td2);
51 check("microseond neg subsecond duration: "+r2 ,
52 std::string("-11:55:57.999999") == r2);
53
54 std::string s1("-01:25:00"), s2("-00:40:00"), is1("-012500"), is2("-004000");
55 time_duration td1(-1,25,0);
56 time_duration tds2(0,-40,0);
57 check("to string: " + to_simple_string(td1), to_simple_string(td1) == s1);
58 check("to string: " + to_simple_string(tds2), to_simple_string(tds2) == s2);
59 check("to string: " + to_iso_string(td1), to_iso_string(td1) == is1);
60 check("to string: " + to_iso_string(tds2), to_iso_string(tds2) == is2);
11fdf7f2
TL
61
62 CHECK_ROUNDTRIP(t3);
7c673cae 63 }
7c673cae 64
f67539c2 65
7c673cae
FG
66
67 if (time_duration::resolution() == boost::date_time::nano) {
68 ptime t2(d1,hours(12) + minutes(5) + seconds(1));
69 time_period p1(t1,t2); //last value in period is 12:05:00 1/10000 sec less than t2
70 std::string period_result("["+t1_result + "/" + d1_string + " " + "12:05:00.999999999]" );
71 check("simple: " + period_result + "==" + to_simple_string(p1), period_result == to_simple_string(p1));
72
73 ptime t3(d1,hours(1)+minutes(2)+seconds(3)+nanosec(4));
74 std::string result = to_simple_string(t3);
75 check("simple subsecond: "+result ,
76 std::string("2002-Jan-01 01:02:03.000000004") == to_simple_string(t3));
77
78
79 std::string s1("-01:25:00"), s2("-00:40:00"), is1("-012500"), is2("-004000");
80 time_duration td1(-1,25,0);
81 time_duration tds2(0,-40,0);
82 check("to string: " + to_simple_string(td1), to_simple_string(td1) == s1);
83 check("to string: " + to_simple_string(tds2), to_simple_string(tds2) == s2);
84 check("to string: " + to_iso_string(td1), to_iso_string(td1) == is1);
85 check("to string: " + to_iso_string(tds2), to_iso_string(tds2) == is2);
86
87 time_duration td2 = hours(-12)+minutes(4)+seconds(2)+nanosec(100);
88 std::string r2 = to_simple_string(td2);
89 check("neg subsecond duration: "+r2 ,
90 std::string("-11:55:57.999999900") == r2);
91
92 ptime t4(d1,hours(1)+minutes(2)+seconds(3)+millisec(4));
93 std::string r3 = to_simple_string(t4);
94 check("simple subsecond: "+r3 ,
95 std::string("2002-Jan-01 01:02:03.004000000") == r3);
11fdf7f2
TL
96
97 CHECK_ROUNDTRIP(t3);
98}
f67539c2 99
7c673cae 100
11fdf7f2
TL
101 // Boost Trac 1078 (https://svn.boost.org/trac10/ticket/1078)
102 // from_iso_string should be able to parse output of to_iso_string
103 CHECK_ROUNDTRIP(ptime());
104 CHECK_ROUNDTRIP(ptime(not_a_date_time)); // should be same as previous
105 CHECK_ROUNDTRIP(ptime(pos_infin));
106 CHECK_ROUNDTRIP(ptime(neg_infin));
107
108 // when min_date_time is formatted out, it is done so as an actual date/time
109 // i.e. it is not "special" in that sense
110 check_equal("from_iso_string(\"minimum-date-time\")", from_iso_string("minimum-date-time"), ptime(min_date_time));
111 check_equal("from_iso_string(\"maximum-date-time\")", from_iso_string("maximum-date-time"), ptime(max_date_time));
7c673cae
FG
112
113 return printTestStats();
7c673cae
FG
114}
115
116