Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:39

0001 #ifndef DATE_TIME_TIME_HPP___
0002 #define DATE_TIME_TIME_HPP___
0003 
0004 /* Copyright (c) 2002,2003,2005,2020 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 
0013 /*! @file time.hpp
0014   This file contains the interface for the time associated classes.
0015 */
0016 #include <string>
0017 #include <boost/operators.hpp>
0018 #include <boost/date_time/time_defs.hpp>
0019 #include <boost/date_time/special_defs.hpp>
0020 
0021 namespace boost {
0022 namespace date_time {
0023 
0024   //! Representation of a precise moment in time, including the date.
0025   /*! 
0026     This class is a skeleton for the interface of a temporal type
0027     with a resolution that is higher than a day.  It is intended that 
0028     this class be the base class and that the actual time 
0029     class be derived using the BN pattern.  In this way, the derived 
0030     class can make decisions such as 'should there be a default constructor' 
0031     and what should it set its value to, should there be optional constructors
0032     say allowing only an time_durations that generate a time from a clock,etc.
0033     So, in fact multiple time types can be created for a time_system with
0034     different construction policies, and all of them can perform basic
0035     operations by only writing a copy constructor.  Finally, compiler 
0036     errors are also shorter. 
0037     
0038     The real behavior of the time class is provided by the time_system
0039     template parameter.  This class must provide all the logic
0040     for addition, subtraction, as well as define all the interface
0041     types.
0042     
0043   */
0044 
0045   template <class T, class time_system>
0046   class base_time : private
0047       boost::less_than_comparable<T
0048     , boost::equality_comparable<T
0049       > >
0050   {
0051   public:
0052     // A tag for type categorization. Can be used to detect Boost.DateTime time points in generic code.
0053     typedef void _is_boost_date_time_time_point;
0054     typedef T time_type;
0055     typedef typename time_system::time_rep_type time_rep_type;
0056     typedef typename time_system::date_type date_type;
0057     typedef typename time_system::date_duration_type date_duration_type;
0058     typedef typename time_system::time_duration_type time_duration_type;
0059     //typedef typename time_system::hms_type hms_type;
0060     
0061     BOOST_CXX14_CONSTEXPR
0062     base_time(const date_type& day, 
0063               const time_duration_type& td, 
0064               dst_flags dst=not_dst) :
0065       time_(time_system::get_time_rep(day, td, dst))
0066     {}
0067     BOOST_CXX14_CONSTEXPR
0068     base_time(special_values sv) :
0069       time_(time_system::get_time_rep(sv))
0070     {}
0071     BOOST_CXX14_CONSTEXPR
0072     base_time(const time_rep_type& rhs) :
0073       time_(rhs)
0074     {}
0075     BOOST_CXX14_CONSTEXPR
0076     date_type date() const
0077     {
0078       return time_system::get_date(time_);
0079     }
0080     BOOST_CXX14_CONSTEXPR
0081     time_duration_type time_of_day() const
0082     {
0083       return time_system::get_time_of_day(time_);
0084     }
0085     /*! Optional bool parameter will return time zone as an offset 
0086      * (ie "+07:00"). Empty string is returned for classes that do 
0087      * not use a time_zone */
0088     std::string zone_name(bool /*as_offset*/=false) const
0089     {
0090       return time_system::zone_name(time_);
0091     }
0092     /*! Optional bool parameter will return time zone as an offset 
0093      * (ie "+07:00"). Empty string is returned for classes that do 
0094      * not use a time_zone */
0095     std::string zone_abbrev(bool /*as_offset*/=false) const
0096     {
0097       return time_system::zone_name(time_);
0098     }
0099     //! An empty string is returned for classes that do not use a time_zone
0100     std::string zone_as_posix_string() const
0101     {
0102       return std::string();
0103     }
0104 
0105     //! check to see if date is not a value
0106     BOOST_CXX14_CONSTEXPR
0107     bool is_not_a_date_time()  const
0108     {
0109       return time_.is_not_a_date_time();
0110     }
0111     //! check to see if date is one of the infinity values
0112     BOOST_CXX14_CONSTEXPR
0113     bool is_infinity()  const
0114     {
0115       return (is_pos_infinity() || is_neg_infinity()); 
0116     }
0117     //! check to see if date is greater than all possible dates
0118     BOOST_CXX14_CONSTEXPR
0119     bool is_pos_infinity()  const
0120     {
0121       return time_.is_pos_infinity();
0122     }
0123     //! check to see if date is greater than all possible dates
0124     BOOST_CXX14_CONSTEXPR
0125     bool is_neg_infinity()  const
0126     {
0127       return time_.is_neg_infinity();
0128     }
0129     //! check to see if time is a special value
0130     BOOST_CXX14_CONSTEXPR
0131     bool is_special() const
0132     {
0133       return(is_not_a_date_time() || is_infinity());
0134     }
0135     //!Equality operator -- others generated by boost::equality_comparable
0136     BOOST_CXX14_CONSTEXPR
0137     bool operator==(const time_type& rhs) const
0138     {
0139       return time_system::is_equal(time_,rhs.time_);
0140     }
0141     //!Equality operator -- others generated by boost::less_than_comparable
0142     BOOST_CXX14_CONSTEXPR
0143     bool operator<(const time_type& rhs) const
0144     {
0145       return time_system::is_less(time_,rhs.time_);
0146     }
0147     //! difference between two times
0148     BOOST_CXX14_CONSTEXPR
0149     time_duration_type operator-(const time_type& rhs) const
0150     {
0151       return time_system::subtract_times(time_, rhs.time_);
0152     }
0153     //! add date durations
0154     BOOST_CXX14_CONSTEXPR
0155     time_type operator+(const date_duration_type& dd) const
0156     {
0157       return time_system::add_days(time_, dd);
0158     }
0159     BOOST_CXX14_CONSTEXPR
0160     time_type operator+=(const date_duration_type& dd)
0161     {
0162       time_ = (time_system::get_time_rep(date() + dd, time_of_day()));
0163       return time_type(time_);
0164     }
0165     //! subtract date durations
0166     BOOST_CXX14_CONSTEXPR
0167     time_type operator-(const date_duration_type& dd) const
0168     {
0169       return time_system::subtract_days(time_, dd);
0170     }
0171     BOOST_CXX14_CONSTEXPR
0172     time_type operator-=(const date_duration_type& dd)
0173     {
0174       time_ = (time_system::get_time_rep(date() - dd, time_of_day()));
0175       return time_type(time_);
0176     }
0177     //! add time durations
0178     BOOST_CXX14_CONSTEXPR
0179     time_type operator+(const time_duration_type& td) const
0180     {
0181       return time_type(time_system::add_time_duration(time_, td));
0182     }
0183     BOOST_CXX14_CONSTEXPR
0184     time_type operator+=(const time_duration_type& td)
0185     {
0186       time_ = time_system::add_time_duration(time_,td);
0187       return time_type(time_);
0188     }
0189     //! subtract time durations
0190     BOOST_CXX14_CONSTEXPR
0191     time_type operator-(const time_duration_type& rhs) const
0192     {
0193       return time_system::subtract_time_duration(time_, rhs);
0194     }
0195     BOOST_CXX14_CONSTEXPR
0196     time_type operator-=(const time_duration_type& td) 
0197     {
0198       time_ = time_system::subtract_time_duration(time_, td);
0199       return time_type(time_);
0200     }
0201     
0202   protected:
0203     time_rep_type time_;
0204   };
0205 
0206 
0207 
0208 
0209 
0210 } } //namespace date_time::boost
0211 
0212 
0213 #endif
0214