• 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, Bart Garst
6  */
7 
8 #include "boost/date_time/gregorian/gregorian.hpp"
9 #include "boost/date_time/posix_time/posix_time.hpp"
10 #include "../testfrmwk.hpp"
11 
12 
main()13 int main(){
14 
15 #if !defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
16   // do not set this test to return fail -
17   // this is not necessarily a compiler problem
18   check("Optional gregorian types not selected - no tests run", true);
19 #else
20 
21   using namespace boost::gregorian;
22   using namespace boost::posix_time;
23 
24 
25   /*** months ***/
26   {
27     ptime p(date(2001, Oct, 31), hours(5));
28     check("ptime + months",
29         ptime(date(2002, Feb, 28), hours(5)) == p + months(4));
30     p += months(4);
31     check("ptime += months",
32         ptime(date(2002, Feb, 28), hours(5)) == p);
33   }
34   {
35     ptime p(date(2001, Oct, 31), hours(5));
36     check("ptime - months",
37         ptime(date(2001, Apr, 30), hours(5)) == p - months(6));
38     p -= months(6);
39     check("ptime -= months",
40         ptime(date(2001, Apr, 30), hours(5)) == p);
41   }
42 
43   /*** years ***/
44   {
45     ptime p(date(2001, Feb, 28), hours(5));
46     check("ptime + years",
47         ptime(date(2004, Feb, 29), hours(5)) == p + years(3));
48     p += years(3);
49     check("ptime += years",
50         ptime(date(2004, Feb, 29), hours(5)) == p);
51   }
52   {
53     ptime p(date(2000, Feb, 29), hours(5));
54     check("ptime - years",
55         ptime(date(1998, Feb, 28), hours(5)) == p - years(2));
56     p -= years(2);
57     check("ptime -= years",
58         ptime(date(1998, Feb, 28), hours(5)) == p);
59   }
60 
61 
62   /*** weeks ***/
63   // shouldn't need many tests, it is nothing more than a date_duration
64   // so all date_duration tests should prove this class
65   {
66     ptime p(date(2001, Feb, 28), hours(5));
67     check("ptime + weeks",
68         ptime(date(2001, Mar, 21), hours(5)) == p + weeks(3));
69     p += weeks(3);
70     check("ptime += weeks",
71         ptime(date(2001, Mar, 21), hours(5)) == p);
72   }
73   {
74     ptime p(date(2001, Feb, 28), hours(5));
75     check("ptime - weeks",
76         ptime(date(2001, Feb, 14), hours(5)) == p - weeks(2));
77     p -= weeks(2);
78     check("ptime -= weeks",
79         ptime(date(2001, Feb, 14), hours(5)) == p);
80   }
81 
82 #endif // BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES
83 
84   return printTestStats();
85 }
86