fix doc example typo
[boost.git] / boost / date_time / gregorian / greg_duration.hpp
blobdc6ad607556e8780e126480dc73ca06acfd8e51a
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
9 * $Date$
12 #include <boost/date_time/date_duration.hpp>
13 #include <boost/date_time/int_adapter.hpp>
14 #include <boost/date_time/special_defs.hpp>
16 namespace boost {
17 namespace gregorian {
19 //!An internal date representation that includes infinities, not a date
20 typedef boost::date_time::duration_traits_adapted date_duration_rep;
22 //! Durations in days for gregorian system
23 /*! \ingroup date_basics
25 class date_duration :
26 public boost::date_time::date_duration< date_duration_rep >
28 typedef boost::date_time::date_duration< date_duration_rep > base_type;
30 public:
31 typedef base_type::duration_rep duration_rep;
33 //! Construct from a day count
34 explicit date_duration(duration_rep day_count = 0) : base_type(day_count) {}
36 //! construct from special_values
37 date_duration(date_time::special_values sv) : base_type(sv) {}
39 //! Copy constructor
40 date_duration(const date_duration& other) : base_type(static_cast< base_type const& >(other))
43 //! Construct from another date_duration
44 date_duration(const base_type& other) : base_type(other)
47 // Relational operators
48 // NOTE: Because of date_time::date_duration< T > design choice we don't use Boost.Operators here,
49 // because we need the class to be a direct base. Either lose EBO, or define operators by hand.
50 // The latter is more effecient.
51 bool operator== (const date_duration& rhs) const
53 return base_type::operator== (rhs);
55 bool operator!= (const date_duration& rhs) const
57 return !operator== (rhs);
59 bool operator< (const date_duration& rhs) const
61 return base_type::operator< (rhs);
63 bool operator> (const date_duration& rhs) const
65 return !(base_type::operator< (rhs) || base_type::operator== (rhs));
67 bool operator<= (const date_duration& rhs) const
69 return (base_type::operator< (rhs) || base_type::operator== (rhs));
71 bool operator>= (const date_duration& rhs) const
73 return !base_type::operator< (rhs);
76 //! Subtract another duration -- result is signed
77 date_duration& operator-= (const date_duration& rhs)
79 base_type::operator-= (rhs);
80 return *this;
82 friend date_duration operator- (date_duration rhs, date_duration const& lhs)
84 rhs -= lhs;
85 return rhs;
88 //! Add a duration -- result is signed
89 date_duration& operator+= (const date_duration& rhs)
91 base_type::operator+= (rhs);
92 return *this;
94 friend date_duration operator+ (date_duration rhs, date_duration const& lhs)
96 rhs += lhs;
97 return rhs;
100 //! unary- Allows for dd = -date_duration(2); -> dd == -2
101 date_duration operator- ()const
103 return date_duration(get_rep() * (-1));
106 //! Division operations on a duration with an integer.
107 date_duration& operator/= (int divisor)
109 base_type::operator/= (divisor);
110 return *this;
112 friend date_duration operator/ (date_duration rhs, int lhs)
114 rhs /= lhs;
115 return rhs;
118 //! Returns the smallest duration -- used by to calculate 'end'
119 static date_duration unit()
121 return date_duration(base_type::unit().get_rep());
125 //! Shorthand for date_duration
126 typedef date_duration days;
128 } } //namespace gregorian
130 #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
131 #include <boost/date_time/date_duration_types.hpp>
132 #endif
134 #endif