• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6  */
7 
8 #include <iostream>
9 #include "boost/date_time/posix_time/posix_time.hpp"
10 #include "boost/date_time/posix_time/time_period.hpp"
11 #include "../testfrmwk.hpp"
12 
main()13 int main()
14 {
15   using namespace boost::gregorian;
16   using namespace boost::posix_time;
17   date d1(2001,Jan, 1);
18   ptime t1 (d1,hours(2));//2001-Jan-1 02:00:00
19   ptime t2 (d1,hours(3));//2001-Jan-1 03:00:00
20   time_period p1(t1,t2); //2001-Jan-1 02:59:59
21   time_period p2(p1);
22   check("copy construct & ==", p1 == p2);
23   time_period p3 = p2;
24   check("assignment", p3 == p2);
25   time_period p4(t1,hours(1));
26   check("length", p4.length() == hours(1));
27   std::cout << t1 << std::endl;
28   std::cout << p4 << std::endl;
29   std::cout << p1 << std::endl;
30   check("construction and ==", p1 == p4);
31   check("begin", p1.begin() == t1);
32   check("last",  p1.end()   == t2);
33   check("end",   p1.last()  == t2-time_duration::unit());
34 
35   std::cout << p1 << std::endl;
36   //  check("last",  p1.()  == t2);
37   check("contains begin", p1.contains(t1));
38   check("contains end-not", !p1.contains(t2));
39   check("contains last",  p1.contains(t2-seconds(1)));
40   ptime t3(date(2001,Jan,1),hours(4));
41   time_period p5(t2,t3);
42   check("check contains", !p1.contains(p5.begin()));
43   check("check contains", !p5.contains(p1.begin()));
44   check("operator== not equal case", !(p1 == p5));
45   check("less than order", p1 < p5);
46   check("greater than order", p5 > p1);
47   check("not equal", p5 != p1);
48   check("intersects with myself", p1.intersects(p1));
49   check("not intersects", !(p1.intersects(p5)));
50   check("not intersects", !(p5.intersects(p1)));
51 
52   time_period p6(p5);
53   p6.shift(minutes(30));
54   std::cout << p5 << std::endl;
55   std::cout << p6 << std::endl;
56   check("shifted intersects",    p5.intersects(p6));
57   check("shifted intersects",    p6.intersects(p5));
58   check("contains begin",        p5.contains(p6.begin()));
59   p6.shift(minutes(30));
60   std::cout << p5 << std::endl;
61   std::cout << p6 << std::endl;
62   check("shifted !intersects",    !p5.intersects(p6));
63   check("shifted !intersects",    !p6.intersects(p5));
64   p6.shift(minutes(-30));
65   std::cout << p5 << std::endl;
66   std::cout << p6 << std::endl;
67   time_period p7 = p5.intersection(p6);
68   std::cout << p7 << std::endl;
69   check("shifted intersection",
70         p7 == time_period(ptime(d1,time_duration(3,30,0)),
71                           ptime(d1,time_duration(4,0,0))));
72 
73 
74   return printTestStats();
75 
76 }
77 
78