]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/test/posix_time/testtime_formatters.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / date_time / test / posix_time / testtime_formatters.cpp
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
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
13 int
14 main()
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
31 CHECK_ROUNDTRIP(t1);
32
33 #ifdef BOOST_DATE_TIME_HAS_MILLISECONDS
34
35 if (time_duration::resolution() == boost::date_time::milli) {
36 ptime t4(d1,hours(1)+minutes(2)+seconds(3)+millisec(4));
37 std::string r3 = to_simple_string(t4);
38 check("simple subsecond: "+r3 ,
39 std::string("2002-Jan-01 01:02:03.004000") == r3);
40 CHECK_ROUNDTRIP(t4);
41 }
42
43 #endif
44
45 #ifdef BOOST_DATE_TIME_HAS_MICROSECONDS
46
47 if (time_duration::resolution() == boost::date_time::micro) {
48 ptime t3(d1,hours(1)+minutes(2)+seconds(3)+microsec(4));
49 std::string result = to_simple_string(t3);
50 check("microsecond: "+result ,
51 std::string("2002-Jan-01 01:02:03.000004") == to_simple_string(t3));
52
53 time_duration td2 = hours(-12)+minutes(4)+seconds(2)+microsec(1);
54 // time_duration td2 = hours(-12)+minutes(4)+seconds(2)+millisec(1);
55 std::string r2 = to_simple_string(td2);
56 check("microseond neg subsecond duration: "+r2 ,
57 std::string("-11:55:57.999999") == r2);
58
59 std::string s1("-01:25:00"), s2("-00:40:00"), is1("-012500"), is2("-004000");
60 time_duration td1(-1,25,0);
61 time_duration tds2(0,-40,0);
62 check("to string: " + to_simple_string(td1), to_simple_string(td1) == s1);
63 check("to string: " + to_simple_string(tds2), to_simple_string(tds2) == s2);
64 check("to string: " + to_iso_string(td1), to_iso_string(td1) == is1);
65 check("to string: " + to_iso_string(tds2), to_iso_string(tds2) == is2);
66
67 CHECK_ROUNDTRIP(t3);
68 }
69 #endif
70
71 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
72
73 if (time_duration::resolution() == boost::date_time::nano) {
74 ptime t2(d1,hours(12) + minutes(5) + seconds(1));
75 time_period p1(t1,t2); //last value in period is 12:05:00 1/10000 sec less than t2
76 std::string period_result("["+t1_result + "/" + d1_string + " " + "12:05:00.999999999]" );
77 check("simple: " + period_result + "==" + to_simple_string(p1), period_result == to_simple_string(p1));
78
79 ptime t3(d1,hours(1)+minutes(2)+seconds(3)+nanosec(4));
80 std::string result = to_simple_string(t3);
81 check("simple subsecond: "+result ,
82 std::string("2002-Jan-01 01:02:03.000000004") == to_simple_string(t3));
83
84
85 std::string s1("-01:25:00"), s2("-00:40:00"), is1("-012500"), is2("-004000");
86 time_duration td1(-1,25,0);
87 time_duration tds2(0,-40,0);
88 check("to string: " + to_simple_string(td1), to_simple_string(td1) == s1);
89 check("to string: " + to_simple_string(tds2), to_simple_string(tds2) == s2);
90 check("to string: " + to_iso_string(td1), to_iso_string(td1) == is1);
91 check("to string: " + to_iso_string(tds2), to_iso_string(tds2) == is2);
92
93 time_duration td2 = hours(-12)+minutes(4)+seconds(2)+nanosec(100);
94 std::string r2 = to_simple_string(td2);
95 check("neg subsecond duration: "+r2 ,
96 std::string("-11:55:57.999999900") == r2);
97
98 ptime t4(d1,hours(1)+minutes(2)+seconds(3)+millisec(4));
99 std::string r3 = to_simple_string(t4);
100 check("simple subsecond: "+r3 ,
101 std::string("2002-Jan-01 01:02:03.004000000") == r3);
102
103 CHECK_ROUNDTRIP(t3);
104 }
105 #endif
106
107 // Boost Trac 1078 (https://svn.boost.org/trac10/ticket/1078)
108 // from_iso_string should be able to parse output of to_iso_string
109 CHECK_ROUNDTRIP(ptime());
110 CHECK_ROUNDTRIP(ptime(not_a_date_time)); // should be same as previous
111 CHECK_ROUNDTRIP(ptime(pos_infin));
112 CHECK_ROUNDTRIP(ptime(neg_infin));
113
114 // when min_date_time is formatted out, it is done so as an actual date/time
115 // i.e. it is not "special" in that sense
116 check_equal("from_iso_string(\"minimum-date-time\")", from_iso_string("minimum-date-time"), ptime(min_date_time));
117 check_equal("from_iso_string(\"maximum-date-time\")", from_iso_string("maximum-date-time"), ptime(max_date_time));
118
119 return printTestStats();
120 }
121
122