annotate DEPENDENCIES/generic/include/boost/date_time/time.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 #ifndef DATE_TIME_TIME_HPP___
Chris@16 2 #define DATE_TIME_TIME_HPP___
Chris@16 3
Chris@16 4 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
Chris@16 5 * Use, modification and distribution is subject to the
Chris@16 6 * Boost Software License, Version 1.0. (See accompanying
Chris@16 7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 * Author: Jeff Garland, Bart Garst
Chris@101 9 * $Date$
Chris@16 10 */
Chris@16 11
Chris@16 12
Chris@16 13 /*! @file time.hpp
Chris@16 14 This file contains the interface for the time associated classes.
Chris@16 15 */
Chris@16 16 #include <string>
Chris@16 17 #include <boost/operators.hpp>
Chris@16 18 #include <boost/date_time/time_defs.hpp>
Chris@16 19 #include <boost/date_time/special_defs.hpp>
Chris@16 20
Chris@16 21 namespace boost {
Chris@16 22 namespace date_time {
Chris@16 23
Chris@16 24 //! Representation of a precise moment in time, including the date.
Chris@16 25 /*!
Chris@16 26 This class is a skeleton for the interface of a temporal type
Chris@16 27 with a resolution that is higher than a day. It is intended that
Chris@16 28 this class be the base class and that the actual time
Chris@16 29 class be derived using the BN pattern. In this way, the derived
Chris@16 30 class can make decisions such as 'should there be a default constructor'
Chris@16 31 and what should it set its value to, should there be optional constructors
Chris@16 32 say allowing only an time_durations that generate a time from a clock,etc.
Chris@16 33 So, in fact multiple time types can be created for a time_system with
Chris@16 34 different construction policies, and all of them can perform basic
Chris@16 35 operations by only writing a copy constructor. Finally, compiler
Chris@16 36 errors are also shorter.
Chris@16 37
Chris@16 38 The real behavior of the time class is provided by the time_system
Chris@16 39 template parameter. This class must provide all the logic
Chris@16 40 for addition, subtraction, as well as define all the interface
Chris@16 41 types.
Chris@16 42
Chris@16 43 */
Chris@16 44
Chris@16 45 template <class T, class time_system>
Chris@16 46 class base_time : private
Chris@16 47 boost::less_than_comparable<T
Chris@16 48 , boost::equality_comparable<T
Chris@16 49 > >
Chris@16 50 {
Chris@16 51 public:
Chris@101 52 // A tag for type categorization. Can be used to detect Boost.DateTime time points in generic code.
Chris@101 53 typedef void _is_boost_date_time_time_point;
Chris@16 54 typedef T time_type;
Chris@16 55 typedef typename time_system::time_rep_type time_rep_type;
Chris@16 56 typedef typename time_system::date_type date_type;
Chris@16 57 typedef typename time_system::date_duration_type date_duration_type;
Chris@16 58 typedef typename time_system::time_duration_type time_duration_type;
Chris@16 59 //typedef typename time_system::hms_type hms_type;
Chris@16 60
Chris@16 61 base_time(const date_type& day,
Chris@16 62 const time_duration_type& td,
Chris@16 63 dst_flags dst=not_dst) :
Chris@16 64 time_(time_system::get_time_rep(day, td, dst))
Chris@16 65 {}
Chris@16 66 base_time(special_values sv) :
Chris@16 67 time_(time_system::get_time_rep(sv))
Chris@16 68 {}
Chris@16 69 base_time(const time_rep_type& rhs) :
Chris@16 70 time_(rhs)
Chris@16 71 {}
Chris@16 72 date_type date() const
Chris@16 73 {
Chris@16 74 return time_system::get_date(time_);
Chris@16 75 }
Chris@16 76 time_duration_type time_of_day() const
Chris@16 77 {
Chris@16 78 return time_system::get_time_of_day(time_);
Chris@16 79 }
Chris@16 80 /*! Optional bool parameter will return time zone as an offset
Chris@16 81 * (ie "+07:00"). Empty string is returned for classes that do
Chris@16 82 * not use a time_zone */
Chris@16 83 std::string zone_name(bool /*as_offset*/=false) const
Chris@16 84 {
Chris@16 85 return time_system::zone_name(time_);
Chris@16 86 }
Chris@16 87 /*! Optional bool parameter will return time zone as an offset
Chris@16 88 * (ie "+07:00"). Empty string is returned for classes that do
Chris@16 89 * not use a time_zone */
Chris@16 90 std::string zone_abbrev(bool /*as_offset*/=false) const
Chris@16 91 {
Chris@16 92 return time_system::zone_name(time_);
Chris@16 93 }
Chris@16 94 //! An empty string is returned for classes that do not use a time_zone
Chris@16 95 std::string zone_as_posix_string() const
Chris@16 96 {
Chris@16 97 return std::string();
Chris@16 98 }
Chris@16 99
Chris@16 100 //! check to see if date is not a value
Chris@16 101 bool is_not_a_date_time() const
Chris@16 102 {
Chris@16 103 return time_.is_not_a_date_time();
Chris@16 104 }
Chris@16 105 //! check to see if date is one of the infinity values
Chris@16 106 bool is_infinity() const
Chris@16 107 {
Chris@16 108 return (is_pos_infinity() || is_neg_infinity());
Chris@16 109 }
Chris@16 110 //! check to see if date is greater than all possible dates
Chris@16 111 bool is_pos_infinity() const
Chris@16 112 {
Chris@16 113 return time_.is_pos_infinity();
Chris@16 114 }
Chris@16 115 //! check to see if date is greater than all possible dates
Chris@16 116 bool is_neg_infinity() const
Chris@16 117 {
Chris@16 118 return time_.is_neg_infinity();
Chris@16 119 }
Chris@16 120 //! check to see if time is a special value
Chris@16 121 bool is_special() const
Chris@16 122 {
Chris@16 123 return(is_not_a_date_time() || is_infinity());
Chris@16 124 }
Chris@16 125 //!Equality operator -- others generated by boost::equality_comparable
Chris@16 126 bool operator==(const time_type& rhs) const
Chris@16 127 {
Chris@16 128 return time_system::is_equal(time_,rhs.time_);
Chris@16 129 }
Chris@16 130 //!Equality operator -- others generated by boost::less_than_comparable
Chris@16 131 bool operator<(const time_type& rhs) const
Chris@16 132 {
Chris@16 133 return time_system::is_less(time_,rhs.time_);
Chris@16 134 }
Chris@16 135 //! difference between two times
Chris@16 136 time_duration_type operator-(const time_type& rhs) const
Chris@16 137 {
Chris@16 138 return time_system::subtract_times(time_, rhs.time_);
Chris@16 139 }
Chris@16 140 //! add date durations
Chris@16 141 time_type operator+(const date_duration_type& dd) const
Chris@16 142 {
Chris@16 143 return time_system::add_days(time_, dd);
Chris@16 144 }
Chris@16 145 time_type operator+=(const date_duration_type& dd)
Chris@16 146 {
Chris@16 147 time_ = (time_system::get_time_rep(date() + dd, time_of_day()));
Chris@16 148 return time_type(time_);
Chris@16 149 }
Chris@16 150 //! subtract date durations
Chris@16 151 time_type operator-(const date_duration_type& dd) const
Chris@16 152 {
Chris@16 153 return time_system::subtract_days(time_, dd);
Chris@16 154 }
Chris@16 155 time_type operator-=(const date_duration_type& dd)
Chris@16 156 {
Chris@16 157 time_ = (time_system::get_time_rep(date() - dd, time_of_day()));
Chris@16 158 return time_type(time_);
Chris@16 159 }
Chris@16 160 //! add time durations
Chris@16 161 time_type operator+(const time_duration_type& td) const
Chris@16 162 {
Chris@16 163 return time_type(time_system::add_time_duration(time_, td));
Chris@16 164 }
Chris@16 165 time_type operator+=(const time_duration_type& td)
Chris@16 166 {
Chris@16 167 time_ = (time_system::get_time_rep(date(), time_of_day() + td));
Chris@16 168 return time_type(time_);
Chris@16 169 }
Chris@16 170 //! subtract time durations
Chris@16 171 time_type operator-(const time_duration_type& rhs) const
Chris@16 172 {
Chris@16 173 return time_system::subtract_time_duration(time_, rhs);
Chris@16 174 }
Chris@16 175 time_type operator-=(const time_duration_type& td)
Chris@16 176 {
Chris@16 177 time_ = (time_system::get_time_rep(date(), time_of_day() - td));
Chris@16 178 return time_type(time_);
Chris@16 179 }
Chris@16 180
Chris@16 181 protected:
Chris@16 182 time_rep_type time_;
Chris@16 183 };
Chris@16 184
Chris@16 185
Chris@16 186
Chris@16 187
Chris@16 188
Chris@16 189 } } //namespace date_time::boost
Chris@16 190
Chris@16 191
Chris@16 192 #endif
Chris@16 193