]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/test/local_time/testlocal_time_period.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / date_time / test / local_time / testlocal_time_period.cpp
1 /* Copyright (c) 2005 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
6 */
7
8 #include "boost/date_time/local_time/local_time.hpp"
9 #include "../testfrmwk.hpp"
10
11 int main()
12 {
13 using namespace boost::gregorian;
14 using namespace boost::posix_time;
15 using namespace boost::local_time;
16 date d1(2001,Jan, 1);
17
18 time_zone_ptr az_tz(new posix_time_zone("MST-07"));
19
20 local_date_time t1 (d1,hours(2), az_tz, false);//2001-Jan-1 02:00:00
21
22 local_date_time t2 (d1,hours(3), az_tz, false);//2001-Jan-1 03:00:00
23 local_time_period p1(t1,t2); //2001-Jan-1 02:59:59
24 local_time_period p2(p1);
25 check("copy construct & ==", p1 == p2);
26 local_time_period p3 = p2;
27 check("assignment", p3 == p2);
28 local_time_period p4(t1,hours(1));
29
30 check("length", p4.length() == hours(1));
31
32 // std::cout << to_simple_string(t1) << std::endl;
33 // std::cout << to_simple_string(p4) << std::endl;
34 // std::cout << to_simple_string(p1) << std::endl;
35 check("construction and ==", p1 == p4);
36 check("begin", p1.begin() == t1);
37 check("last", p1.end() == t2);
38 check("end", p1.last() == t2-time_duration::unit());
39
40 // std::cout << to_simple_string(p1) << std::endl;
41 // // check("last", p1.() == t2);
42 check("contains begin", p1.contains(t1));
43 check("contains end-not", !p1.contains(t2));
44 check("contains last", p1.contains(t2-seconds(1)));
45 local_date_time t3(date(2001,Jan,1),hours(4), az_tz, false);
46 local_time_period p5(t2,t3);
47 check("check contains", !p1.contains(p5.begin()));
48 check("check contains", !p5.contains(p1.begin()));
49 check("operator== not equal case", !(p1 == p5));
50 check("less than order", p1 < p5);
51 check("greater than order", p5 > p1);
52 check("not equal", p5 != p1);
53 check("intersects with myself", p1.intersects(p1));
54 check("not intersects", !(p1.intersects(p5)));
55 check("not intersects", !(p5.intersects(p1)));
56
57 local_time_period p6(p5);
58 p6.shift(minutes(30));
59 // std::cout << to_simple_string(p5) << std::endl;
60 // std::cout << to_simple_string(p6) << std::endl;
61 check("shifted intersects", p5.intersects(p6));
62 check("shifted intersects", p6.intersects(p5));
63 check("contains begin", p5.contains(p6.begin()));
64 p6.shift(minutes(30));
65 // std::cout << to_simple_string(p5) << std::endl;
66 // std::cout << to_simple_string(p6) << std::endl;
67 check("shifted !intersects", !p5.intersects(p6));
68 check("shifted !intersects", !p6.intersects(p5));
69 p6.shift(minutes(-30));
70 // std::cout << to_simple_string(p5) << std::endl;
71 // std::cout << to_simple_string(p6) << std::endl;
72 local_time_period p7 = p5.intersection(p6);
73 // std::cout << to_simple_string(p7) << std::endl;
74 check("shifted intersection",
75 p7 == local_time_period(local_date_time(d1,time_duration(3,30,0), az_tz, false),
76 local_date_time(d1,time_duration(4,0,0), az_tz, false)));
77
78
79 return printTestStats();
80
81 }
82