]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/date_time/gregorian/greg_duration.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / date_time / gregorian / greg_duration.hpp
1 #ifndef GREG_DURATION_HPP___
2 #define GREG_DURATION_HPP___
3
4 /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
9 * $Date$
10 */
11
12 #include <boost/date_time/compiler_config.hpp>
13 #include <boost/date_time/date_duration.hpp>
14 #include <boost/date_time/int_adapter.hpp>
15 #include <boost/date_time/special_defs.hpp>
16
17 namespace boost {
18 namespace gregorian {
19
20 //!An internal date representation that includes infinities, not a date
21 typedef boost::date_time::duration_traits_adapted date_duration_rep;
22
23 //! Durations in days for gregorian system
24 /*! \ingroup date_basics
25 */
26 class BOOST_SYMBOL_VISIBLE date_duration :
27 public boost::date_time::date_duration< date_duration_rep >
28 {
29 typedef boost::date_time::date_duration< date_duration_rep > base_type;
30
31 public:
32 typedef base_type::duration_rep duration_rep;
33
34 //! Construct from a day count
35 BOOST_CXX14_CONSTEXPR explicit
36 date_duration(duration_rep day_count = 0) : base_type(day_count) {}
37
38 //! construct from special_values
39 BOOST_CXX14_CONSTEXPR
40 date_duration(date_time::special_values sv) : base_type(sv) {}
41
42 //! Copy constructor
43 BOOST_CXX14_CONSTEXPR
44 date_duration(const date_duration& other) : base_type(static_cast< base_type const& >(other))
45 {}
46
47 //! Construct from another date_duration
48 BOOST_CXX14_CONSTEXPR
49 date_duration(const base_type& other) : base_type(other)
50 {}
51
52 // Relational operators
53 // NOTE: Because of date_time::date_duration< T > design choice we don't use Boost.Operators here,
54 // because we need the class to be a direct base. Either lose EBO, or define operators by hand.
55 // The latter is more effecient.
56 BOOST_CXX14_CONSTEXPR bool operator== (const date_duration& rhs) const
57 {
58 return base_type::operator== (rhs);
59 }
60 BOOST_CXX14_CONSTEXPR bool operator!= (const date_duration& rhs) const
61 {
62 return !operator== (rhs);
63 }
64 BOOST_CXX14_CONSTEXPR bool operator< (const date_duration& rhs) const
65 {
66 return base_type::operator< (rhs);
67 }
68 BOOST_CXX14_CONSTEXPR bool operator> (const date_duration& rhs) const
69 {
70 return !(base_type::operator< (rhs) || base_type::operator== (rhs));
71 }
72 BOOST_CXX14_CONSTEXPR bool operator<= (const date_duration& rhs) const
73 {
74 return (base_type::operator< (rhs) || base_type::operator== (rhs));
75 }
76 BOOST_CXX14_CONSTEXPR bool operator>= (const date_duration& rhs) const
77 {
78 return !base_type::operator< (rhs);
79 }
80
81 //! Subtract another duration -- result is signed
82 BOOST_CXX14_CONSTEXPR date_duration& operator-= (const date_duration& rhs)
83 {
84 base_type::operator-= (rhs);
85 return *this;
86 }
87 BOOST_CXX14_CONSTEXPR friend
88 date_duration operator- (date_duration rhs, date_duration const& lhs)
89 {
90 rhs -= lhs;
91 return rhs;
92 }
93
94 //! Add a duration -- result is signed
95 BOOST_CXX14_CONSTEXPR date_duration& operator+= (const date_duration& rhs)
96 {
97 base_type::operator+= (rhs);
98 return *this;
99 }
100 BOOST_CXX14_CONSTEXPR friend
101 date_duration operator+ (date_duration rhs, date_duration const& lhs)
102 {
103 rhs += lhs;
104 return rhs;
105 }
106
107 //! unary- Allows for dd = -date_duration(2); -> dd == -2
108 BOOST_CXX14_CONSTEXPR date_duration operator- ()const
109 {
110 return date_duration(get_rep() * (-1));
111 }
112
113 //! Division operations on a duration with an integer.
114 BOOST_CXX14_CONSTEXPR date_duration& operator/= (int divisor)
115 {
116 base_type::operator/= (divisor);
117 return *this;
118 }
119 BOOST_CXX14_CONSTEXPR friend date_duration operator/ (date_duration rhs, int lhs)
120 {
121 rhs /= lhs;
122 return rhs;
123 }
124
125 //! Returns the smallest duration -- used by to calculate 'end'
126 static BOOST_CXX14_CONSTEXPR date_duration unit()
127 {
128 return date_duration(base_type::unit().get_rep());
129 }
130 };
131
132 //! Shorthand for date_duration
133 typedef date_duration days;
134
135 } } //namespace gregorian
136
137 #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
138 #include <boost/date_time/date_duration_types.hpp>
139 #endif
140
141 #endif