]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/test/posix_time/testtime_formatters.cpp
add subtree-ish sources for 12.0.3
[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 int
12 main()
13 {
14
15 using namespace boost::posix_time;
16 using namespace boost::gregorian;
17 date d1(2002,Jan,1);
18 std::string d1_string("2002-Jan-01");
19 std::string t1_string("01:02:03");
20 std::string t1_result = d1_string + " " + t1_string;
21 ptime t1(d1,time_duration(1,2,3)); //2002-Jan-1 01:02:03
22 std::cout << to_simple_string(t1) << std::endl;
23 check("simple: " + t1_result, t1_result == to_simple_string(t1));
24 std::string iso_result = "20020101T010203";
25 check("iso: " + iso_result, iso_result == to_iso_string(t1));
26 std::string iso_ext_result = "2002-01-01T01:02:03";
27 check("iso ext: " + iso_ext_result, iso_ext_result == to_iso_extended_string(t1));
28
29
30
31 #ifdef BOOST_DATE_TIME_HAS_MILLISECONDS
32
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);
38 }
39
40 #endif
41
42 #ifdef BOOST_DATE_TIME_HAS_MICROSECONDS
43
44 if (time_duration::resolution() == boost::date_time::micro) {
45 ptime t3(d1,hours(1)+minutes(2)+seconds(3)+microsec(4));
46 std::string result = to_simple_string(t3);
47 check("microsecond: "+result ,
48 std::string("2002-Jan-01 01:02:03.000004") == to_simple_string(t3));
49
50 time_duration td2 = hours(-12)+minutes(4)+seconds(2)+microsec(1);
51 // time_duration td2 = hours(-12)+minutes(4)+seconds(2)+millisec(1);
52 std::string r2 = to_simple_string(td2);
53 check("microseond neg subsecond duration: "+r2 ,
54 std::string("-11:55:57.999999") == r2);
55
56 std::string s1("-01:25:00"), s2("-00:40:00"), is1("-012500"), is2("-004000");
57 time_duration td1(-1,25,0);
58 time_duration tds2(0,-40,0);
59 check("to string: " + to_simple_string(td1), to_simple_string(td1) == s1);
60 check("to string: " + to_simple_string(tds2), to_simple_string(tds2) == s2);
61 check("to string: " + to_iso_string(td1), to_iso_string(td1) == is1);
62 check("to string: " + to_iso_string(tds2), to_iso_string(tds2) == is2);
63 }
64 #endif
65
66 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
67
68 if (time_duration::resolution() == boost::date_time::nano) {
69 ptime t2(d1,hours(12) + minutes(5) + seconds(1));
70 time_period p1(t1,t2); //last value in period is 12:05:00 1/10000 sec less than t2
71 std::string period_result("["+t1_result + "/" + d1_string + " " + "12:05:00.999999999]" );
72 check("simple: " + period_result + "==" + to_simple_string(p1), period_result == to_simple_string(p1));
73
74 ptime t3(d1,hours(1)+minutes(2)+seconds(3)+nanosec(4));
75 std::string result = to_simple_string(t3);
76 check("simple subsecond: "+result ,
77 std::string("2002-Jan-01 01:02:03.000000004") == to_simple_string(t3));
78
79
80 std::string s1("-01:25:00"), s2("-00:40:00"), is1("-012500"), is2("-004000");
81 time_duration td1(-1,25,0);
82 time_duration tds2(0,-40,0);
83 check("to string: " + to_simple_string(td1), to_simple_string(td1) == s1);
84 check("to string: " + to_simple_string(tds2), to_simple_string(tds2) == s2);
85 check("to string: " + to_iso_string(td1), to_iso_string(td1) == is1);
86 check("to string: " + to_iso_string(tds2), to_iso_string(tds2) == is2);
87
88 time_duration td2 = hours(-12)+minutes(4)+seconds(2)+nanosec(100);
89 std::string r2 = to_simple_string(td2);
90 check("neg subsecond duration: "+r2 ,
91 std::string("-11:55:57.999999900") == r2);
92
93 ptime t4(d1,hours(1)+minutes(2)+seconds(3)+millisec(4));
94 std::string r3 = to_simple_string(t4);
95 check("simple subsecond: "+r3 ,
96 std::string("2002-Jan-01 01:02:03.004000000") == r3);
97 }
98 #endif
99
100
101 return printTestStats();
102
103
104 }
105
106