1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4    Distributed under the Boost Software License, Version 1.0.
5       (See accompanying file LICENCE.txt or copy at
6            http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_GREGORIAN_DATE_HPP_JOFA_080416
9 #define BOOST_ICL_GREGORIAN_DATE_HPP_JOFA_080416
10 
11 #include <boost/icl/detail/boost_config.hpp>
12 #include <boost/detail/workaround.hpp>
13 
14 #ifdef BOOST_MSVC
15 #pragma warning(push)
16 #pragma warning(disable:4100) // unreferenced formal parameter
17 #pragma warning(disable:4127) // conditional expression is constant
18 #pragma warning(disable:4244) // 'argument' : conversion from 'int' to 'unsigned short', possible loss of data
19 #pragma warning(disable:4702) // boost\lexical_cast.hpp(1159) : warning C4702: unreachable code
20 #pragma warning(disable:4996) // Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
21 #endif
22 
23 #include <stdio.h>
24 #include <string>
25 #include <sstream>
26 #include <iostream>
27 #include <boost/date_time/gregorian/gregorian.hpp>
28 
29 #ifdef BOOST_MSVC
30 #pragma warning(pop)
31 #endif
32 
33 #include <boost/icl/type_traits/identity_element.hpp>
34 #include <boost/icl/type_traits/is_discrete.hpp>
35 #include <boost/icl/type_traits/difference_type_of.hpp>
36 #include <boost/icl/type_traits/size_type_of.hpp>
37 
38 namespace boost{namespace icl
39 {
40     template<> struct is_discrete<boost::gregorian::date>
41     {
42         typedef is_discrete type;
43         BOOST_STATIC_CONSTANT(bool, value = true);
44     };
45 
46     template<>
value()47     inline boost::gregorian::date identity_element<boost::gregorian::date>::value()
48     {
49         return boost::gregorian::date(boost::gregorian::min_date_time);
50     }
51 
52     template<>
53     struct identity_element<boost::gregorian::date_duration>
54     {
valueboost::icl::identity_element55         static boost::gregorian::date_duration value()
56         {
57             return boost::gregorian::date(boost::gregorian::min_date_time)
58                  - boost::gregorian::date(boost::gregorian::min_date_time);
59         }
60     };
61 
62     template<>
63     struct has_difference<boost::gregorian::date>
64     {
65         typedef has_difference type;
66         BOOST_STATIC_CONSTANT(bool, value = true);
67     };
68 
69     template<>
70     struct difference_type_of<boost::gregorian::date>
71     { typedef boost::gregorian::date_duration type; };
72 
73     template<>
74     struct size_type_of<boost::gregorian::date>
75     { typedef boost::gregorian::date_duration type; };
76 
77 
78 
79     // ------------------------------------------------------------------------
operator ++(boost::gregorian::date & x)80     inline boost::gregorian::date operator ++(boost::gregorian::date& x)
81     {
82         return x += boost::gregorian::date::duration_type::unit();
83     }
84 
operator --(boost::gregorian::date & x)85     inline boost::gregorian::date operator --(boost::gregorian::date& x)
86     {
87         return x -= boost::gregorian::date::duration_type::unit();
88     }
89 
90     // ------------------------------------------------------------------------
91     template<> struct is_discrete<boost::gregorian::date_duration>
92     {
93         typedef is_discrete type;
94         BOOST_STATIC_CONSTANT(bool, value = true);
95     };
96 
97     template<>
98     struct has_difference<boost::gregorian::date_duration>
99     {
100         typedef has_difference type;
101         BOOST_STATIC_CONSTANT(bool, value = true);
102     };
103 
104     template<>
105     struct size_type_of<boost::gregorian::date_duration>
106     {
107         typedef boost::gregorian::date_duration type;
108     };
109 
operator ++(boost::gregorian::date_duration & x)110     inline boost::gregorian::date_duration operator ++(boost::gregorian::date_duration& x)
111     {
112         return x += boost::gregorian::date::duration_type::unit();
113     }
114 
operator --(boost::gregorian::date_duration & x)115     inline boost::gregorian::date_duration operator --(boost::gregorian::date_duration& x)
116     {
117         return x -= boost::gregorian::date::duration_type::unit();
118     }
119 
120     // ------------------------------------------------------------------------
121 
122 
123 }} // namespace icl boost
124 
125 #endif
126 
127 
128