1 #ifndef GREG_DURATION_HPP___
2 #define GREG_DURATION_HPP___
4 /* Copyright (c) 2002,2003 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
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>
20 //!An internal date representation that includes infinities, not a date
21 typedef boost::date_time::duration_traits_adapted date_duration_rep;
23 //! Durations in days for gregorian system
24 /*! \ingroup date_basics
26 class BOOST_SYMBOL_VISIBLE date_duration :
27 public boost::date_time::date_duration< date_duration_rep >
29 typedef boost::date_time::date_duration< date_duration_rep > base_type;
32 typedef base_type::duration_rep duration_rep;
34 //! Construct from a day count
35 explicit date_duration(duration_rep day_count = 0) : base_type(day_count) {}
37 //! construct from special_values
38 date_duration(date_time::special_values sv) : base_type(sv) {}
41 date_duration(const date_duration& other) : base_type(static_cast< base_type const& >(other))
44 //! Construct from another date_duration
45 date_duration(const base_type& other) : base_type(other)
48 // Relational operators
49 // NOTE: Because of date_time::date_duration< T > design choice we don't use Boost.Operators here,
50 // because we need the class to be a direct base. Either lose EBO, or define operators by hand.
51 // The latter is more effecient.
52 bool operator== (const date_duration& rhs) const
54 return base_type::operator== (rhs);
56 bool operator!= (const date_duration& rhs) const
58 return !operator== (rhs);
60 bool operator< (const date_duration& rhs) const
62 return base_type::operator< (rhs);
64 bool operator> (const date_duration& rhs) const
66 return !(base_type::operator< (rhs) || base_type::operator== (rhs));
68 bool operator<= (const date_duration& rhs) const
70 return (base_type::operator< (rhs) || base_type::operator== (rhs));
72 bool operator>= (const date_duration& rhs) const
74 return !base_type::operator< (rhs);
77 //! Subtract another duration -- result is signed
78 date_duration& operator-= (const date_duration& rhs)
80 base_type::operator-= (rhs);
83 friend date_duration operator- (date_duration rhs, date_duration const& lhs)
89 //! Add a duration -- result is signed
90 date_duration& operator+= (const date_duration& rhs)
92 base_type::operator+= (rhs);
95 friend date_duration operator+ (date_duration rhs, date_duration const& lhs)
101 //! unary- Allows for dd = -date_duration(2); -> dd == -2
102 date_duration operator- ()const
104 return date_duration(get_rep() * (-1));
107 //! Division operations on a duration with an integer.
108 date_duration& operator/= (int divisor)
110 base_type::operator/= (divisor);
113 friend date_duration operator/ (date_duration rhs, int lhs)
119 //! Returns the smallest duration -- used by to calculate 'end'
120 static date_duration unit()
122 return date_duration(base_type::unit().get_rep());
126 //! Shorthand for date_duration
127 typedef date_duration days;
129 } } //namespace gregorian
131 #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
132 #include <boost/date_time/date_duration_types.hpp>