?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/date_time.zip
???????
PK �b�[R;AV� � date_defs.hppnu �[��� #ifndef DATE_TIME_DATE_DEFS_HPP #define DATE_TIME_DATE_DEFS_HPP /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ namespace boost { namespace date_time { //! An enumeration of weekday names enum weekdays {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; //! Simple enum to allow for nice programming with Jan, Feb, etc enum months_of_year {Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,NotAMonth,NumMonths}; } } //namespace date_time #endif PK �b�[�h 8� � time.hppnu �[��� #ifndef DATE_TIME_TIME_HPP___ #define DATE_TIME_TIME_HPP___ /* Copyright (c) 2002,2003,2005,2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ /*! @file time.hpp This file contains the interface for the time associated classes. */ #include <string> #include <boost/operators.hpp> #include <boost/date_time/time_defs.hpp> #include <boost/date_time/special_defs.hpp> namespace boost { namespace date_time { //! Representation of a precise moment in time, including the date. /*! This class is a skeleton for the interface of a temporal type with a resolution that is higher than a day. It is intended that this class be the base class and that the actual time class be derived using the BN pattern. In this way, the derived class can make decisions such as 'should there be a default constructor' and what should it set its value to, should there be optional constructors say allowing only an time_durations that generate a time from a clock,etc. So, in fact multiple time types can be created for a time_system with different construction policies, and all of them can perform basic operations by only writing a copy constructor. Finally, compiler errors are also shorter. The real behavior of the time class is provided by the time_system template parameter. This class must provide all the logic for addition, subtraction, as well as define all the interface types. */ template <class T, class time_system> class base_time : private boost::less_than_comparable<T , boost::equality_comparable<T > > { public: // A tag for type categorization. Can be used to detect Boost.DateTime time points in generic code. typedef void _is_boost_date_time_time_point; typedef T time_type; typedef typename time_system::time_rep_type time_rep_type; typedef typename time_system::date_type date_type; typedef typename time_system::date_duration_type date_duration_type; typedef typename time_system::time_duration_type time_duration_type; //typedef typename time_system::hms_type hms_type; BOOST_CXX14_CONSTEXPR base_time(const date_type& day, const time_duration_type& td, dst_flags dst=not_dst) : time_(time_system::get_time_rep(day, td, dst)) {} BOOST_CXX14_CONSTEXPR base_time(special_values sv) : time_(time_system::get_time_rep(sv)) {} BOOST_CXX14_CONSTEXPR base_time(const time_rep_type& rhs) : time_(rhs) {} BOOST_CXX14_CONSTEXPR date_type date() const { return time_system::get_date(time_); } BOOST_CXX14_CONSTEXPR time_duration_type time_of_day() const { return time_system::get_time_of_day(time_); } /*! Optional bool parameter will return time zone as an offset * (ie "+07:00"). Empty string is returned for classes that do * not use a time_zone */ std::string zone_name(bool /*as_offset*/=false) const { return time_system::zone_name(time_); } /*! Optional bool parameter will return time zone as an offset * (ie "+07:00"). Empty string is returned for classes that do * not use a time_zone */ std::string zone_abbrev(bool /*as_offset*/=false) const { return time_system::zone_name(time_); } //! An empty string is returned for classes that do not use a time_zone std::string zone_as_posix_string() const { return std::string(); } //! check to see if date is not a value BOOST_CXX14_CONSTEXPR bool is_not_a_date_time() const { return time_.is_not_a_date_time(); } //! check to see if date is one of the infinity values BOOST_CXX14_CONSTEXPR bool is_infinity() const { return (is_pos_infinity() || is_neg_infinity()); } //! check to see if date is greater than all possible dates BOOST_CXX14_CONSTEXPR bool is_pos_infinity() const { return time_.is_pos_infinity(); } //! check to see if date is greater than all possible dates BOOST_CXX14_CONSTEXPR bool is_neg_infinity() const { return time_.is_neg_infinity(); } //! check to see if time is a special value BOOST_CXX14_CONSTEXPR bool is_special() const { return(is_not_a_date_time() || is_infinity()); } //!Equality operator -- others generated by boost::equality_comparable BOOST_CXX14_CONSTEXPR bool operator==(const time_type& rhs) const { return time_system::is_equal(time_,rhs.time_); } //!Equality operator -- others generated by boost::less_than_comparable BOOST_CXX14_CONSTEXPR bool operator<(const time_type& rhs) const { return time_system::is_less(time_,rhs.time_); } //! difference between two times BOOST_CXX14_CONSTEXPR time_duration_type operator-(const time_type& rhs) const { return time_system::subtract_times(time_, rhs.time_); } //! add date durations BOOST_CXX14_CONSTEXPR time_type operator+(const date_duration_type& dd) const { return time_system::add_days(time_, dd); } BOOST_CXX14_CONSTEXPR time_type operator+=(const date_duration_type& dd) { time_ = (time_system::get_time_rep(date() + dd, time_of_day())); return time_type(time_); } //! subtract date durations BOOST_CXX14_CONSTEXPR time_type operator-(const date_duration_type& dd) const { return time_system::subtract_days(time_, dd); } BOOST_CXX14_CONSTEXPR time_type operator-=(const date_duration_type& dd) { time_ = (time_system::get_time_rep(date() - dd, time_of_day())); return time_type(time_); } //! add time durations BOOST_CXX14_CONSTEXPR time_type operator+(const time_duration_type& td) const { return time_type(time_system::add_time_duration(time_, td)); } BOOST_CXX14_CONSTEXPR time_type operator+=(const time_duration_type& td) { time_ = time_system::add_time_duration(time_,td); return time_type(time_); } //! subtract time durations BOOST_CXX14_CONSTEXPR time_type operator-(const time_duration_type& rhs) const { return time_system::subtract_time_duration(time_, rhs); } BOOST_CXX14_CONSTEXPR time_type operator-=(const time_duration_type& td) { time_ = time_system::subtract_time_duration(time_, td); return time_type(time_); } protected: time_rep_type time_; }; } } //namespace date_time::boost #endif PK �b�[r�� � parse_format_base.hppnu �[��� #ifndef DATE_TIME_PARSE_FORMAT_BASE__ #define DATE_TIME_PARSE_FORMAT_BASE__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ namespace boost { namespace date_time { //! Enum for distinguishing parsing and formatting options enum month_format_spec {month_as_integer, month_as_short_string, month_as_long_string}; //! Enum for distinguishing the order of Month, Day, & Year. /*! Enum for distinguishing the order in which Month, Day, & Year * will appear in a date string */ enum ymd_order_spec {ymd_order_iso, //order is year-month-day ymd_order_dmy, //day-month-year ymd_order_us}; //order is month-day-year } }//namespace date_time #endif PK �b�[��� � time_system_split.hppnu �[��� #ifndef DATE_TIME_TIME_SYSTEM_SPLIT_HPP #define DATE_TIME_TIME_SYSTEM_SPLIT_HPP /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <string> #include <boost/cstdint.hpp> #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/time_defs.hpp> #include <boost/date_time/special_defs.hpp> #include <boost/date_time/wrapping_int.hpp> namespace boost { namespace date_time { //! An unadjusted time system implementation. #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) template<typename config, boost::int32_t ticks_per_second> #else template<typename config> #endif class split_timedate_system { public: typedef typename config::time_rep_type time_rep_type; typedef typename config::date_type date_type; typedef typename config::time_duration_type time_duration_type; typedef typename config::date_duration_type date_duration_type; typedef typename config::int_type int_type; typedef typename config::resolution_traits resolution_traits; //86400 is number of seconds in a day... #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) typedef date_time::wrapping_int<int_type, INT64_C(86400) * ticks_per_second > wrap_int_type; #else private: BOOST_STATIC_CONSTANT(int_type, ticks_per_day = INT64_C(86400) * config::tick_per_second); public: # if BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0X581) ) typedef date_time::wrapping_int< split_timedate_system::int_type, split_timedate_system::ticks_per_day> wrap_int_type; # else typedef date_time::wrapping_int<int_type, ticks_per_day> wrap_int_type; #endif #endif static BOOST_CXX14_CONSTEXPR time_rep_type get_time_rep(special_values sv) { switch (sv) { case not_a_date_time: return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); case pos_infin: return time_rep_type(date_type(pos_infin), time_duration_type(pos_infin)); case neg_infin: return time_rep_type(date_type(neg_infin), time_duration_type(neg_infin)); case max_date_time: { time_duration_type td = time_duration_type(24,0,0,0) - time_duration_type(0,0,0,1); return time_rep_type(date_type(max_date_time), td); } case min_date_time: return time_rep_type(date_type(min_date_time), time_duration_type(0,0,0,0)); default: return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } } static BOOST_CXX14_CONSTEXPR time_rep_type get_time_rep(const date_type& day, const time_duration_type& tod, date_time::dst_flags /* dst */ = not_dst) { if(day.is_special() || tod.is_special()) { if(day.is_not_a_date() || tod.is_not_a_date_time()) { return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } else if(day.is_pos_infinity()) { if(tod.is_neg_infinity()) { return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } else { return time_rep_type(day, time_duration_type(pos_infin)); } } else if(day.is_neg_infinity()) { if(tod.is_pos_infinity()) { return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } else { return time_rep_type(day, time_duration_type(neg_infin)); } } else if(tod.is_pos_infinity()) { if(day.is_neg_infinity()) { return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } else { return time_rep_type(date_type(pos_infin), tod); } } else if(tod.is_neg_infinity()) { if(day.is_pos_infinity()) { return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } else { return time_rep_type(date_type(neg_infin), tod); } } } return time_rep_type(day, tod); } static BOOST_CONSTEXPR date_type get_date(const time_rep_type& val) { return date_type(val.day); } static BOOST_CONSTEXPR time_duration_type get_time_of_day(const time_rep_type& val) { return time_duration_type(val.time_of_day); } static std::string zone_name(const time_rep_type&) { return std::string(); } static BOOST_CONSTEXPR bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs) { return ((lhs.day == rhs.day) && (lhs.time_of_day == rhs.time_of_day)); } static BOOST_CXX14_CONSTEXPR bool is_less(const time_rep_type& lhs, const time_rep_type& rhs) { if (lhs.day < rhs.day) return true; if (lhs.day > rhs.day) return false; return (lhs.time_of_day < rhs.time_of_day); } static BOOST_CXX14_CONSTEXPR time_rep_type add_days(const time_rep_type& base, const date_duration_type& dd) { return time_rep_type(base.day+dd, base.time_of_day); } static BOOST_CXX14_CONSTEXPR time_rep_type subtract_days(const time_rep_type& base, const date_duration_type& dd) { return split_timedate_system::get_time_rep(base.day-dd, base.time_of_day); } static BOOST_CXX14_CONSTEXPR time_rep_type subtract_time_duration(const time_rep_type& base, const time_duration_type& td) { if(base.day.is_special() || td.is_special()) { return split_timedate_system::get_time_rep(base.day, -td); } if (td.is_negative()) { time_duration_type td1 = td.invert_sign(); return add_time_duration(base,td1); } wrap_int_type day_offset(base.time_of_day.ticks()); date_duration_type day_overflow(static_cast<typename date_duration_type::duration_rep_type>(day_offset.subtract(td.ticks()))); return time_rep_type(base.day-day_overflow, time_duration_type(0,0,0,day_offset.as_int())); } static BOOST_CXX14_CONSTEXPR time_rep_type add_time_duration(const time_rep_type& base, time_duration_type td) { if(base.day.is_special() || td.is_special()) { return split_timedate_system::get_time_rep(base.day, td); } if (td.is_negative()) { time_duration_type td1 = td.invert_sign(); return subtract_time_duration(base,td1); } wrap_int_type day_offset(base.time_of_day.ticks()); date_duration_type day_overflow(static_cast< typename date_duration_type::duration_rep_type >(day_offset.add(td.ticks()))); return time_rep_type(base.day+day_overflow, time_duration_type(0,0,0,day_offset.as_int())); } static BOOST_CXX14_CONSTEXPR time_duration_type subtract_times(const time_rep_type& lhs, const time_rep_type& rhs) { date_duration_type dd = lhs.day - rhs.day; if (BOOST_LIKELY(!dd.is_special())) { time_duration_type td(dd.days()*24,0,0); // days * 24 hours time_duration_type td2 = lhs.time_of_day - rhs.time_of_day; return td+td2; } else { time_duration_type td(dd.as_special()); time_duration_type td2 = lhs.time_of_day - rhs.time_of_day; return td+td2; } } }; } } //namespace date_time #endif PK �b�[�D��8 8 int_adapter.hppnu �[��� #ifndef _DATE_TIME_INT_ADAPTER_HPP__ #define _DATE_TIME_INT_ADAPTER_HPP__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include "boost/config.hpp" #include "boost/limits.hpp" //work around compilers without limits #include "boost/date_time/special_defs.hpp" #include "boost/date_time/locale_config.hpp" #ifndef BOOST_DATE_TIME_NO_LOCALE # include <ostream> #endif #if defined(BOOST_MSVC) #pragma warning(push) // conditional expression is constant #pragma warning(disable: 4127) #endif namespace boost { namespace date_time { //! Adapter to create integer types with +-infinity, and not a value /*! This class is used internally in counted date/time representations. * It adds the floating point like features of infinities and * not a number. It also provides mathmatical operations with * consideration to special values following these rules: *@code * +infinity - infinity == Not A Number (NAN) * infinity * non-zero == infinity * infinity * zero == NAN * +infinity * -integer == -infinity * infinity / infinity == NAN * infinity * infinity == infinity *@endcode */ template<typename int_type_> class int_adapter { public: typedef int_type_ int_type; BOOST_CXX14_CONSTEXPR int_adapter(int_type v) : value_(v) {} static BOOST_CONSTEXPR bool has_infinity() { return true; } static BOOST_CONSTEXPR int_adapter pos_infinity() { return (::std::numeric_limits<int_type>::max)(); } static BOOST_CONSTEXPR int_adapter neg_infinity() { return (::std::numeric_limits<int_type>::min)(); } static BOOST_CONSTEXPR int_adapter not_a_number() { return (::std::numeric_limits<int_type>::max)()-1; } static BOOST_CONSTEXPR int_adapter max BOOST_PREVENT_MACRO_SUBSTITUTION () { return (::std::numeric_limits<int_type>::max)()-2; } static BOOST_CONSTEXPR int_adapter min BOOST_PREVENT_MACRO_SUBSTITUTION () { return (::std::numeric_limits<int_type>::min)()+1; } static BOOST_CXX14_CONSTEXPR int_adapter from_special(special_values sv) { switch (sv) { case not_a_date_time: return not_a_number(); case neg_infin: return neg_infinity(); case pos_infin: return pos_infinity(); case max_date_time: return (max)(); case min_date_time: return (min)(); default: return not_a_number(); } } static BOOST_CONSTEXPR bool is_inf(int_type v) { return (v == neg_infinity().as_number() || v == pos_infinity().as_number()); } static BOOST_CXX14_CONSTEXPR bool is_neg_inf(int_type v) { return (v == neg_infinity().as_number()); } static BOOST_CXX14_CONSTEXPR bool is_pos_inf(int_type v) { return (v == pos_infinity().as_number()); } static BOOST_CXX14_CONSTEXPR bool is_not_a_number(int_type v) { return (v == not_a_number().as_number()); } //! Returns either special value type or is_not_special static BOOST_CXX14_CONSTEXPR special_values to_special(int_type v) { if (is_not_a_number(v)) return not_a_date_time; if (is_neg_inf(v)) return neg_infin; if (is_pos_inf(v)) return pos_infin; return not_special; } //-3 leaves room for representations of infinity and not a date static BOOST_CONSTEXPR int_type maxcount() { return (::std::numeric_limits<int_type>::max)()-3; } BOOST_CONSTEXPR bool is_infinity() const { return (value_ == neg_infinity().as_number() || value_ == pos_infinity().as_number()); } BOOST_CONSTEXPR bool is_pos_infinity()const { return(value_ == pos_infinity().as_number()); } BOOST_CONSTEXPR bool is_neg_infinity()const { return(value_ == neg_infinity().as_number()); } BOOST_CONSTEXPR bool is_nan() const { return (value_ == not_a_number().as_number()); } BOOST_CONSTEXPR bool is_special() const { return(is_infinity() || is_nan()); } BOOST_CONSTEXPR bool operator==(const int_adapter& rhs) const { return (compare(rhs) == 0); } BOOST_CXX14_CONSTEXPR bool operator==(const int& rhs) const { if(!std::numeric_limits<int_type>::is_signed) { if(is_neg_inf(value_) && rhs == 0) { return false; } } return (compare(rhs) == 0); } BOOST_CONSTEXPR bool operator!=(const int_adapter& rhs) const { return (compare(rhs) != 0); } BOOST_CXX14_CONSTEXPR bool operator!=(const int& rhs) const { if(!std::numeric_limits<int_type>::is_signed) { if(is_neg_inf(value_) && rhs == 0) { return true; } } return (compare(rhs) != 0); } BOOST_CONSTEXPR bool operator<(const int_adapter& rhs) const { return (compare(rhs) == -1); } BOOST_CXX14_CONSTEXPR bool operator<(const int& rhs) const { // quiets compiler warnings if(!std::numeric_limits<int_type>::is_signed) { if(is_neg_inf(value_) && rhs == 0) { return true; } } return (compare(rhs) == -1); } BOOST_CONSTEXPR bool operator>(const int_adapter& rhs) const { return (compare(rhs) == 1); } BOOST_CONSTEXPR int_type as_number() const { return value_; } //! Returns either special value type or is_not_special BOOST_CONSTEXPR special_values as_special() const { return int_adapter::to_special(value_); } //creates nasty ambiguities // operator int_type() const // { // return value_; // } /*! Operator allows for adding dissimilar int_adapter types. * The return type will match that of the the calling object's type */ template<class rhs_type> BOOST_CXX14_CONSTEXPR int_adapter operator+(const int_adapter<rhs_type>& rhs) const { if(is_special() || rhs.is_special()) { if (is_nan() || rhs.is_nan()) { return int_adapter::not_a_number(); } if((is_pos_inf(value_) && rhs.is_neg_inf(rhs.as_number())) || (is_neg_inf(value_) && rhs.is_pos_inf(rhs.as_number())) ) { return int_adapter::not_a_number(); } if (is_infinity()) { return *this; } if (rhs.is_pos_inf(rhs.as_number())) { return int_adapter::pos_infinity(); } if (rhs.is_neg_inf(rhs.as_number())) { return int_adapter::neg_infinity(); } } return int_adapter<int_type>(value_ + static_cast<int_type>(rhs.as_number())); } BOOST_CXX14_CONSTEXPR int_adapter operator+(const int_type rhs) const { if(is_special()) { if (is_nan()) { return int_adapter<int_type>(not_a_number()); } if (is_infinity()) { return *this; } } return int_adapter<int_type>(value_ + rhs); } /*! Operator allows for subtracting dissimilar int_adapter types. * The return type will match that of the the calling object's type */ template<class rhs_type> BOOST_CXX14_CONSTEXPR int_adapter operator-(const int_adapter<rhs_type>& rhs)const { if(is_special() || rhs.is_special()) { if (is_nan() || rhs.is_nan()) { return int_adapter::not_a_number(); } if((is_pos_inf(value_) && rhs.is_pos_inf(rhs.as_number())) || (is_neg_inf(value_) && rhs.is_neg_inf(rhs.as_number())) ) { return int_adapter::not_a_number(); } if (is_infinity()) { return *this; } if (rhs.is_pos_inf(rhs.as_number())) { return int_adapter::neg_infinity(); } if (rhs.is_neg_inf(rhs.as_number())) { return int_adapter::pos_infinity(); } } return int_adapter<int_type>(value_ - static_cast<int_type>(rhs.as_number())); } BOOST_CXX14_CONSTEXPR int_adapter operator-(const int_type rhs) const { if(is_special()) { if (is_nan()) { return int_adapter<int_type>(not_a_number()); } if (is_infinity()) { return *this; } } return int_adapter<int_type>(value_ - rhs); } // should templatize this to be consistant with op +- BOOST_CXX14_CONSTEXPR int_adapter operator*(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { return mult_div_specials(rhs); } return int_adapter<int_type>(value_ * rhs.value_); } /*! Provided for cases when automatic conversion from * 'int' to 'int_adapter' causes incorrect results. */ BOOST_CXX14_CONSTEXPR int_adapter operator*(const int rhs) const { if(is_special()) { return mult_div_specials(rhs); } return int_adapter<int_type>(value_ * rhs); } // should templatize this to be consistant with op +- BOOST_CXX14_CONSTEXPR int_adapter operator/(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { if(is_infinity() && rhs.is_infinity()) { return int_adapter<int_type>(not_a_number()); } if(rhs != 0) { return mult_div_specials(rhs); } else { // let divide by zero blow itself up return int_adapter<int_type>(value_ / rhs.value_); //NOLINT } } return int_adapter<int_type>(value_ / rhs.value_); } /*! Provided for cases when automatic conversion from * 'int' to 'int_adapter' causes incorrect results. */ BOOST_CXX14_CONSTEXPR int_adapter operator/(const int rhs) const { if(is_special() && rhs != 0) { return mult_div_specials(rhs); } // let divide by zero blow itself up like int return int_adapter<int_type>(value_ / rhs); //NOLINT } // should templatize this to be consistant with op +- BOOST_CXX14_CONSTEXPR int_adapter operator%(const int_adapter& rhs)const { if(this->is_special() || rhs.is_special()) { if(is_infinity() && rhs.is_infinity()) { return int_adapter<int_type>(not_a_number()); } if(rhs != 0) { return mult_div_specials(rhs); } else { // let divide by zero blow itself up return int_adapter<int_type>(value_ % rhs.value_); //NOLINT } } return int_adapter<int_type>(value_ % rhs.value_); } /*! Provided for cases when automatic conversion from * 'int' to 'int_adapter' causes incorrect results. */ BOOST_CXX14_CONSTEXPR int_adapter operator%(const int rhs) const { if(is_special() && rhs != 0) { return mult_div_specials(rhs); } // let divide by zero blow itself up return int_adapter<int_type>(value_ % rhs); //NOLINT } private: int_type value_; //! returns -1, 0, 1, or 2 if 'this' is <, ==, >, or 'nan comparison' rhs BOOST_CXX14_CONSTEXPR int compare( const int_adapter& rhs ) const { if(this->is_special() || rhs.is_special()) { if(this->is_nan() || rhs.is_nan()) { if(this->is_nan() && rhs.is_nan()) { return 0; // equal } else { return 2; // nan } } if((is_neg_inf(value_) && !is_neg_inf(rhs.value_)) || (is_pos_inf(rhs.value_) && !is_pos_inf(value_)) ) { return -1; // less than } if((is_pos_inf(value_) && !is_pos_inf(rhs.value_)) || (is_neg_inf(rhs.value_) && !is_neg_inf(value_)) ) { return 1; // greater than } } if(value_ < rhs.value_) return -1; if(value_ > rhs.value_) return 1; // implied-> if(value_ == rhs.value_) return 0; } /* When multiplying and dividing with at least 1 special value * very simmilar rules apply. In those cases where the rules * are different, they are handled in the respective operator * function. */ //! Assumes at least 'this' or 'rhs' is a special value BOOST_CXX14_CONSTEXPR int_adapter mult_div_specials(const int_adapter& rhs) const { if(this->is_nan() || rhs.is_nan()) { return int_adapter<int_type>(not_a_number()); } BOOST_CONSTEXPR_OR_CONST int min_value = std::numeric_limits<int_type>::is_signed ? 0 : 1; if((*this > 0 && rhs > 0) || (*this < min_value && rhs < min_value)) { return int_adapter<int_type>(pos_infinity()); } if((*this > 0 && rhs < min_value) || (*this < min_value && rhs > 0)) { return int_adapter<int_type>(neg_infinity()); } //implied -> if(this->value_ == 0 || rhs.value_ == 0) return int_adapter<int_type>(not_a_number()); } /* Overloaded function necessary because of special * situation where int_adapter is instantiated with * 'unsigned' and func is called with negative int. * It would produce incorrect results since 'unsigned' * wraps around when initialized with a negative value */ //! Assumes 'this' is a special value BOOST_CXX14_CONSTEXPR int_adapter mult_div_specials(const int& rhs) const { if(this->is_nan()) { return int_adapter<int_type>(not_a_number()); } BOOST_CONSTEXPR_OR_CONST int min_value = std::numeric_limits<int_type>::is_signed ? 0 : 1; if((*this > 0 && rhs > 0) || (*this < min_value && rhs < 0)) { return int_adapter<int_type>(pos_infinity()); } if((*this > 0 && rhs < 0) || (*this < min_value && rhs > 0)) { return int_adapter<int_type>(neg_infinity()); } //implied -> if(this->value_ == 0 || rhs.value_ == 0) return int_adapter<int_type>(not_a_number()); } }; #ifndef BOOST_DATE_TIME_NO_LOCALE /*! Expected output is either a numeric representation * or a special values representation.<BR> * Ex. "12", "+infinity", "not-a-number", etc. */ //template<class charT = char, class traits = std::traits<charT>, typename int_type> template<class charT, class traits, typename int_type> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const int_adapter<int_type>& ia) { if(ia.is_special()) { // switch copied from date_names_put.hpp switch(ia.as_special()) { case not_a_date_time: os << "not-a-number"; break; case pos_infin: os << "+infinity"; break; case neg_infin: os << "-infinity"; break; default: os << ""; } } else { os << ia.as_number(); } return os; } #endif } } //namespace date_time #if defined(BOOST_MSVC) #pragma warning(pop) #endif #endif PK �b�[�H� � � date_iterator.hppnu �[��� #ifndef DATE_ITERATOR_HPP___ #define DATE_ITERATOR_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <iterator> namespace boost { namespace date_time { //! An iterator over dates with varying resolution (day, week, month, year, etc) enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions}; //! Base date iterator type /*! This class provides the skeleton for the creation of iterators. * New and interesting interators can be created by plugging in a new * function that derives the next value from the current state. * generation of various types of -based information. * * <b>Template Parameters</b> * * <b>date_type</b> * * The date_type is a concrete date_type. The date_type must * define a duration_type and a calendar_type. */ template<class date_type> class date_itr_base { // works, but benefit unclear at the moment // class date_itr_base : public std::iterator<std::input_iterator_tag, // date_type, void, void, void>{ public: typedef typename date_type::duration_type duration_type; typedef date_type value_type; typedef std::input_iterator_tag iterator_category; date_itr_base(date_type d) : current_(d) {} virtual ~date_itr_base() {} date_itr_base& operator++() { current_ = current_ + get_offset(current_); return *this; } date_itr_base& operator--() { current_ = current_ + get_neg_offset(current_); return *this; } virtual duration_type get_offset(const date_type& current) const=0; virtual duration_type get_neg_offset(const date_type& current) const=0; date_type operator*() {return current_;} date_type* operator->() {return ¤t_;} bool operator< (const date_type& d) {return current_ < d;} bool operator<= (const date_type& d) {return current_ <= d;} bool operator> (const date_type& d) {return current_ > d;} bool operator>= (const date_type& d) {return current_ >= d;} bool operator== (const date_type& d) {return current_ == d;} bool operator!= (const date_type& d) {return current_ != d;} private: date_type current_; }; //! Overrides the base date iterator providing hook for functors /* * <b>offset_functor</b> * * The offset functor must define a get_offset function that takes the * current point in time and calculates and offset. * */ template<class offset_functor, class date_type> class date_itr : public date_itr_base<date_type> { public: typedef typename date_type::duration_type duration_type; date_itr(date_type d, int factor=1) : date_itr_base<date_type>(d), of_(factor) {} private: virtual duration_type get_offset(const date_type& current) const { return of_.get_offset(current); } virtual duration_type get_neg_offset(const date_type& current) const { return of_.get_neg_offset(current); } offset_functor of_; }; } } //namespace date_time #endif PK �b�[�"o[� � string_parse_tree.hppnu �[��� #ifndef BOOST_DATE_TIME_STRING_PARSE_TREE___HPP__ #define BOOST_DATE_TIME_STRING_PARSE_TREE___HPP__ /* Copyright (c) 2004-2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/algorithm/string/case_conv.hpp> #include <cctype> #include <map> #include <string> #include <vector> #include <ostream> #include <iterator> #include <algorithm> namespace boost { namespace date_time { template<typename charT> struct parse_match_result { parse_match_result() : match_depth(0), current_match(PARSE_ERROR) {} typedef std::basic_string<charT> string_type; string_type remaining() const { if (match_depth == cache.size()) { return string_type(); } if (current_match == PARSE_ERROR) { return cache; } //some of the cache was used return the rest return string_type(cache, match_depth); } charT last_char() const { return cache[cache.size()-1]; } //! Returns true if more characters were parsed than was necessary /*! Should be used in conjunction with last_char() * to get the remaining character. */ bool has_remaining() const { return (cache.size() > match_depth); } // cache will hold characters that have been read from the stream string_type cache; unsigned short match_depth; short current_match; enum PARSE_STATE { PARSE_ERROR = -1 }; }; //for debug -- really only char streams... template<typename charT> std::basic_ostream<charT>& operator<<(std::basic_ostream<charT>& os, parse_match_result<charT>& mr) { os << "cm: " << mr.current_match << " C: '" << mr.cache << "' md: " << mr.match_depth << " R: " << mr.remaining(); return os; } //! Recursive data structure to allow efficient parsing of various strings /*! This class provides a quick lookup by building what amounts to a * tree data structure. It also features a match function which can * can handle nasty input interators by caching values as it recurses * the tree so that it can backtrack as needed. */ template<typename charT> struct string_parse_tree { #if BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x581) ) typedef std::multimap<charT, string_parse_tree< charT> > ptree_coll; #else typedef std::multimap<charT, string_parse_tree > ptree_coll; #endif typedef typename ptree_coll::value_type value_type; typedef typename ptree_coll::iterator iterator; typedef typename ptree_coll::const_iterator const_iterator; typedef std::basic_string<charT> string_type; typedef std::vector<std::basic_string<charT> > collection_type; typedef parse_match_result<charT> parse_match_result_type; /*! Parameter "starting_point" designates where the numbering begins. * A starting_point of zero will start the numbering at zero * (Sun=0, Mon=1, ...) were a starting_point of one starts the * numbering at one (Jan=1, Feb=2, ...). The default is zero, * negative vaules are not allowed */ string_parse_tree(collection_type names, unsigned int starting_point=0) : m_value(parse_match_result_type::PARSE_ERROR) { // iterate thru all the elements and build the tree unsigned short index = 0; while (index != names.size() ) { string_type s = boost::algorithm::to_lower_copy(names[index]); insert(s, static_cast<unsigned short>(index + starting_point)); index++; } //set the last tree node = index+1 indicating a value index++; } string_parse_tree(short value = parse_match_result_type::PARSE_ERROR) : m_value(value) {} ptree_coll m_next_chars; short m_value; void insert(const string_type& s, unsigned short value) { unsigned int i = 0; iterator ti; while(i < s.size()) { if (i==0) { if (i == (s.size()-1)) { ti = m_next_chars.insert(value_type(s[i], string_parse_tree<charT>(value))); } else { ti = m_next_chars.insert(value_type(s[i], string_parse_tree<charT>())); } } else { if (i == (s.size()-1)) { ti = ti->second.m_next_chars.insert(value_type(s[i], string_parse_tree<charT>(value))); } else { ti = ti->second.m_next_chars.insert(value_type(s[i], string_parse_tree<charT>())); } } i++; } } //! Recursive function that finds a matching string in the tree. /*! Must check match_results::has_remaining() after match() is * called. This is required so the user can determine if * stream iterator is already pointing to the expected * character or not (match() might advance sitr to next char in stream). * * A parse_match_result that has been returned from a failed match * attempt can be sent in to the match function of a different * string_parse_tree to attempt a match there. Use the iterators * for the partially consumed stream, the parse_match_result object, * and '0' for the level parameter. */ short match(std::istreambuf_iterator<charT>& sitr, std::istreambuf_iterator<charT>& stream_end, parse_match_result_type& result, unsigned int& level) const { level++; charT c; // if we conditionally advance sitr, we won't have // to consume the next character past the input bool adv_itr = true; if (level > result.cache.size()) { if (sitr == stream_end) return 0; //bail - input exhausted c = static_cast<charT>(std::tolower(*sitr)); //result.cache += c; //sitr++; } else { // if we're looking for characters from the cache, // we don't want to increment sitr adv_itr = false; c = static_cast<charT>(std::tolower(result.cache[level-1])); } const_iterator litr = m_next_chars.lower_bound(c); const_iterator uitr = m_next_chars.upper_bound(c); while (litr != uitr) { // equal if not found if(adv_itr) { sitr++; result.cache += c; } if (litr->second.m_value != -1) { // -1 is default value if (result.match_depth < level) { result.current_match = litr->second.m_value; result.match_depth = static_cast<unsigned short>(level); } litr->second.match(sitr, stream_end, result, level); level--; } else { litr->second.match(sitr, stream_end, result, level); level--; } if(level <= result.cache.size()) { adv_itr = false; } litr++; } return result.current_match; } /*! Must check match_results::has_remaining() after match() is * called. This is required so the user can determine if * stream iterator is already pointing to the expected * character or not (match() might advance sitr to next char in stream). */ parse_match_result_type match(std::istreambuf_iterator<charT>& sitr, std::istreambuf_iterator<charT>& stream_end) const { // lookup to_lower of char in tree. unsigned int level = 0; // string_type cache; parse_match_result_type result; match(sitr, stream_end, result, level); return result; } void printme(std::ostream& os, int& level) { level++; iterator itr = m_next_chars.begin(); iterator end = m_next_chars.end(); // os << "starting level: " << level << std::endl; while (itr != end) { os << "level: " << level << " node: " << itr->first << " value: " << itr->second.m_value << std::endl; itr->second.printme(os, level); itr++; } level--; } void print(std::ostream& os) { int level = 0; printme(os, level); } void printmatch(std::ostream& os, charT c) { iterator litr = m_next_chars.lower_bound(c); iterator uitr = m_next_chars.upper_bound(c); os << "matches for: " << c << std::endl; while (litr != uitr) { os << " node: " << litr->first << " value: " << litr->second.m_value << std::endl; litr++; } } }; } } //namespace #endif PK �b�[CF. F. time_parsing.hppnu �[��� #ifndef _DATE_TIME_TIME_PARSING_HPP___ #define _DATE_TIME_TIME_PARSING_HPP___ /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include "boost/tokenizer.hpp" #include "boost/lexical_cast.hpp" #include "boost/date_time/date_parsing.hpp" #include "boost/date_time/special_values_parser.hpp" #include "boost/cstdint.hpp" #include <iostream> namespace boost { namespace date_time { //! computes exponential math like 2^8 => 256, only works with positive integers //Not general purpose, but needed b/c std::pow is not available //everywhere. Hasn't been tested with negatives and zeros template<class int_type> inline int_type power(int_type base, int_type exponent) { int_type result = 1; for(int i = 0; i < exponent; ++i){ result *= base; } return result; } //! Creates a time_duration object from a delimited string /*! Expected format for string is "[-]h[h][:mm][:ss][.fff]". * If the number of fractional digits provided is greater than the * precision of the time duration type then the extra digits are * truncated. * * A negative duration will be created if the first character in * string is a '-', all other '-' will be treated as delimiters. * Accepted delimiters are "-:,.". */ template<class time_duration, class char_type> inline time_duration str_from_delimited_time_duration(const std::basic_string<char_type>& s) { unsigned short min=0, sec =0; int hour =0; bool is_neg = (s.at(0) == '-'); boost::int64_t fs=0; int pos = 0; typedef typename std::basic_string<char_type>::traits_type traits_type; typedef boost::char_separator<char_type, traits_type> char_separator_type; typedef boost::tokenizer<char_separator_type, typename std::basic_string<char_type>::const_iterator, std::basic_string<char_type> > tokenizer; typedef typename boost::tokenizer<char_separator_type, typename std::basic_string<char_type>::const_iterator, typename std::basic_string<char_type> >::iterator tokenizer_iterator; char_type sep_chars[5] = {'-',':',',','.'}; char_separator_type sep(sep_chars); tokenizer tok(s,sep); for(tokenizer_iterator beg=tok.begin(); beg!=tok.end();++beg){ switch(pos) { case 0: { hour = boost::lexical_cast<int>(*beg); break; } case 1: { min = boost::lexical_cast<unsigned short>(*beg); break; } case 2: { sec = boost::lexical_cast<unsigned short>(*beg); break; } case 3: { int digits = static_cast<int>(beg->length()); //Works around a bug in MSVC 6 library that does not support //operator>> thus meaning lexical_cast will fail to compile. #if (defined(BOOST_MSVC) && (_MSC_VER < 1300)) // msvc wouldn't compile 'time_duration::num_fractional_digits()' // (required template argument list) as a workaround a temp // time_duration object was used time_duration td(hour,min,sec,fs); int precision = td.num_fractional_digits(); // _atoi64 is an MS specific function if(digits >= precision) { // drop excess digits fs = _atoi64(beg->substr(0, precision).c_str()); } else { fs = _atoi64(beg->c_str()); } #else int precision = time_duration::num_fractional_digits(); if(digits >= precision) { // drop excess digits fs = boost::lexical_cast<boost::int64_t>(beg->substr(0, precision)); } else { fs = boost::lexical_cast<boost::int64_t>(*beg); } #endif if(digits < precision){ // trailing zeros get dropped from the string, // "1:01:01.1" would yield .000001 instead of .100000 // the power() compensates for the missing decimal places fs *= power(10, precision - digits); } break; } default: break; }//switch pos++; } if(is_neg) { return -time_duration(hour, min, sec, fs); } else { return time_duration(hour, min, sec, fs); } } //! Creates a time_duration object from a delimited string /*! Expected format for string is "[-]h[h][:mm][:ss][.fff]". * If the number of fractional digits provided is greater than the * precision of the time duration type then the extra digits are * truncated. * * A negative duration will be created if the first character in * string is a '-', all other '-' will be treated as delimiters. * Accepted delimiters are "-:,.". */ template<class time_duration> inline time_duration parse_delimited_time_duration(const std::string& s) { return str_from_delimited_time_duration<time_duration,char>(s); } //! Utility function to split appart string inline bool split(const std::string& s, char sep, std::string& first, std::string& second) { std::string::size_type sep_pos = s.find(sep); first = s.substr(0,sep_pos); if (sep_pos!=std::string::npos) second = s.substr(sep_pos+1); return true; } template<class time_type> inline time_type parse_delimited_time(const std::string& s, char sep) { typedef typename time_type::time_duration_type time_duration; typedef typename time_type::date_type date_type; //split date/time on a unique delimiter char such as ' ' or 'T' std::string date_string, tod_string; split(s, sep, date_string, tod_string); //call parse_date with first string date_type d = parse_date<date_type>(date_string); //call parse_time_duration with remaining string time_duration td = parse_delimited_time_duration<time_duration>(tod_string); //construct a time return time_type(d, td); } //! Parse time duration part of an iso time of form: [-]hhmmss[.fff...] (eg: 120259.123 is 12 hours, 2 min, 59 seconds, 123000 microseconds) template<class time_duration> inline time_duration parse_undelimited_time_duration(const std::string& s) { int precision = 0; { // msvc wouldn't compile 'time_duration::num_fractional_digits()' // (required template argument list) as a workaround, a temp // time_duration object was used time_duration tmp(0,0,0,1); precision = tmp.num_fractional_digits(); } // 'precision+1' is so we grab all digits, plus the decimal int offsets[] = {2,2,2, precision+1}; int pos = 0, sign = 0; int hours = 0; short min=0, sec=0; boost::int64_t fs=0; // increment one position if the string was "signed" if(s.at(sign) == '-') { ++sign; } // stlport choked when passing s.substr() to tokenizer // using a new string fixed the error std::string remain = s.substr(sign); /* We do not want the offset_separator to wrap the offsets, we * will never want to process more than: * 2 char, 2 char, 2 char, frac_sec length. * We *do* want the offset_separator to give us a partial for the * last characters if there were not enough provided in the input string. */ bool wrap_off = false; bool ret_part = true; boost::offset_separator osf(offsets, offsets+4, wrap_off, ret_part); typedef boost::tokenizer<boost::offset_separator, std::basic_string<char>::const_iterator, std::basic_string<char> > tokenizer; typedef boost::tokenizer<boost::offset_separator, std::basic_string<char>::const_iterator, std::basic_string<char> >::iterator tokenizer_iterator; tokenizer tok(remain, osf); for(tokenizer_iterator ti=tok.begin(); ti!=tok.end();++ti){ switch(pos) { case 0: { hours = boost::lexical_cast<int>(*ti); break; } case 1: { min = boost::lexical_cast<short>(*ti); break; } case 2: { sec = boost::lexical_cast<short>(*ti); break; } case 3: { std::string char_digits(ti->substr(1)); // digits w/no decimal int digits = static_cast<int>(char_digits.length()); //Works around a bug in MSVC 6 library that does not support //operator>> thus meaning lexical_cast will fail to compile. #if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 // _atoi64 is an MS specific function if(digits >= precision) { // drop excess digits fs = _atoi64(char_digits.substr(0, precision).c_str()); } else if(digits == 0) { fs = 0; // just in case _atoi64 doesn't like an empty string } else { fs = _atoi64(char_digits.c_str()); } #else if(digits >= precision) { // drop excess digits fs = boost::lexical_cast<boost::int64_t>(char_digits.substr(0, precision)); } else if(digits == 0) { fs = 0; // lexical_cast doesn't like empty strings } else { fs = boost::lexical_cast<boost::int64_t>(char_digits); } #endif if(digits < precision){ // trailing zeros get dropped from the string, // "1:01:01.1" would yield .000001 instead of .100000 // the power() compensates for the missing decimal places fs *= power(10, precision - digits); } break; } default: break; } pos++; } if(sign) { return -time_duration(hours, min, sec, fs); } else { return time_duration(hours, min, sec, fs); } } //! Parse time string of form YYYYMMDDThhmmss where T is delimeter between date and time template<class time_type> inline time_type parse_iso_time(const std::string& s, char sep) { typedef typename time_type::time_duration_type time_duration; typedef typename time_type::date_type date_type; typedef special_values_parser<date_type, std::string::value_type> svp_type; // given to_iso_string can produce a special value string // then from_iso_string should be able to read a special value string // the special_values_parser is expensive to set up and not thread-safe // so it cannot be static, so we need to be careful about when we use it if (svp_type::likely(s)) { typedef typename svp_type::stringstream_type ss_type; typedef typename svp_type::stream_itr_type itr_type; typedef typename svp_type::match_results mr_type; svp_type p; // expensive mr_type mr; ss_type ss(s); itr_type itr(ss); itr_type end; if (p.match(itr, end, mr)) { return time_type(static_cast<special_values>(mr.current_match)); } } //split date/time on a unique delimiter char such as ' ' or 'T' std::string date_string, tod_string; split(s, sep, date_string, tod_string); //call parse_date with first string date_type d = parse_undelimited_date<date_type>(date_string); //call parse_time_duration with remaining string time_duration td = parse_undelimited_time_duration<time_duration>(tod_string); //construct a time return time_type(d, td); } } }//namespace date_time #endif PK �b�[��&"\ \ date_formatting_locales.hppnu �[��� #ifndef DATE_TIME_DATE_FORMATTING_LOCALES_HPP___ #define DATE_TIME_DATE_FORMATTING_LOCALES_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include "boost/date_time/locale_config.hpp" // set BOOST_DATE_TIME_NO_LOCALE #ifndef BOOST_DATE_TIME_NO_LOCALE #include "boost/date_time/iso_format.hpp" #include "boost/date_time/date_names_put.hpp" #include "boost/date_time/parse_format_base.hpp" #include <boost/io/ios_state.hpp> //#include <string> #include <sstream> #include <iomanip> namespace boost { namespace date_time { //! Formats a month as as string into an ostream template<class facet_type, class charT = char> class ostream_month_formatter { public: typedef typename facet_type::month_type month_type; typedef std::basic_ostream<charT> ostream_type; //! Formats a month as as string into an output iterator static void format_month(const month_type& month, ostream_type& os, const facet_type& f) { switch (f.month_format()) { case month_as_short_string: { std::ostreambuf_iterator<charT> oitr(os); f.put_month_short(oitr, month.as_enum()); break; } case month_as_long_string: { std::ostreambuf_iterator<charT> oitr(os); f.put_month_long(oitr, month.as_enum()); break; } case month_as_integer: { boost::io::basic_ios_fill_saver<charT> ifs(os); os << std::setw(2) << std::setfill(os.widen('0')) << month.as_number(); break; } } } // format_month }; //! Formats a weekday template<class weekday_type, class facet_type, class charT = char> class ostream_weekday_formatter { public: typedef typename facet_type::month_type month_type; typedef std::basic_ostream<charT> ostream_type; //! Formats a month as as string into an output iterator static void format_weekday(const weekday_type& wd, ostream_type& os, const facet_type& f, bool as_long_string) { std::ostreambuf_iterator<charT> oitr(os); if (as_long_string) { f.put_weekday_long(oitr, wd.as_enum()); } else { f.put_weekday_short(oitr, wd.as_enum()); } } // format_weekday }; //! Convert ymd to a standard string formatting policies template<class ymd_type, class facet_type, class charT = char> class ostream_ymd_formatter { public: typedef typename ymd_type::month_type month_type; typedef ostream_month_formatter<facet_type, charT> month_formatter_type; typedef std::basic_ostream<charT> ostream_type; typedef std::basic_string<charT> foo_type; //! Convert ymd to a standard string formatting policies /*! This is standard code for handling date formatting with * year-month-day based date information. This function * uses the format_type to control whether the string will * contain separator characters, and if so what the character * will be. In addtion, it can format the month as either * an integer or a string as controled by the formatting * policy */ // static string_type ymd_to_string(ymd_type ymd) // { // std::ostringstream ss; // facet_type dnp; // ymd_put(ymd, ss, dnp); // return ss.str(); // } // Put ymd to ostream -- part of ostream refactor static void ymd_put(ymd_type ymd, ostream_type& os, const facet_type& f) { boost::io::basic_ios_fill_saver<charT> ifs(os); std::ostreambuf_iterator<charT> oitr(os); switch (f.date_order()) { case ymd_order_iso: { os << ymd.year; if (f.has_date_sep_chars()) { f.month_sep_char(oitr); } month_formatter_type::format_month(ymd.month, os, f); if (f.has_date_sep_chars()) { f.day_sep_char(oitr); } os << std::setw(2) << std::setfill(os.widen('0')) << ymd.day; break; } case ymd_order_us: { month_formatter_type::format_month(ymd.month, os, f); if (f.has_date_sep_chars()) { f.day_sep_char(oitr); } os << std::setw(2) << std::setfill(os.widen('0')) << ymd.day; if (f.has_date_sep_chars()) { f.month_sep_char(oitr); } os << ymd.year; break; } case ymd_order_dmy: { os << std::setw(2) << std::setfill(os.widen('0')) << ymd.day; if (f.has_date_sep_chars()) { f.day_sep_char(oitr); } month_formatter_type::format_month(ymd.month, os, f); if (f.has_date_sep_chars()) { f.month_sep_char(oitr); } os << ymd.year; break; } } } }; //! Convert a date to string using format policies template<class date_type, class facet_type, class charT = char> class ostream_date_formatter { public: typedef std::basic_ostream<charT> ostream_type; typedef typename date_type::ymd_type ymd_type; //! Put date into an ostream static void date_put(const date_type& d, ostream_type& os, const facet_type& f) { special_values sv = d.as_special(); if (sv == not_special) { ymd_type ymd = d.year_month_day(); ostream_ymd_formatter<ymd_type, facet_type, charT>::ymd_put(ymd, os, f); } else { // output a special value std::ostreambuf_iterator<charT> coi(os); f.put_special_value(coi, sv); } } //! Put date into an ostream static void date_put(const date_type& d, ostream_type& os) { //retrieve the local from the ostream std::locale locale = os.getloc(); if (std::has_facet<facet_type>(locale)) { const facet_type& f = std::use_facet<facet_type>(locale); date_put(d, os, f); } else { //default to something sensible if no facet installed facet_type default_facet; date_put(d, os, default_facet); } } // date_to_ostream }; //class date_formatter } } //namespace date_time #endif #endif PK �b�[D��= = date_duration.hppnu �[��� #ifndef DATE_TIME_DATE_DURATION__ #define DATE_TIME_DATE_DURATION__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/operators.hpp> #include <boost/date_time/special_defs.hpp> #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/int_adapter.hpp> namespace boost { namespace date_time { //! Duration type with date level resolution template<class duration_rep_traits> class BOOST_SYMBOL_VISIBLE date_duration : private boost::less_than_comparable1< date_duration< duration_rep_traits > , boost::equality_comparable1< date_duration< duration_rep_traits > , boost::addable1< date_duration< duration_rep_traits > , boost::subtractable1< date_duration< duration_rep_traits > , boost::dividable2< date_duration< duration_rep_traits >, int > > > > > { public: typedef typename duration_rep_traits::int_type duration_rep_type; typedef typename duration_rep_traits::impl_type duration_rep; //! Construct from a day count BOOST_CXX14_CONSTEXPR explicit date_duration(duration_rep day_count) : days_(day_count) {} /*! construct from special_values - only works when * instantiated with duration_traits_adapted */ BOOST_CXX14_CONSTEXPR date_duration(special_values sv) : days_(duration_rep::from_special(sv)) {} //! returns days_ as it's instantiated type - used for streaming BOOST_CXX14_CONSTEXPR duration_rep get_rep()const { return days_; } BOOST_CXX14_CONSTEXPR special_values as_special() const { return days_.as_special(); } BOOST_CXX14_CONSTEXPR bool is_special()const { return days_.is_special(); } //! returns days as value, not object. BOOST_CXX14_CONSTEXPR duration_rep_type days() const { return duration_rep_traits::as_number(days_); } //! Returns the smallest duration -- used by to calculate 'end' static BOOST_CXX14_CONSTEXPR date_duration unit() { return date_duration<duration_rep_traits>(1); } //! Equality BOOST_CXX14_CONSTEXPR bool operator==(const date_duration& rhs) const { return days_ == rhs.days_; } //! Less BOOST_CXX14_CONSTEXPR bool operator<(const date_duration& rhs) const { return days_ < rhs.days_; } /* For shortcut operators (+=, -=, etc) simply using * "days_ += days_" may not work. If instantiated with * an int_adapter, shortcut operators are not present, * so this will not compile */ //! Subtract another duration -- result is signed BOOST_CXX14_CONSTEXPR date_duration& operator-=(const date_duration& rhs) { //days_ -= rhs.days_; days_ = days_ - rhs.days_; return *this; } //! Add a duration -- result is signed BOOST_CXX14_CONSTEXPR date_duration& operator+=(const date_duration& rhs) { days_ = days_ + rhs.days_; return *this; } //! unary- Allows for dd = -date_duration(2); -> dd == -2 BOOST_CXX14_CONSTEXPR date_duration operator-() const { return date_duration<duration_rep_traits>(get_rep() * (-1)); } //! Division operations on a duration with an integer. BOOST_CXX14_CONSTEXPR date_duration& operator/=(int divisor) { days_ = days_ / divisor; return *this; } //! return sign information BOOST_CXX14_CONSTEXPR bool is_negative() const { return days_ < 0; } private: duration_rep days_; }; /*! Struct for instantiating date_duration with <b>NO</b> special values * functionality. Allows for transparent implementation of either * date_duration<long> or date_duration<int_adapter<long> > */ struct BOOST_SYMBOL_VISIBLE duration_traits_long { typedef long int_type; typedef long impl_type; static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i; } }; /*! Struct for instantiating date_duration <b>WITH</b> special values * functionality. Allows for transparent implementation of either * date_duration<long> or date_duration<int_adapter<long> > */ struct BOOST_SYMBOL_VISIBLE duration_traits_adapted { typedef long int_type; typedef boost::date_time::int_adapter<long> impl_type; static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i.as_number(); } }; } } //namspace date_time #endif PK �b�[ %s7�3 �3 gregorian/greg_facet.hppnu �[��� #ifndef GREGORIAN_FACET_HPP___ #define GREGORIAN_FACET_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/gregorian/gregorian_types.hpp> #include <boost/date_time/date_formatting_locales.hpp> // sets BOOST_DATE_TIME_NO_LOCALE #include <boost/date_time/gregorian/parsers.hpp> #include <boost/io/ios_state.hpp> //This file is basically commented out if locales are not supported #ifndef BOOST_DATE_TIME_NO_LOCALE #include <string> #include <memory> #include <locale> #include <iostream> #include <exception> namespace boost { namespace gregorian { //! Configuration of the output facet template struct BOOST_SYMBOL_VISIBLE greg_facet_config { typedef boost::gregorian::greg_month month_type; typedef boost::date_time::special_values special_value_enum; typedef boost::gregorian::months_of_year month_enum; typedef boost::date_time::weekdays weekday_enum; }; #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO) //! Create the base facet type for gregorian::date typedef boost::date_time::date_names_put<greg_facet_config> greg_base_facet; //! ostream operator for gregorian::date /*! Uses the date facet to determine various output parameters including: * - string values for the month (eg: Jan, Feb, Mar) (default: English) * - string values for special values (eg: not-a-date-time) (default: English) * - selection of long, short strings, or numerical month representation (default: short string) * - month day year order (default yyyy-mmm-dd) */ template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const date& d) { typedef boost::date_time::date_names_put<greg_facet_config, charT> facet_def; typedef boost::date_time::ostream_date_formatter<date, facet_def, charT> greg_ostream_formatter; greg_ostream_formatter::date_put(d, os); return os; } //! operator<< for gregorian::greg_month typically streaming: Jan, Feb, Mar... /*! Uses the date facet to determine output string as well as selection of long or short strings. * Default if no facet is installed is to output a 2 wide numeric value for the month * eg: 01 == Jan, 02 == Feb, ... 12 == Dec. */ template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const greg_month& m) { typedef boost::date_time::date_names_put<greg_facet_config, charT> facet_def; typedef boost::date_time::ostream_month_formatter<facet_def, charT> greg_month_formatter; std::locale locale = os.getloc(); if (std::has_facet<facet_def>(locale)) { const facet_def& f = std::use_facet<facet_def>(locale); greg_month_formatter::format_month(m, os, f); } else { // default to numeric boost::io::basic_ios_fill_saver<charT> ifs(os); os << std::setw(2) << std::setfill(os.widen('0')) << m.as_number(); } return os; } //! operator<< for gregorian::greg_weekday typically streaming: Sun, Mon, Tue, ... /*! Uses the date facet to determine output string as well as selection of long or short string. * Default if no facet is installed is to output a 3 char english string for the * day of the week. */ template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const greg_weekday& wd) { typedef boost::date_time::date_names_put<greg_facet_config, charT> facet_def; typedef boost::date_time::ostream_weekday_formatter<greg_weekday, facet_def, charT> greg_weekday_formatter; std::locale locale = os.getloc(); if (std::has_facet<facet_def>(locale)) { const facet_def& f = std::use_facet<facet_def>(locale); greg_weekday_formatter::format_weekday(wd, os, f, true); } else { //default to short English string eg: Sun, Mon, Tue, Wed... os << wd.as_short_string(); } return os; } //! operator<< for gregorian::date_period typical output: [2002-Jan-01/2002-Jan-31] /*! Uses the date facet to determine output string as well as selection of long * or short string fr dates. * Default if no facet is installed is to output a 3 char english string for the * day of the week. */ template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const date_period& dp) { os << '['; //TODO: facet or manipulator for periods? os << dp.begin(); os << '/'; //TODO: facet or manipulator for periods? os << dp.last(); os << ']'; return os; } template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const date_duration& dd) { //os << dd.days(); os << dd.get_rep(); return os; } //! operator<< for gregorian::partial_date. Output: "Jan 1" template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const partial_date& pd) { boost::io::basic_ios_fill_saver<charT> ifs(os); os << std::setw(2) << std::setfill(os.widen('0')) << pd.day() << ' ' << pd.month().as_short_string() ; return os; } //! operator<< for gregorian::nth_kday_of_month. Output: "first Mon of Jun" template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const nth_kday_of_month& nkd) { os << nkd.nth_week_as_str() << ' ' << nkd.day_of_week() << " of " << nkd.month().as_short_string() ; return os; } //! operator<< for gregorian::first_kday_of_month. Output: "first Mon of Jun" template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const first_kday_of_month& fkd) { os << "first " << fkd.day_of_week() << " of " << fkd.month().as_short_string() ; return os; } //! operator<< for gregorian::last_kday_of_month. Output: "last Mon of Jun" template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const last_kday_of_month& lkd) { os << "last " << lkd.day_of_week() << " of " << lkd.month().as_short_string() ; return os; } //! operator<< for gregorian::first_kday_after. Output: "first Mon after" template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const first_kday_after& fka) { os << fka.day_of_week() << " after"; return os; } //! operator<< for gregorian::first_kday_before. Output: "first Mon before" template <class charT, class traits> inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const first_kday_before& fkb) { os << fkb.day_of_week() << " before"; return os; } #endif // USE_DATE_TIME_PRE_1_33_FACET_IO /**************** Input Streaming ******************/ #if !defined(BOOST_NO_STD_ITERATOR_TRAITS) //! operator>> for gregorian::date template<class charT> inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, date& d) { std::istream_iterator<std::basic_string<charT>, charT> beg(is), eos; d = from_stream(beg, eos); return is; } #endif // BOOST_NO_STD_ITERATOR_TRAITS //! operator>> for gregorian::date_duration template<class charT> inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, date_duration& dd) { long v; is >> v; dd = date_duration(v); return is; } //! operator>> for gregorian::date_period template<class charT> inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, date_period& dp) { std::basic_string<charT> s; is >> s; dp = date_time::from_simple_string_type<date>(s); return is; } //! generates a locale with the set of gregorian name-strings of type char* BOOST_DATE_TIME_DECL std::locale generate_locale(std::locale& loc, char type); //! Returns a pointer to a facet with a default set of names (English) /* Necessary in the event an exception is thrown from op>> for * weekday or month. See comments in those functions for more info */ BOOST_DATE_TIME_DECL boost::date_time::all_date_names_put<greg_facet_config, char>* create_facet_def(char type); #ifndef BOOST_NO_STD_WSTRING //! generates a locale with the set of gregorian name-strings of type wchar_t* BOOST_DATE_TIME_DECL std::locale generate_locale(std::locale& loc, wchar_t type); //! Returns a pointer to a facet with a default set of names (English) /* Necessary in the event an exception is thrown from op>> for * weekday or month. See comments in those functions for more info */ BOOST_DATE_TIME_DECL boost::date_time::all_date_names_put<greg_facet_config, wchar_t>* create_facet_def(wchar_t type); #endif // BOOST_NO_STD_WSTRING //! operator>> for gregorian::greg_month - throws exception if invalid month given template<class charT> inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is,greg_month& m) { typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def; std::basic_string<charT> s; is >> s; if(!std::has_facet<facet_def>(is.getloc())) { std::locale loc = is.getloc(); charT a = '\0'; is.imbue(generate_locale(loc, a)); } short num = 0; try{ const facet_def& f = std::use_facet<facet_def>(is.getloc()); num = date_time::find_match(f.get_short_month_names(), f.get_long_month_names(), (greg_month::max)(), s); // greg_month spans 1..12, so max returns the array size, // which is needed by find_match } /* bad_cast will be thrown if the desired facet is not accessible * so we can generate the facet. This has the drawback of using english * names as a default. */ catch(std::bad_cast&){ charT a = '\0'; #if defined(BOOST_NO_CXX11_SMART_PTR) std::auto_ptr< const facet_def > f(create_facet_def(a)); #else std::unique_ptr< const facet_def > f(create_facet_def(a)); #endif num = date_time::find_match(f->get_short_month_names(), f->get_long_month_names(), (greg_month::max)(), s); // greg_month spans 1..12, so max returns the array size, // which is needed by find_match } ++num; // months numbered 1-12 m = greg_month(num); return is; } //! operator>> for gregorian::greg_weekday - throws exception if invalid weekday given template<class charT> inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is,greg_weekday& wd) { typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def; std::basic_string<charT> s; is >> s; if(!std::has_facet<facet_def>(is.getloc())) { std::locale loc = is.getloc(); charT a = '\0'; is.imbue(generate_locale(loc, a)); } short num = 0; try{ const facet_def& f = std::use_facet<facet_def>(is.getloc()); num = date_time::find_match(f.get_short_weekday_names(), f.get_long_weekday_names(), (greg_weekday::max)() + 1, s); // greg_weekday spans 0..6, so increment is needed // to form the array size which is needed by find_match } /* bad_cast will be thrown if the desired facet is not accessible * so we can generate the facet. This has the drawback of using english * names as a default. */ catch(std::bad_cast&){ charT a = '\0'; #if defined(BOOST_NO_CXX11_SMART_PTR) std::auto_ptr< const facet_def > f(create_facet_def(a)); #else std::unique_ptr< const facet_def > f(create_facet_def(a)); #endif num = date_time::find_match(f->get_short_weekday_names(), f->get_long_weekday_names(), (greg_weekday::max)() + 1, s); // greg_weekday spans 0..6, so increment is needed // to form the array size which is needed by find_match } wd = greg_weekday(num); // weekdays numbered 0-6 return is; } } } //namespace gregorian #endif #endif PK �b�[�F#$� � gregorian/parsers.hppnu �[��� #ifndef GREGORIAN_PARSERS_HPP___ #define GREGORIAN_PARSERS_HPP___ /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/gregorian/gregorian_types.hpp> #include <boost/date_time/date_parsing.hpp> #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/parse_format_base.hpp> #include <boost/date_time/special_defs.hpp> #include <boost/date_time/find_match.hpp> #include <string> #include <iterator> namespace boost { namespace gregorian { //! Return special_value from string argument /*! Return special_value from string argument. If argument is * not one of the special value names (defined in names.hpp), * return 'not_special' */ inline date_time::special_values special_value_from_string(const std::string& s) { static const char* const special_value_names[date_time::NumSpecialValues] = {"not-a-date-time","-infinity","+infinity","min_date_time", "max_date_time","not_special"}; short i = date_time::find_match(special_value_names, special_value_names, date_time::NumSpecialValues, s); if(i >= date_time::NumSpecialValues) { // match not found return date_time::not_special; } else { return static_cast<date_time::special_values>(i); } } //! Deprecated: Use from_simple_string inline date from_string(const std::string& s) { return date_time::parse_date<date>(s); } //! From delimited date string where with order year-month-day eg: 2002-1-25 or 2003-Jan-25 (full month name is also accepted) inline date from_simple_string(const std::string& s) { return date_time::parse_date<date>(s, date_time::ymd_order_iso); } //! From delimited date string where with order year-month-day eg: 1-25-2003 or Jan-25-2003 (full month name is also accepted) inline date from_us_string(const std::string& s) { return date_time::parse_date<date>(s, date_time::ymd_order_us); } //! From delimited date string where with order day-month-year eg: 25-1-2002 or 25-Jan-2003 (full month name is also accepted) inline date from_uk_string(const std::string& s) { return date_time::parse_date<date>(s, date_time::ymd_order_dmy); } //! From iso type date string where with order year-month-day eg: 20020125 inline date from_undelimited_string(const std::string& s) { return date_time::parse_undelimited_date<date>(s); } //! From iso type date string where with order year-month-day eg: 20020125 inline date date_from_iso_string(const std::string& s) { return date_time::parse_undelimited_date<date>(s); } #if !(defined(BOOST_NO_STD_ITERATOR_TRAITS)) //! Stream should hold a date in the form of: 2002-1-25. Month number, abbrev, or name are accepted /* Arguments passed in by-value for convertability of char[] * to iterator_type. Calls to from_stream_type are by-reference * since conversion is already done */ template<class iterator_type> inline date from_stream(iterator_type beg, iterator_type end) { if(beg == end) { return date(not_a_date_time); } typedef typename std::iterator_traits<iterator_type>::value_type value_type; return date_time::from_stream_type<date>(beg, end, value_type()); } #endif //BOOST_NO_STD_ITERATOR_TRAITS #if (defined(_MSC_VER) && (_MSC_VER < 1300)) // This function cannot be compiled with MSVC 6.0 due to internal compiler shorcomings #else //! Function to parse a date_period from a string (eg: [2003-Oct-31/2003-Dec-25]) inline date_period date_period_from_string(const std::string& s){ return date_time::from_simple_string_type<date,char>(s); } # if !defined(BOOST_NO_STD_WSTRING) //! Function to parse a date_period from a wstring (eg: [2003-Oct-31/2003-Dec-25]) inline date_period date_period_from_wstring(const std::wstring& s){ return date_time::from_simple_string_type<date,wchar_t>(s); } # endif // BOOST_NO_STD_WSTRING #endif } } //namespace gregorian #endif PK �b�[`��f f gregorian/greg_weekday.hppnu �[��� #ifndef GREG_WEEKDAY_HPP___ #define GREG_WEEKDAY_HPP___ /* Copyright (c) 2002,2003,2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/constrained_value.hpp> #include <boost/date_time/date_defs.hpp> #include <boost/date_time/compiler_config.hpp> #include <stdexcept> #include <string> namespace boost { namespace gregorian { //bring enum values into the namespace using date_time::Sunday; using date_time::Monday; using date_time::Tuesday; using date_time::Wednesday; using date_time::Thursday; using date_time::Friday; using date_time::Saturday; //! Exception that flags that a weekday number is incorrect struct BOOST_SYMBOL_VISIBLE bad_weekday : public std::out_of_range { bad_weekday() : std::out_of_range(std::string("Weekday is out of range 0..6")) {} }; typedef CV::simple_exception_policy<unsigned short, 0, 6, bad_weekday> greg_weekday_policies; typedef CV::constrained_value<greg_weekday_policies> greg_weekday_rep; //! Represent a day within a week (range 0==Sun to 6==Sat) class BOOST_SYMBOL_VISIBLE greg_weekday : public greg_weekday_rep { public: typedef boost::date_time::weekdays weekday_enum; BOOST_CXX14_CONSTEXPR greg_weekday(value_type day_of_week_num) : greg_weekday_rep(day_of_week_num) {} BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;} BOOST_CXX14_CONSTEXPR weekday_enum as_enum() const {return static_cast<weekday_enum>(value_);} //! Return a 3 digit english string of the day of week (eg: Sun) const char* as_short_string() const { static const char* const short_weekday_names[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; return short_weekday_names[value_]; } //! Return a point to a long english string representing day of week const char* as_long_string() const { static const char* const long_weekday_names[] = {"Sunday","Monday","Tuesday","Wednesday", "Thursday", "Friday", "Saturday"}; return long_weekday_names[value_]; } #ifndef BOOST_NO_STD_WSTRING //! Return a 3 digit english wchar_t string of the day of week (eg: Sun) const wchar_t* as_short_wstring() const { static const wchar_t* const w_short_weekday_names[]={L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat"}; return w_short_weekday_names[value_]; } //! Return a point to a long english wchar_t string representing day of week const wchar_t* as_long_wstring() const { static const wchar_t* const w_long_weekday_names[]= {L"Sunday",L"Monday",L"Tuesday", L"Wednesday", L"Thursday", L"Friday", L"Saturday"}; return w_long_weekday_names[value_]; } #endif // BOOST_NO_STD_WSTRING }; } } //namespace gregorian #endif PK �b�[u�} � � gregorian/greg_month.hppnu �[��� #ifndef GREG_MONTH_HPP___ #define GREG_MONTH_HPP___ /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/constrained_value.hpp> #include <boost/date_time/date_defs.hpp> #include <boost/date_time/compiler_config.hpp> #include <stdexcept> #include <string> namespace boost { namespace gregorian { typedef date_time::months_of_year months_of_year; //bring enum values into the namespace using date_time::Jan; using date_time::Feb; using date_time::Mar; using date_time::Apr; using date_time::May; using date_time::Jun; using date_time::Jul; using date_time::Aug; using date_time::Sep; using date_time::Oct; using date_time::Nov; using date_time::Dec; using date_time::NotAMonth; using date_time::NumMonths; //! Exception thrown if a greg_month is constructed with a value out of range struct BOOST_SYMBOL_VISIBLE bad_month : public std::out_of_range { bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {} }; //! Build a policy class for the greg_month_rep typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month> greg_month_policies; //! A constrained range that implements the gregorian_month rules typedef CV::constrained_value<greg_month_policies> greg_month_rep; //! Wrapper class to represent months in gregorian based calendar class BOOST_SYMBOL_VISIBLE greg_month : public greg_month_rep { public: typedef date_time::months_of_year month_enum; //! Construct a month from the months_of_year enumeration BOOST_CXX14_CONSTEXPR greg_month(month_enum theMonth) : greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {} //! Construct from a short value BOOST_CXX14_CONSTEXPR greg_month(value_type theMonth) : greg_month_rep(theMonth) {} //! Convert the value back to a short BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;} //! Returns month as number from 1 to 12 BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;} BOOST_CXX14_CONSTEXPR month_enum as_enum() const {return static_cast<month_enum>(value_);} //! Returns 3 char english string for the month ex: Jan, Feb, Mar, Apr const char* as_short_string() const { static const char* const short_month_names[NumMonths] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", "NAM"}; return short_month_names[value_-1]; } //! Returns full name of month as string in english ex: January, February const char* as_long_string() const { static const char* const long_month_names[NumMonths] = {"January","February","March","April","May","June","July","August", "September","October","November","December","NotAMonth"}; return long_month_names[value_-1]; } #ifndef BOOST_NO_STD_WSTRING //! Returns 3 wchar_t english string for the month ex: Jan, Feb, Mar, Apr const wchar_t* as_short_wstring() const { static const wchar_t* const w_short_month_names[NumMonths] = {L"Jan",L"Feb",L"Mar",L"Apr",L"May",L"Jun",L"Jul",L"Aug",L"Sep",L"Oct", L"Nov",L"Dec",L"NAM"}; return w_short_month_names[value_-1]; } //! Returns full name of month as wchar_t string in english ex: January, February const wchar_t* as_long_wstring() const { static const wchar_t* const w_long_month_names[NumMonths] = {L"January",L"February",L"March",L"April",L"May",L"June",L"July",L"August", L"September",L"October",L"November",L"December",L"NotAMonth"}; return w_long_month_names[value_-1]; } #endif // BOOST_NO_STD_WSTRING /* parameterized as_*_string functions are intended to be called * from a template function: "... as_short_string(charT c='\0');" */ const char* as_short_string(char) const { return as_short_string(); } const char* as_long_string(char) const { return as_long_string(); } #ifndef BOOST_NO_STD_WSTRING const wchar_t* as_short_string(wchar_t) const { return as_short_wstring(); } const wchar_t* as_long_string(wchar_t) const { return as_long_wstring(); } #endif // BOOST_NO_STD_WSTRING }; } } //namespace gregorian #endif PK �b�[f�6� � gregorian/greg_date.hppnu �[��� #ifndef GREG_DATE_HPP___ #define GREG_DATE_HPP___ /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ #include <boost/throw_exception.hpp> #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/date.hpp> #include <boost/date_time/special_defs.hpp> #include <boost/date_time/gregorian/greg_calendar.hpp> #include <boost/date_time/gregorian/greg_duration.hpp> namespace boost { namespace gregorian { //bring special enum values into the namespace using date_time::special_values; using date_time::not_special; using date_time::neg_infin; using date_time::pos_infin; using date_time::not_a_date_time; using date_time::max_date_time; using date_time::min_date_time; //! A date type based on gregorian_calendar /*! This class is the primary interface for programming with greogorian dates. The is a lightweight type that can be freely passed by value. All comparison operators are supported. \ingroup date_basics */ class BOOST_SYMBOL_VISIBLE date : public date_time::date<date, gregorian_calendar, date_duration> { public: typedef gregorian_calendar::year_type year_type; typedef gregorian_calendar::month_type month_type; typedef gregorian_calendar::day_type day_type; typedef gregorian_calendar::day_of_year_type day_of_year_type; typedef gregorian_calendar::ymd_type ymd_type; typedef gregorian_calendar::date_rep_type date_rep_type; typedef gregorian_calendar::date_int_type date_int_type; typedef date_duration duration_type; #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR) //! Default constructor constructs with not_a_date_time BOOST_CXX14_CONSTEXPR date(): date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(not_a_date_time)) {} #endif // DATE_TIME_NO_DEFAULT_CONSTRUCTOR //! Main constructor with year, month, day BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d) : date_time::date<date, gregorian_calendar, date_duration>(y, m, d) { if (gregorian_calendar::end_of_month_day(y, m) < d) { boost::throw_exception(bad_day_of_month(std::string("Day of month is not valid for year"))); } } //! Constructor from a ymd_type structure BOOST_CXX14_CONSTEXPR explicit date(const ymd_type& ymd) : date_time::date<date, gregorian_calendar, date_duration>(ymd) {} //! Needed copy constructor BOOST_CXX14_CONSTEXPR explicit date(const date_int_type& rhs): date_time::date<date,gregorian_calendar, date_duration>(rhs) {} //! Needed copy constructor BOOST_CXX14_CONSTEXPR explicit date(date_rep_type rhs): date_time::date<date,gregorian_calendar, date_duration>(rhs) {} //! Constructor for infinities, not a date, max and min date BOOST_CXX14_CONSTEXPR explicit date(special_values sv): date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(sv)) { if (sv == min_date_time) { *this = date(1400, 1, 1); } if (sv == max_date_time) { *this = date(9999, 12, 31); } } //!Return the Julian Day number for the date. BOOST_CXX14_CONSTEXPR date_int_type julian_day() const { ymd_type ymd = year_month_day(); return gregorian_calendar::julian_day_number(ymd); } //!Return the day of year 1..365 or 1..366 (for leap year) BOOST_CXX14_CONSTEXPR day_of_year_type day_of_year() const { date start_of_year(year(), 1, 1); unsigned short doy = static_cast<unsigned short>((*this-start_of_year).days() + 1); return day_of_year_type(doy); } //!Return the Modified Julian Day number for the date. BOOST_CXX14_CONSTEXPR date_int_type modjulian_day() const { ymd_type ymd = year_month_day(); return gregorian_calendar::modjulian_day_number(ymd); } //!Return the iso 8601 week number 1..53 BOOST_CXX14_CONSTEXPR int week_number() const { ymd_type ymd = year_month_day(); return gregorian_calendar::week_number(ymd); } //! Return the day number from the calendar BOOST_CXX14_CONSTEXPR date_int_type day_number() const { return days_; } //! Return the last day of the current month BOOST_CXX14_CONSTEXPR date end_of_month() const { ymd_type ymd = year_month_day(); unsigned short eom_day = gregorian_calendar::end_of_month_day(ymd.year, ymd.month); return date(ymd.year, ymd.month, eom_day); } friend BOOST_CXX14_CONSTEXPR bool operator==(const date& lhs, const date& rhs); private: }; inline BOOST_CXX14_CONSTEXPR bool operator==(const date& lhs, const date& rhs) { return lhs.days_ == rhs.days_; } } } //namespace gregorian #endif PK �b�[�=� gregorian/conversion.hppnu �[��� #ifndef _GREGORIAN__CONVERSION_HPP___ #define _GREGORIAN__CONVERSION_HPP___ /* Copyright (c) 2004-2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <cstring> #include <string> #include <stdexcept> #include <boost/throw_exception.hpp> #include <boost/date_time/c_time.hpp> #include <boost/date_time/special_defs.hpp> #include <boost/date_time/gregorian/gregorian_types.hpp> namespace boost { namespace gregorian { //! Converts a date to a tm struct. Throws out_of_range exception if date is a special value inline std::tm to_tm(const date& d) { if (d.is_special()) { std::string s = "tm unable to handle "; switch (d.as_special()) { case date_time::not_a_date_time: s += "not-a-date-time value"; break; case date_time::neg_infin: s += "-infinity date value"; break; case date_time::pos_infin: s += "+infinity date value"; break; default: s += "a special date value"; break; } boost::throw_exception(std::out_of_range(s)); } std::tm datetm; std::memset(&datetm, 0, sizeof(datetm)); boost::gregorian::date::ymd_type ymd = d.year_month_day(); datetm.tm_year = ymd.year - 1900; datetm.tm_mon = ymd.month - 1; datetm.tm_mday = ymd.day; datetm.tm_wday = d.day_of_week(); datetm.tm_yday = d.day_of_year() - 1; datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst return datetm; } //! Converts a tm structure into a date dropping the any time values. inline date date_from_tm(const std::tm& datetm) { return date(static_cast<unsigned short>(datetm.tm_year+1900), static_cast<unsigned short>(datetm.tm_mon+1), static_cast<unsigned short>(datetm.tm_mday)); } } } //namespace boost::gregorian #endif PK �b�[�\h�4 4 gregorian/greg_calendar.hppnu �[��� #ifndef GREGORIAN_GREGORIAN_CALENDAR_HPP__ #define GREGORIAN_GREGORIAN_CALENDAR_HPP__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ #include <boost/cstdint.hpp> #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/gregorian/greg_weekday.hpp> #include <boost/date_time/gregorian/greg_day_of_year.hpp> #include <boost/date_time/gregorian_calendar.hpp> #include <boost/date_time/gregorian/greg_ymd.hpp> #include <boost/date_time/int_adapter.hpp> namespace boost { namespace gregorian { //!An internal date representation that includes infinities, not a date typedef date_time::int_adapter<uint32_t> fancy_date_rep; //! Gregorian calendar for this implementation, hard work in the base class BOOST_SYMBOL_VISIBLE gregorian_calendar : public date_time::gregorian_calendar_base<greg_year_month_day, fancy_date_rep::int_type> { public: //! Type to hold a weekday (eg: Sunday, Monday,...) typedef greg_weekday day_of_week_type; //! Counter type from 1 to 366 for gregorian dates. typedef greg_day_of_year_rep day_of_year_type; //! Internal date representation that handles infinity, not a date typedef fancy_date_rep date_rep_type; //! Date rep implements the traits stuff as well typedef fancy_date_rep date_traits_type; private: }; } } //namespace gregorian #endif PK �b�[z���/ / gregorian/gregorian_types.hppnu �[��� #ifndef _GREGORIAN_TYPES_HPP__ #define _GREGORIAN_TYPES_HPP__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ /*! @file gregorian_types.hpp Single file header that defines most of the types for the gregorian date-time system. */ #include "boost/date_time/date.hpp" #include "boost/date_time/period.hpp" #include "boost/date_time/gregorian/greg_calendar.hpp" #include "boost/date_time/gregorian/greg_duration.hpp" #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) #include "boost/date_time/gregorian/greg_duration_types.hpp" #endif #include "boost/date_time/gregorian/greg_date.hpp" #include "boost/date_time/date_generators.hpp" #include "boost/date_time/date_clock_device.hpp" #include "boost/date_time/date_iterator.hpp" #include "boost/date_time/adjust_functors.hpp" namespace boost { //! Gregorian date system based on date_time components /*! This date system defines a full complement of types including * a date, date_duration, date_period, day_clock, and a * day_iterator. */ namespace gregorian { //! Date periods for the gregorian system /*!\ingroup date_basics */ typedef date_time::period<date, date_duration> date_period; //! A unifying date_generator base type /*! A unifying date_generator base type for: * partial_date, nth_day_of_the_week_in_month, * first_day_of_the_week_in_month, and last_day_of_the_week_in_month */ typedef date_time::year_based_generator<date> year_based_generator; //! A date generation object type typedef date_time::partial_date<date> partial_date; typedef date_time::nth_kday_of_month<date> nth_kday_of_month; typedef nth_kday_of_month nth_day_of_the_week_in_month; typedef date_time::first_kday_of_month<date> first_kday_of_month; typedef first_kday_of_month first_day_of_the_week_in_month; typedef date_time::last_kday_of_month<date> last_kday_of_month; typedef last_kday_of_month last_day_of_the_week_in_month; typedef date_time::first_kday_after<date> first_kday_after; typedef first_kday_after first_day_of_the_week_after; typedef date_time::first_kday_before<date> first_kday_before; typedef first_kday_before first_day_of_the_week_before; //! A clock to get the current day from the local computer /*!\ingroup date_basics */ typedef date_time::day_clock<date> day_clock; //! Base date_iterator type for gregorian types. /*!\ingroup date_basics */ typedef date_time::date_itr_base<date> date_iterator; //! A day level iterator /*!\ingroup date_basics */ typedef date_time::date_itr<date_time::day_functor<date>, date> day_iterator; //! A week level iterator /*!\ingroup date_basics */ typedef date_time::date_itr<date_time::week_functor<date>, date> week_iterator; //! A month level iterator /*!\ingroup date_basics */ typedef date_time::date_itr<date_time::month_functor<date>, date> month_iterator; //! A year level iterator /*!\ingroup date_basics */ typedef date_time::date_itr<date_time::year_functor<date>, date> year_iterator; // bring in these date_generator functions from date_time namespace using date_time::days_until_weekday; using date_time::days_before_weekday; using date_time::next_weekday; using date_time::previous_weekday; } } //namespace gregorian #endif PK �b�[=�� � gregorian/formatters_limited.hppnu �[��� #ifndef GREGORIAN_FORMATTERS_LIMITED_HPP___ #define GREGORIAN_FORMATTERS_LIMITED_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include "boost/date_time/gregorian/gregorian_types.hpp" #include "boost/date_time/date_formatting_limited.hpp" #include "boost/date_time/iso_format.hpp" #include "boost/date_time/date_format_simple.hpp" #include "boost/date_time/compiler_config.hpp" namespace boost { namespace gregorian { //! To YYYY-mmm-DD string where mmm 3 char month name. Example: 2002-Jan-01 /*!\ingroup date_format */ inline std::string to_simple_string(const date& d) { return date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d); } //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02] /*!\ingroup date_format */ inline std::string to_simple_string(const date_period& d) { std::string s("["); std::string d1(date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d.begin())); std::string d2(date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d.last())); return std::string("[" + d1 + "/" + d2 + "]"); } //! Date period to iso standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231 /*!\ingroup date_format */ inline std::string to_iso_string(const date_period& d) { std::string s(date_time::date_formatter<date,date_time::iso_format<char> >::date_to_string(d.begin())); return s + "/" + date_time::date_formatter<date,date_time::iso_format<char> >::date_to_string(d.last()); } //! Convert to iso extended format string CCYY-MM-DD. Example 2002-12-31 /*!\ingroup date_format */ inline std::string to_iso_extended_string(const date& d) { return date_time::date_formatter<date,date_time::iso_extended_format<char> >::date_to_string(d); } //! Convert to iso standard string YYYYMMDD. Example: 20021231 /*!\ingroup date_format */ inline std::string to_iso_string(const date& d) { return date_time::date_formatter<date,date_time::iso_format<char> >::date_to_string(d); } inline std::string to_sql_string(const date& d) { date::ymd_type ymd = d.year_month_day(); std::ostringstream ss; ss << ymd.year << "-" << std::setw(2) << std::setfill('0') << ymd.month.as_number() //solves problem with gcc 3.1 hanging << "-" << std::setw(2) << std::setfill('0') << ymd.day; return ss.str(); } } } //namespace gregorian #endif PK �b�[H�x\� � ! gregorian/greg_duration_types.hppnu �[��� #ifndef GREG_DURATION_TYPES_HPP___ #define GREG_DURATION_TYPES_HPP___ /* Copyright (c) 2004 CrystalClear Software, Inc. * Subject to Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/gregorian/greg_date.hpp> #include <boost/date_time/int_adapter.hpp> #include <boost/date_time/adjust_functors.hpp> #include <boost/date_time/date_duration_types.hpp> #include <boost/date_time/gregorian/greg_duration.hpp> namespace boost { namespace gregorian { //! config struct for additional duration types (ie months_duration<> & years_duration<>) struct BOOST_SYMBOL_VISIBLE greg_durations_config { typedef date date_type; typedef date_time::int_adapter<int> int_rep; typedef date_time::month_functor<date_type> month_adjustor_type; }; typedef date_time::months_duration<greg_durations_config> months; typedef date_time::years_duration<greg_durations_config> years; class BOOST_SYMBOL_VISIBLE weeks_duration : public date_duration { public: BOOST_CXX14_CONSTEXPR weeks_duration(duration_rep w) : date_duration(w * 7) {} BOOST_CXX14_CONSTEXPR weeks_duration(date_time::special_values sv) : date_duration(sv) {} }; typedef weeks_duration weeks; }} // namespace boost::gregorian #endif // GREG_DURATION_TYPES_HPP___ PK �b�[Ӓ$5o o gregorian/greg_day.hppnu �[��� #ifndef GREG_DAY_HPP___ #define GREG_DAY_HPP___ /* Copyright (c) 2002,2003,2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ #include <boost/date_time/constrained_value.hpp> #include <boost/date_time/compiler_config.hpp> #include <stdexcept> #include <string> namespace boost { namespace gregorian { //! Exception type for gregorian day of month (1..31) struct BOOST_SYMBOL_VISIBLE bad_day_of_month : public std::out_of_range { bad_day_of_month() : std::out_of_range(std::string("Day of month value is out of range 1..31")) {} //! Allow other classes to throw with unique string for bad day like Feb 29 bad_day_of_month(const std::string& s) : std::out_of_range(s) {} }; //! Policy class that declares error handling and day of month ranges typedef CV::simple_exception_policy<unsigned short, 1, 31, bad_day_of_month> greg_day_policies; //! Generated represetation for gregorian day of month typedef CV::constrained_value<greg_day_policies> greg_day_rep; //! Represent a day of the month (range 1 - 31) /*! This small class allows for simple conversion an integer value into a day of the month for a standard gregorian calendar. The type is automatically range checked so values outside of the range 1-31 will cause a bad_day_of_month exception */ class BOOST_SYMBOL_VISIBLE greg_day : public greg_day_rep { public: BOOST_CXX14_CONSTEXPR greg_day(value_type day_of_month) : greg_day_rep(day_of_month) {} BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;} BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;} private: }; } } //namespace gregorian #endif PK �b�["��}� � gregorian/greg_duration.hppnu �[��� #ifndef GREG_DURATION_HPP___ #define GREG_DURATION_HPP___ /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/date_duration.hpp> #include <boost/date_time/int_adapter.hpp> #include <boost/date_time/special_defs.hpp> namespace boost { namespace gregorian { //!An internal date representation that includes infinities, not a date typedef boost::date_time::duration_traits_adapted date_duration_rep; //! Durations in days for gregorian system /*! \ingroup date_basics */ class BOOST_SYMBOL_VISIBLE date_duration : public boost::date_time::date_duration< date_duration_rep > { typedef boost::date_time::date_duration< date_duration_rep > base_type; public: typedef base_type::duration_rep duration_rep; //! Construct from a day count BOOST_CXX14_CONSTEXPR explicit date_duration(duration_rep day_count = 0) : base_type(day_count) {} //! construct from special_values BOOST_CXX14_CONSTEXPR date_duration(date_time::special_values sv) : base_type(sv) {} //! Construct from another date_duration BOOST_CXX14_CONSTEXPR date_duration(const base_type& other) : base_type(other) {} // Relational operators // NOTE: Because of date_time::date_duration< T > design choice we don't use Boost.Operators here, // because we need the class to be a direct base. Either lose EBO, or define operators by hand. // The latter is more effecient. BOOST_CXX14_CONSTEXPR bool operator== (const date_duration& rhs) const { return base_type::operator== (rhs); } BOOST_CXX14_CONSTEXPR bool operator!= (const date_duration& rhs) const { return !operator== (rhs); } BOOST_CXX14_CONSTEXPR bool operator< (const date_duration& rhs) const { return base_type::operator< (rhs); } BOOST_CXX14_CONSTEXPR bool operator> (const date_duration& rhs) const { return !(base_type::operator< (rhs) || base_type::operator== (rhs)); } BOOST_CXX14_CONSTEXPR bool operator<= (const date_duration& rhs) const { return (base_type::operator< (rhs) || base_type::operator== (rhs)); } BOOST_CXX14_CONSTEXPR bool operator>= (const date_duration& rhs) const { return !base_type::operator< (rhs); } //! Subtract another duration -- result is signed BOOST_CXX14_CONSTEXPR date_duration& operator-= (const date_duration& rhs) { base_type::operator-= (rhs); return *this; } BOOST_CXX14_CONSTEXPR friend date_duration operator- (date_duration rhs, date_duration const& lhs); //! Add a duration -- result is signed BOOST_CXX14_CONSTEXPR date_duration& operator+= (const date_duration& rhs) { base_type::operator+= (rhs); return *this; } BOOST_CXX14_CONSTEXPR friend date_duration operator+ (date_duration rhs, date_duration const& lhs); //! unary- Allows for dd = -date_duration(2); -> dd == -2 BOOST_CXX14_CONSTEXPR date_duration operator- ()const { return date_duration(get_rep() * (-1)); } //! Division operations on a duration with an integer. BOOST_CXX14_CONSTEXPR date_duration& operator/= (int divisor) { base_type::operator/= (divisor); return *this; } BOOST_CXX14_CONSTEXPR friend date_duration operator/ (date_duration rhs, int lhs); //! Returns the smallest duration -- used by to calculate 'end' static BOOST_CXX14_CONSTEXPR date_duration unit() { return date_duration(base_type::unit().get_rep()); } }; inline BOOST_CXX14_CONSTEXPR date_duration operator- (date_duration rhs, date_duration const& lhs) { rhs -= lhs; return rhs; } inline BOOST_CXX14_CONSTEXPR date_duration operator+ (date_duration rhs, date_duration const& lhs) { rhs += lhs; return rhs; } inline BOOST_CXX14_CONSTEXPR date_duration operator/ (date_duration rhs, int lhs) { rhs /= lhs; return rhs; } //! Shorthand for date_duration typedef date_duration days; } } //namespace gregorian #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) #include <boost/date_time/date_duration_types.hpp> #endif #endif PK �b�[�*��o �o gregorian/gregorian_io.hppnu �[��� #ifndef DATE_TIME_GREGORIAN_IO_HPP__ #define DATE_TIME_GREGORIAN_IO_HPP__ /* Copyright (c) 2004-2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <locale> #include <iostream> #include <iterator> // i/ostreambuf_iterator #include <boost/io/ios_state.hpp> #include <boost/date_time/date_facet.hpp> #include <boost/date_time/period_parser.hpp> #include <boost/date_time/period_formatter.hpp> #include <boost/date_time/special_values_parser.hpp> #include <boost/date_time/special_values_formatter.hpp> #include <boost/date_time/gregorian/gregorian_types.hpp> #include <boost/date_time/gregorian/conversion.hpp> // to_tm will be needed in the facets namespace boost { namespace gregorian { typedef boost::date_time::period_formatter<wchar_t> wperiod_formatter; typedef boost::date_time::period_formatter<char> period_formatter; typedef boost::date_time::date_facet<date,wchar_t> wdate_facet; typedef boost::date_time::date_facet<date,char> date_facet; typedef boost::date_time::period_parser<date,char> period_parser; typedef boost::date_time::period_parser<date,wchar_t> wperiod_parser; typedef boost::date_time::special_values_formatter<char> special_values_formatter; typedef boost::date_time::special_values_formatter<wchar_t> wspecial_values_formatter; typedef boost::date_time::special_values_parser<date,char> special_values_parser; typedef boost::date_time::special_values_parser<date,wchar_t> wspecial_values_parser; typedef boost::date_time::date_input_facet<date,char> date_input_facet; typedef boost::date_time::date_input_facet<date,wchar_t> wdate_input_facet; template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::date& d) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), d); else { //instantiate a custom facet for dealing with dates since the user //has not put one in the stream so far. This is for efficiency //since we would always need to reconstruct for every date //if the locale did not already exist. Of course this will be overridden //if the user imbues at some later point. With the default settings //for the facet the resulting format will be the same as the //std::time_facet settings. custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), d); } return os; } //! input operator for date template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, date& d) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, d); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, d); } } catch(...) { // mask tells us what exceptions are turned on std::ios_base::iostate exception_mask = is.exceptions(); // if the user wants exceptions on failbit, we'll rethrow our // date_time exception & set the failbit if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} // ignore this one throw; // rethrow original exception } else { // if the user want's to fail quietly, we simply set the failbit is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::date_duration& dd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), dd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), dd); } return os; } //! input operator for date_duration template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, date_duration& dd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, dd); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, dd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::date_period& dp) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), dp); else { //instantiate a custom facet for dealing with date periods since the user //has not put one in the stream so far. This is for efficiency //since we would always need to reconstruct for every time period //if the local did not already exist. Of course this will be overridden //if the user imbues at some later point. With the default settings //for the facet the resulting format will be the same as the //std::time_facet settings. custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), dp); } return os; } //! input operator for date_period template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, date_period& dp) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, dp); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, dp); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } /********** small gregorian types **********/ template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::greg_month& gm) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), gm); else { custom_date_facet* f = new custom_date_facet();//-> 10/1074199752/32 because year & day not initialized in put(...) //custom_date_facet* f = new custom_date_facet("%B"); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), gm); } return os; } //! input operator for greg_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, greg_month& m) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, m); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, m); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::greg_weekday& gw) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), gw); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), gw); } return os; } //! input operator for greg_weekday template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, greg_weekday& wd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, wd); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, wd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } //NOTE: output operator for greg_day was not necessary //! input operator for greg_day template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, greg_day& gd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, gd); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, gd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } //NOTE: output operator for greg_year was not necessary //! input operator for greg_year template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, greg_year& gy) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, gy); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, gy); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } /********** date generator types **********/ template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::partial_date& pd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), pd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), pd); } return os; } //! input operator for partial_date template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, partial_date& pd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, pd); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, pd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::nth_day_of_the_week_in_month& nkd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), nkd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), nkd); } return os; } //! input operator for nth_day_of_the_week_in_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, nth_day_of_the_week_in_month& nday) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, nday); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, nday); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::first_day_of_the_week_in_month& fkd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), fkd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), fkd); } return os; } //! input operator for first_day_of_the_week_in_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, first_day_of_the_week_in_month& fkd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, fkd); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, fkd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::last_day_of_the_week_in_month& lkd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), lkd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), lkd); } return os; } //! input operator for last_day_of_the_week_in_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, last_day_of_the_week_in_month& lkd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, lkd); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, lkd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::first_day_of_the_week_after& fda) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) { std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), fda); } else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), fda); } return os; } //! input operator for first_day_of_the_week_after template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, first_day_of_the_week_after& fka) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, fka); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, fka); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::first_day_of_the_week_before& fdb) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) { std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), fdb); } else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), fdb); } return os; } //! input operator for first_day_of_the_week_before template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, first_day_of_the_week_before& fkb) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet_local; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet_local>(is.getloc())) { std::use_facet<date_input_facet_local>(is.getloc()).get(sit, str_end, is, fkb); } else { date_input_facet_local* f = new date_input_facet_local(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, fkb); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } } } // namespaces #endif // DATE_TIME_GREGORIAN_IO_HPP__ PK �b�[���A� � gregorian/greg_year.hppnu �[��� #ifndef GREG_YEAR_HPP___ #define GREG_YEAR_HPP___ /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/constrained_value.hpp> #include <stdexcept> #include <string> namespace boost { namespace gregorian { //! Exception type for gregorian year struct BOOST_SYMBOL_VISIBLE bad_year : public std::out_of_range { bad_year() : std::out_of_range(std::string("Year is out of valid range: 1400..9999")) {} }; //! Policy class that declares error handling gregorian year type typedef CV::simple_exception_policy<unsigned short, 1400, 9999, bad_year> greg_year_policies; //! Generated representation for gregorian year typedef CV::constrained_value<greg_year_policies> greg_year_rep; //! Represent a year (range 1400 - 9999) /*! This small class allows for simple conversion an integer value into a year for the gregorian calendar. This currently only allows a range of 1400 to 9999. Both ends of the range are a bit arbitrary at the moment, but they are the limits of current testing of the library. As such they may be increased in the future. */ class BOOST_SYMBOL_VISIBLE greg_year : public greg_year_rep { public: BOOST_CXX14_CONSTEXPR greg_year(value_type year) : greg_year_rep(year) {} BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;} }; } } //namespace gregorian #endif PK �b�[�o-�� � gregorian/formatters.hppnu �[��� #ifndef GREGORIAN_FORMATTERS_HPP___ #define GREGORIAN_FORMATTERS_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include "boost/date_time/compiler_config.hpp" #include "boost/date_time/gregorian/gregorian_types.hpp" #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) #include "boost/date_time/date_formatting_limited.hpp" #else #include "boost/date_time/date_formatting.hpp" #endif #include "boost/date_time/iso_format.hpp" #include "boost/date_time/date_format_simple.hpp" /* NOTE: "to_*_string" code for older compilers, ones that define * BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS, is located in * formatters_limited.hpp */ namespace boost { namespace gregorian { // wrapper function for to_simple_(w)string(date) template<class charT> inline std::basic_string<charT> to_simple_string_type(const date& d) { return date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d); } //! To YYYY-mmm-DD string where mmm 3 char month name. Example: 2002-Jan-01 /*!\ingroup date_format */ inline std::string to_simple_string(const date& d) { return to_simple_string_type<char>(d); } // wrapper function for to_simple_(w)string(date_period) template<class charT> inline std::basic_string<charT> to_simple_string_type(const date_period& d) { typedef std::basic_string<charT> string_type; charT b = '[', m = '/', e=']'; string_type d1(date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d.begin())); string_type d2(date_time::date_formatter<date,date_time::simple_format<charT>,charT>::date_to_string(d.last())); return string_type(b + d1 + m + d2 + e); } //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02] /*!\ingroup date_format */ inline std::string to_simple_string(const date_period& d) { return to_simple_string_type<char>(d); } // wrapper function for to_iso_(w)string(date_period) template<class charT> inline std::basic_string<charT> to_iso_string_type(const date_period& d) { charT sep = '/'; std::basic_string<charT> s(date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d.begin())); return s + sep + date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d.last()); } //! Date period to iso standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231 /*!\ingroup date_format */ inline std::string to_iso_string(const date_period& d) { return to_iso_string_type<char>(d); } // wrapper function for to_iso_extended_(w)string(date) template<class charT> inline std::basic_string<charT> to_iso_extended_string_type(const date& d) { return date_time::date_formatter<date,date_time::iso_extended_format<charT>,charT>::date_to_string(d); } //! Convert to iso extended format string CCYY-MM-DD. Example 2002-12-31 /*!\ingroup date_format */ inline std::string to_iso_extended_string(const date& d) { return to_iso_extended_string_type<char>(d); } // wrapper function for to_iso_(w)string(date) template<class charT> inline std::basic_string<charT> to_iso_string_type(const date& d) { return date_time::date_formatter<date,date_time::iso_format<charT>,charT>::date_to_string(d); } //! Convert to iso standard string YYYYMMDD. Example: 20021231 /*!\ingroup date_format */ inline std::string to_iso_string(const date& d) { return to_iso_string_type<char>(d); } // wrapper function for to_sql_(w)string(date) template<class charT> inline std::basic_string<charT> to_sql_string_type(const date& d) { date::ymd_type ymd = d.year_month_day(); std::basic_ostringstream<charT> ss; ss << ymd.year << "-" << std::setw(2) << std::setfill(ss.widen('0')) << ymd.month.as_number() //solves problem with gcc 3.1 hanging << "-" << std::setw(2) << std::setfill(ss.widen('0')) << ymd.day; return ss.str(); } inline std::string to_sql_string(const date& d) { return to_sql_string_type<char>(d); } #if !defined(BOOST_NO_STD_WSTRING) //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02] /*!\ingroup date_format */ inline std::wstring to_simple_wstring(const date_period& d) { return to_simple_string_type<wchar_t>(d); } //! To YYYY-mmm-DD string where mmm 3 char month name. Example: 2002-Jan-01 /*!\ingroup date_format */ inline std::wstring to_simple_wstring(const date& d) { return to_simple_string_type<wchar_t>(d); } //! Date period to iso standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231 /*!\ingroup date_format */ inline std::wstring to_iso_wstring(const date_period& d) { return to_iso_string_type<wchar_t>(d); } //! Convert to iso extended format string CCYY-MM-DD. Example 2002-12-31 /*!\ingroup date_format */ inline std::wstring to_iso_extended_wstring(const date& d) { return to_iso_extended_string_type<wchar_t>(d); } //! Convert to iso standard string YYYYMMDD. Example: 20021231 /*!\ingroup date_format */ inline std::wstring to_iso_wstring(const date& d) { return to_iso_string_type<wchar_t>(d); } inline std::wstring to_sql_wstring(const date& d) { return to_sql_string_type<wchar_t>(d); } #endif // BOOST_NO_STD_WSTRING } } //namespace gregorian #endif PK �b�[�Iwj� � gregorian/gregorian.hppnu �[��� #ifndef GREGORIAN_HPP__ #define GREGORIAN_HPP__ /* Copyright (c) 2002-2004 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ /*! @file gregorian.hpp Single file header that provides overall include for all elements of the gregorian date-time system. This includes the various types defined, but also other functions for formatting and parsing. */ #include "boost/date_time/compiler_config.hpp" #include "boost/date_time/gregorian/gregorian_types.hpp" #include "boost/date_time/gregorian/conversion.hpp" #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) #include "boost/date_time/gregorian/formatters_limited.hpp" #else #include "boost/date_time/gregorian/formatters.hpp" #endif #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO) #include "boost/date_time/gregorian/greg_facet.hpp" #else #include "boost/date_time/gregorian/gregorian_io.hpp" #endif // USE_DATE_TIME_PRE_1_33_FACET_IO #include "boost/date_time/gregorian/parsers.hpp" #endif PK �b�[1I�F F gregorian/greg_day_of_year.hppnu �[��� #ifndef GREG_DAY_OF_YEAR_HPP___ #define GREG_DAY_OF_YEAR_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ #include <boost/date_time/constrained_value.hpp> #include <boost/date_time/compiler_config.hpp> #include <stdexcept> #include <string> namespace boost { namespace gregorian { //! Exception type for day of year (1..366) struct BOOST_SYMBOL_VISIBLE bad_day_of_year : public std::out_of_range { bad_day_of_year() : std::out_of_range(std::string("Day of year value is out of range 1..366")) {} }; //! A day of the year range (1..366) typedef CV::simple_exception_policy<unsigned short,1,366,bad_day_of_year> greg_day_of_year_policies; //! Define a range representation type for the day of the year 1..366 typedef CV::constrained_value<greg_day_of_year_policies> greg_day_of_year_rep; } } //namespace gregorian #endif PK �b�[��/�M �M gregorian/greg_serialize.hppnu �[��� #ifndef GREGORIAN_SERIALIZE_HPP___ #define GREGORIAN_SERIALIZE_HPP___ /* Copyright (c) 2004-2005 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include "boost/date_time/gregorian/gregorian_types.hpp" #include "boost/date_time/gregorian/parsers.hpp" #include "boost/core/nvp.hpp" namespace boost { namespace gregorian { std::string to_iso_string(const date&); } namespace serialization { // A macro to split serialize functions into save & load functions. // It is here to avoid dependency on Boost.Serialization just for the // BOOST_SERIALIZATION_SPLIT_FREE macro #define BOOST_DATE_TIME_SPLIT_FREE(T) \ template<class Archive> \ inline void serialize(Archive & ar, \ T & t, \ const unsigned int file_version) \ { \ split_free(ar, t, file_version); \ } /*! Method that does serialization for gregorian::date -- splits to load/save */ BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date_duration) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date_duration::duration_rep) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::date_period) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_year) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_month) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_day) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::greg_weekday) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::partial_date) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::nth_kday_of_month) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::first_kday_of_month) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::last_kday_of_month) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::first_kday_before) BOOST_DATE_TIME_SPLIT_FREE(::boost::gregorian::first_kday_after) #undef BOOST_DATE_TIME_SPLIT_FREE //! Function to save gregorian::date objects using serialization lib /*! Dates are serialized into a string for transport and storage. * While it would be more efficient to store the internal * integer used to manipulate the dates, it is an unstable solution. */ template<class Archive> void save(Archive & ar, const ::boost::gregorian::date & d, unsigned int /* version */) { std::string ds = to_iso_string(d); ar & make_nvp("date", ds); } //! Function to load gregorian::date objects using serialization lib /*! Dates are serialized into a string for transport and storage. * While it would be more efficient to store the internal * integer used to manipulate the dates, it is an unstable solution. */ template<class Archive> void load(Archive & ar, ::boost::gregorian::date & d, unsigned int /*version*/) { std::string ds; ar & make_nvp("date", ds); try{ d = ::boost::gregorian::from_undelimited_string(ds); }catch(bad_lexical_cast&) { gregorian::special_values sv = gregorian::special_value_from_string(ds); if(sv == gregorian::not_special) { throw; // no match found, rethrow original exception } else { d = gregorian::date(sv); } } } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, ::boost::gregorian::date* dp, const unsigned int /*file_version*/) { // retrieve data from archive required to construct new // invoke inplace constructor to initialize instance of date ::new(dp) ::boost::gregorian::date(::boost::gregorian::not_a_date_time); } /**** date_duration ****/ //! Function to save gregorian::date_duration objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::date_duration & dd, unsigned int /*version*/) { typename gregorian::date_duration::duration_rep dr = dd.get_rep(); ar & make_nvp("date_duration", dr); } //! Function to load gregorian::date_duration objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::date_duration & dd, unsigned int /*version*/) { typename gregorian::date_duration::duration_rep dr(0); ar & make_nvp("date_duration", dr); dd = gregorian::date_duration(dr); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::date_duration* dd, const unsigned int /*file_version*/) { ::new(dd) gregorian::date_duration(gregorian::not_a_date_time); } /**** date_duration::duration_rep (most likely int_adapter) ****/ //! helper unction to save date_duration objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::date_duration::duration_rep & dr, unsigned int /*version*/) { typename gregorian::date_duration::duration_rep::int_type it = dr.as_number(); ar & make_nvp("date_duration_duration_rep", it); } //! helper function to load date_duration objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::date_duration::duration_rep & dr, unsigned int /*version*/) { typename gregorian::date_duration::duration_rep::int_type it(0); ar & make_nvp("date_duration_duration_rep", it); dr = gregorian::date_duration::duration_rep::int_type(it); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::date_duration::duration_rep* dr, const unsigned int /*file_version*/) { ::new(dr) gregorian::date_duration::duration_rep(0); } /**** date_period ****/ //! Function to save gregorian::date_period objects using serialization lib /*! date_period objects are broken down into 2 parts for serialization: * the begining date object and the end date object */ template<class Archive> void save(Archive & ar, const gregorian::date_period& dp, unsigned int /*version*/) { gregorian::date d1 = dp.begin(); gregorian::date d2 = dp.end(); ar & make_nvp("date_period_begin_date", d1); ar & make_nvp("date_period_end_date", d2); } //! Function to load gregorian::date_period objects using serialization lib /*! date_period objects are broken down into 2 parts for serialization: * the begining date object and the end date object */ template<class Archive> void load(Archive & ar, gregorian::date_period& dp, unsigned int /*version*/) { gregorian::date d1(gregorian::not_a_date_time); gregorian::date d2(gregorian::not_a_date_time); ar & make_nvp("date_period_begin_date", d1); ar & make_nvp("date_period_end_date", d2); dp = gregorian::date_period(d1,d2); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::date_period* dp, const unsigned int /*file_version*/) { gregorian::date d(gregorian::not_a_date_time); gregorian::date_duration dd(1); ::new(dp) gregorian::date_period(d,dd); } /**** greg_year ****/ //! Function to save gregorian::greg_year objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::greg_year& gy, unsigned int /*version*/) { unsigned short us = gy; ar & make_nvp("greg_year", us); } //! Function to load gregorian::greg_year objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::greg_year& gy, unsigned int /*version*/) { unsigned short us; ar & make_nvp("greg_year", us); gy = gregorian::greg_year(us); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::greg_year* gy, const unsigned int /*file_version*/) { ::new(gy) gregorian::greg_year(1900); } /**** greg_month ****/ //! Function to save gregorian::greg_month objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::greg_month& gm, unsigned int /*version*/) { unsigned short us = gm.as_number(); ar & make_nvp("greg_month", us); } //! Function to load gregorian::greg_month objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::greg_month& gm, unsigned int /*version*/) { unsigned short us; ar & make_nvp("greg_month", us); gm = gregorian::greg_month(us); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::greg_month* gm, const unsigned int /*file_version*/) { ::new(gm) gregorian::greg_month(1); } /**** greg_day ****/ //! Function to save gregorian::greg_day objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::greg_day& gd, unsigned int /*version*/) { unsigned short us = gd.as_number(); ar & make_nvp("greg_day", us); } //! Function to load gregorian::greg_day objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::greg_day& gd, unsigned int /*version*/) { unsigned short us; ar & make_nvp("greg_day", us); gd = gregorian::greg_day(us); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::greg_day* gd, const unsigned int /*file_version*/) { ::new(gd) gregorian::greg_day(1); } /**** greg_weekday ****/ //! Function to save gregorian::greg_weekday objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::greg_weekday& gd, unsigned int /*version*/) { unsigned short us = gd.as_number(); ar & make_nvp("greg_weekday", us); } //! Function to load gregorian::greg_weekday objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::greg_weekday& gd, unsigned int /*version*/) { unsigned short us; ar & make_nvp("greg_weekday", us); gd = gregorian::greg_weekday(us); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::greg_weekday* gd, const unsigned int /*file_version*/) { ::new(gd) gregorian::greg_weekday(1); } /**** date_generators ****/ /**** partial_date ****/ //! Function to save gregorian::partial_date objects using serialization lib /*! partial_date objects are broken down into 2 parts for serialization: * the day (typically greg_day) and month (typically greg_month) objects */ template<class Archive> void save(Archive & ar, const gregorian::partial_date& pd, unsigned int /*version*/) { gregorian::greg_day gd(pd.day()); gregorian::greg_month gm(pd.month().as_number()); ar & make_nvp("partial_date_day", gd); ar & make_nvp("partial_date_month", gm); } //! Function to load gregorian::partial_date objects using serialization lib /*! partial_date objects are broken down into 2 parts for serialization: * the day (greg_day) and month (greg_month) objects */ template<class Archive> void load(Archive & ar, gregorian::partial_date& pd, unsigned int /*version*/) { gregorian::greg_day gd(1); gregorian::greg_month gm(1); ar & make_nvp("partial_date_day", gd); ar & make_nvp("partial_date_month", gm); pd = gregorian::partial_date(gd,gm); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::partial_date* pd, const unsigned int /*file_version*/) { gregorian::greg_month gm(1); gregorian::greg_day gd(1); ::new(pd) gregorian::partial_date(gd,gm); } /**** nth_kday_of_month ****/ //! Function to save nth_day_of_the_week_in_month objects using serialization lib /*! nth_day_of_the_week_in_month objects are broken down into 3 parts for * serialization: the week number, the day of the week, and the month */ template<class Archive> void save(Archive & ar, const gregorian::nth_kday_of_month& nkd, unsigned int /*version*/) { typename gregorian::nth_kday_of_month::week_num wn(nkd.nth_week()); typename gregorian::nth_kday_of_month::day_of_week_type d(nkd.day_of_week().as_number()); typename gregorian::nth_kday_of_month::month_type m(nkd.month().as_number()); ar & make_nvp("nth_kday_of_month_week_num", wn); ar & make_nvp("nth_kday_of_month_day_of_week", d); ar & make_nvp("nth_kday_of_month_month", m); } //! Function to load nth_day_of_the_week_in_month objects using serialization lib /*! nth_day_of_the_week_in_month objects are broken down into 3 parts for * serialization: the week number, the day of the week, and the month */ template<class Archive> void load(Archive & ar, gregorian::nth_kday_of_month& nkd, unsigned int /*version*/) { typename gregorian::nth_kday_of_month::week_num wn(gregorian::nth_kday_of_month::first); typename gregorian::nth_kday_of_month::day_of_week_type d(gregorian::Monday); typename gregorian::nth_kday_of_month::month_type m(gregorian::Jan); ar & make_nvp("nth_kday_of_month_week_num", wn); ar & make_nvp("nth_kday_of_month_day_of_week", d); ar & make_nvp("nth_kday_of_month_month", m); nkd = gregorian::nth_kday_of_month(wn,d,m); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::nth_kday_of_month* nkd, const unsigned int /*file_version*/) { // values used are not significant ::new(nkd) gregorian::nth_kday_of_month(gregorian::nth_kday_of_month::first, gregorian::Monday,gregorian::Jan); } /**** first_kday_of_month ****/ //! Function to save first_day_of_the_week_in_month objects using serialization lib /*! first_day_of_the_week_in_month objects are broken down into 2 parts for * serialization: the day of the week, and the month */ template<class Archive> void save(Archive & ar, const gregorian::first_kday_of_month& fkd, unsigned int /*version*/) { typename gregorian::first_kday_of_month::day_of_week_type d(fkd.day_of_week().as_number()); typename gregorian::first_kday_of_month::month_type m(fkd.month().as_number()); ar & make_nvp("first_kday_of_month_day_of_week", d); ar & make_nvp("first_kday_of_month_month", m); } //! Function to load first_day_of_the_week_in_month objects using serialization lib /*! first_day_of_the_week_in_month objects are broken down into 2 parts for * serialization: the day of the week, and the month */ template<class Archive> void load(Archive & ar, gregorian::first_kday_of_month& fkd, unsigned int /*version*/) { typename gregorian::first_kday_of_month::day_of_week_type d(gregorian::Monday); typename gregorian::first_kday_of_month::month_type m(gregorian::Jan); ar & make_nvp("first_kday_of_month_day_of_week", d); ar & make_nvp("first_kday_of_month_month", m); fkd = gregorian::first_kday_of_month(d,m); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::first_kday_of_month* fkd, const unsigned int /*file_version*/) { // values used are not significant ::new(fkd) gregorian::first_kday_of_month(gregorian::Monday,gregorian::Jan); } /**** last_kday_of_month ****/ //! Function to save last_day_of_the_week_in_month objects using serialization lib /*! last_day_of_the_week_in_month objects are broken down into 2 parts for * serialization: the day of the week, and the month */ template<class Archive> void save(Archive & ar, const gregorian::last_kday_of_month& lkd, unsigned int /*version*/) { typename gregorian::last_kday_of_month::day_of_week_type d(lkd.day_of_week().as_number()); typename gregorian::last_kday_of_month::month_type m(lkd.month().as_number()); ar & make_nvp("last_kday_of_month_day_of_week", d); ar & make_nvp("last_kday_of_month_month", m); } //! Function to load last_day_of_the_week_in_month objects using serialization lib /*! last_day_of_the_week_in_month objects are broken down into 2 parts for * serialization: the day of the week, and the month */ template<class Archive> void load(Archive & ar, gregorian::last_kday_of_month& lkd, unsigned int /*version*/) { typename gregorian::last_kday_of_month::day_of_week_type d(gregorian::Monday); typename gregorian::last_kday_of_month::month_type m(gregorian::Jan); ar & make_nvp("last_kday_of_month_day_of_week", d); ar & make_nvp("last_kday_of_month_month", m); lkd = gregorian::last_kday_of_month(d,m); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::last_kday_of_month* lkd, const unsigned int /*file_version*/) { // values used are not significant ::new(lkd) gregorian::last_kday_of_month(gregorian::Monday,gregorian::Jan); } /**** first_kday_before ****/ //! Function to save first_day_of_the_week_before objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::first_kday_before& fkdb, unsigned int /*version*/) { typename gregorian::first_kday_before::day_of_week_type d(fkdb.day_of_week().as_number()); ar & make_nvp("first_kday_before_day_of_week", d); } //! Function to load first_day_of_the_week_before objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::first_kday_before& fkdb, unsigned int /*version*/) { typename gregorian::first_kday_before::day_of_week_type d(gregorian::Monday); ar & make_nvp("first_kday_before_day_of_week", d); fkdb = gregorian::first_kday_before(d); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::first_kday_before* fkdb, const unsigned int /*file_version*/) { // values used are not significant ::new(fkdb) gregorian::first_kday_before(gregorian::Monday); } /**** first_kday_after ****/ //! Function to save first_day_of_the_week_after objects using serialization lib template<class Archive> void save(Archive & ar, const gregorian::first_kday_after& fkda, unsigned int /*version*/) { typename gregorian::first_kday_after::day_of_week_type d(fkda.day_of_week().as_number()); ar & make_nvp("first_kday_after_day_of_week", d); } //! Function to load first_day_of_the_week_after objects using serialization lib template<class Archive> void load(Archive & ar, gregorian::first_kday_after& fkda, unsigned int /*version*/) { typename gregorian::first_kday_after::day_of_week_type d(gregorian::Monday); ar & make_nvp("first_kday_after_day_of_week", d); fkda = gregorian::first_kday_after(d); } //!override needed b/c no default constructor template<class Archive> inline void load_construct_data(Archive & /*ar*/, gregorian::first_kday_after* fkda, const unsigned int /*file_version*/) { // values used are not significant ::new(fkda) gregorian::first_kday_after(gregorian::Monday); } } // namespace serialization } // namespace boost #endif PK �b�[���Y Y gregorian/greg_ymd.hppnu �[��� #ifndef DATE_TIME_GREG_YMD_HPP__ #define DATE_TIME_GREG_YMD_HPP__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ #include "boost/date_time/year_month_day.hpp" #include "boost/date_time/special_defs.hpp" #include "boost/date_time/gregorian/greg_day.hpp" #include "boost/date_time/gregorian/greg_year.hpp" #include "boost/date_time/gregorian/greg_month.hpp" namespace boost { namespace gregorian { typedef date_time::year_month_day_base<greg_year, greg_month, greg_day> greg_year_month_day; } } //namespace gregorian #endif PK �b�[���=[# [# time_system_counted.hppnu �[��� #ifndef DATE_TIME_TIME_SYSTEM_COUNTED_HPP #define DATE_TIME_TIME_SYSTEM_COUNTED_HPP /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/time_defs.hpp> #include <boost/date_time/special_defs.hpp> #include <string> namespace boost { namespace date_time { //! Time representation that uses a single integer count template<class config> struct counted_time_rep { typedef typename config::int_type int_type; typedef typename config::date_type date_type; typedef typename config::impl_type impl_type; typedef typename date_type::duration_type date_duration_type; typedef typename date_type::calendar_type calendar_type; typedef typename date_type::ymd_type ymd_type; typedef typename config::time_duration_type time_duration_type; typedef typename config::resolution_traits resolution_traits; BOOST_CXX14_CONSTEXPR counted_time_rep(const date_type& d, const time_duration_type& time_of_day) : time_count_(1) { if(d.is_infinity() || d.is_not_a_date() || time_of_day.is_special()) { time_count_ = time_of_day.get_rep() + d.day_count(); //std::cout << time_count_ << std::endl; } else { time_count_ = (d.day_number() * frac_sec_per_day()) + time_of_day.ticks(); } } BOOST_CXX14_CONSTEXPR explicit counted_time_rep(int_type count) : time_count_(count) {} BOOST_CXX14_CONSTEXPR explicit counted_time_rep(impl_type count) : time_count_(count) {} BOOST_CXX14_CONSTEXPR date_type date() const { if(time_count_.is_special()) { return date_type(time_count_.as_special()); } else { typename calendar_type::date_int_type dc = static_cast<typename calendar_type::date_int_type>(day_count()); //std::cout << "time_rep here:" << dc << std::endl; ymd_type ymd = calendar_type::from_day_number(dc); return date_type(ymd); } } //int_type day_count() const BOOST_CXX14_CONSTEXPR unsigned long day_count() const { /* resolution_traits::as_number returns a boost::int64_t & * frac_sec_per_day is also a boost::int64_t so, naturally, * the division operation returns a boost::int64_t. * The static_cast to an unsigned long is ok (results in no data loss) * because frac_sec_per_day is either the number of * microseconds per day, or the number of nanoseconds per day. * Worst case scenario: resolution_traits::as_number returns the * maximum value an int64_t can hold and frac_sec_per_day * is microseconds per day (lowest possible value). * The division operation will then return a value of 106751991 - * easily fitting in an unsigned long. */ return static_cast<unsigned long>(resolution_traits::as_number(time_count_) / frac_sec_per_day()); } BOOST_CXX14_CONSTEXPR int_type time_count() const { return resolution_traits::as_number(time_count_); } BOOST_CXX14_CONSTEXPR int_type tod() const { return resolution_traits::as_number(time_count_) % frac_sec_per_day(); } static BOOST_CXX14_CONSTEXPR int_type frac_sec_per_day() { int_type seconds_per_day = 60*60*24; int_type fractional_sec_per_sec(resolution_traits::res_adjust()); return seconds_per_day*fractional_sec_per_sec; } BOOST_CXX14_CONSTEXPR bool is_pos_infinity()const { return impl_type::is_pos_inf(time_count_.as_number()); } BOOST_CXX14_CONSTEXPR bool is_neg_infinity()const { return impl_type::is_neg_inf(time_count_.as_number()); } BOOST_CXX14_CONSTEXPR bool is_not_a_date_time()const { return impl_type::is_not_a_number(time_count_.as_number()); } BOOST_CXX14_CONSTEXPR bool is_special()const { return time_count_.is_special(); } BOOST_CXX14_CONSTEXPR impl_type get_rep()const { return time_count_; } private: impl_type time_count_; }; //! An unadjusted time system implementation. template<class time_rep> class counted_time_system { public: typedef time_rep time_rep_type; typedef typename time_rep_type::impl_type impl_type; typedef typename time_rep_type::time_duration_type time_duration_type; typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type; typedef typename time_rep_type::date_type date_type; typedef typename time_rep_type::date_duration_type date_duration_type; template<class T> static BOOST_CXX14_CONSTEXPR void unused_var(const T&) {} static BOOST_CXX14_CONSTEXPR time_rep_type get_time_rep(const date_type& day, const time_duration_type& tod, date_time::dst_flags dst=not_dst) { unused_var(dst); return time_rep_type(day, tod); } static BOOST_CXX14_CONSTEXPR time_rep_type get_time_rep(special_values sv) { switch (sv) { case not_a_date_time: return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); case pos_infin: return time_rep_type(date_type(pos_infin), time_duration_type(pos_infin)); case neg_infin: return time_rep_type(date_type(neg_infin), time_duration_type(neg_infin)); case max_date_time: { time_duration_type td = time_duration_type(24,0,0,0) - time_duration_type(0,0,0,1); return time_rep_type(date_type(max_date_time), td); } case min_date_time: return time_rep_type(date_type(min_date_time), time_duration_type(0,0,0,0)); default: return time_rep_type(date_type(not_a_date_time), time_duration_type(not_a_date_time)); } } static BOOST_CXX14_CONSTEXPR date_type get_date(const time_rep_type& val) { return val.date(); } static BOOST_CXX14_CONSTEXPR time_duration_type get_time_of_day(const time_rep_type& val) { if(val.is_special()) { return time_duration_type(val.get_rep().as_special()); } else{ return time_duration_type(0,0,0,val.tod()); } } static std::string zone_name(const time_rep_type&) { return ""; } static BOOST_CXX14_CONSTEXPR bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs) { return (lhs.time_count() == rhs.time_count()); } static BOOST_CXX14_CONSTEXPR bool is_less(const time_rep_type& lhs, const time_rep_type& rhs) { return (lhs.time_count() < rhs.time_count()); } static BOOST_CXX14_CONSTEXPR time_rep_type add_days(const time_rep_type& base, const date_duration_type& dd) { if(base.is_special() || dd.is_special()) { return(time_rep_type(base.get_rep() + dd.get_rep())); } else { return time_rep_type(base.time_count() + (dd.days() * time_rep_type::frac_sec_per_day())); } } static BOOST_CXX14_CONSTEXPR time_rep_type subtract_days(const time_rep_type& base, const date_duration_type& dd) { if(base.is_special() || dd.is_special()) { return(time_rep_type(base.get_rep() - dd.get_rep())); } else{ return time_rep_type(base.time_count() - (dd.days() * time_rep_type::frac_sec_per_day())); } } static BOOST_CXX14_CONSTEXPR time_rep_type subtract_time_duration(const time_rep_type& base, const time_duration_type& td) { if(base.is_special() || td.is_special()) { return(time_rep_type(base.get_rep() - td.get_rep())); } else { return time_rep_type(base.time_count() - td.ticks()); } } static BOOST_CXX14_CONSTEXPR time_rep_type add_time_duration(const time_rep_type& base, time_duration_type td) { if(base.is_special() || td.is_special()) { return(time_rep_type(base.get_rep() + td.get_rep())); } else { return time_rep_type(base.time_count() + td.ticks()); } } static BOOST_CXX14_CONSTEXPR time_duration_type subtract_times(const time_rep_type& lhs, const time_rep_type& rhs) { if(lhs.is_special() || rhs.is_special()) { return(time_duration_type( impl_type::to_special((lhs.get_rep() - rhs.get_rep()).as_number()))); } else { fractional_seconds_type fs = lhs.time_count() - rhs.time_count(); return time_duration_type(0,0,0,fs); } } }; } } //namespace date_time #endif PK �b�[2LĽ � date.hppnu �[��� #ifndef DATE_TIME_DATE_HPP___ #define DATE_TIME_DATE_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date$ */ #include <boost/operators.hpp> #include <boost/date_time/compiler_config.hpp> #include <boost/date_time/year_month_day.hpp> #include <boost/date_time/special_defs.hpp> namespace boost { namespace date_time { //!Representation of timepoint at the one day level resolution. /*! The date template represents an interface shell for a date class that is based on a year-month-day system such as the gregorian or iso systems. It provides basic operations to enable calculation and comparisons. <b>Theory</b> This date representation fundamentally departs from the C tm struct approach. The goal for this type is to provide efficient date operations (add, subtract) and storage (minimize space to represent) in a concrete class. Thus, the date uses a count internally to represent a particular date. The calendar parameter defines the policies for converting the the year-month-day and internal counted form here. Applications that need to perform heavy formatting of the same date repeatedly will perform better by using the year-month-day representation. Internally the date uses a day number to represent the date. This is a monotonic time representation. This representation allows for fast comparison as well as simplifying the creation of writing numeric operations. Essentially, the internal day number is like adjusted julian day. The adjustment is determined by the Epoch date which is represented as day 1 of the calendar. Day 0 is reserved for negative infinity so that any actual date is automatically greater than negative infinity. When a date is constructed from a date or formatted for output, the appropriate conversions are applied to create the year, month, day representations. */ template<class T, class calendar, class duration_type_> class BOOST_SYMBOL_VISIBLE date : private boost::less_than_comparable<T , boost::equality_comparable<T > > { public: typedef T date_type; typedef calendar calendar_type; typedef typename calendar::date_traits_type traits_type; typedef duration_type_ duration_type; typedef typename calendar::year_type year_type; typedef typename calendar::month_type month_type; typedef typename calendar::day_type day_type; typedef typename calendar::ymd_type ymd_type; typedef typename calendar::date_rep_type date_rep_type; typedef typename calendar::date_int_type date_int_type; typedef typename calendar::day_of_week_type day_of_week_type; BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d) : days_(calendar::day_number(ymd_type(y, m, d))) {} BOOST_CXX14_CONSTEXPR date(const ymd_type& ymd) : days_(calendar::day_number(ymd)) {} //let the compiler write copy, assignment, and destructor BOOST_CXX14_CONSTEXPR year_type year() const { ymd_type ymd = calendar::from_day_number(days_); return ymd.year; } BOOST_CXX14_CONSTEXPR month_type month() const { ymd_type ymd = calendar::from_day_number(days_); return ymd.month; } BOOST_CXX14_CONSTEXPR day_type day() const { ymd_type ymd = calendar::from_day_number(days_); return ymd.day; } BOOST_CXX14_CONSTEXPR day_of_week_type day_of_week() const { ymd_type ymd = calendar::from_day_number(days_); return calendar::day_of_week(ymd); } BOOST_CXX14_CONSTEXPR ymd_type year_month_day() const { return calendar::from_day_number(days_); } BOOST_CONSTEXPR bool operator<(const date_type& rhs) const { return days_ < rhs.days_; } BOOST_CONSTEXPR bool operator==(const date_type& rhs) const { return days_ == rhs.days_; } //! check to see if date is a special value BOOST_CONSTEXPR bool is_special()const { return(is_not_a_date() || is_infinity()); } //! check to see if date is not a value BOOST_CONSTEXPR bool is_not_a_date() const { return traits_type::is_not_a_number(days_); } //! check to see if date is one of the infinity values BOOST_CONSTEXPR bool is_infinity() const { return traits_type::is_inf(days_); } //! check to see if date is greater than all possible dates BOOST_CONSTEXPR bool is_pos_infinity() const { return traits_type::is_pos_inf(days_); } //! check to see if date is greater than all possible dates BOOST_CONSTEXPR bool is_neg_infinity() const { return traits_type::is_neg_inf(days_); } //! return as a special value or a not_special if a normal date BOOST_CXX14_CONSTEXPR special_values as_special() const { return traits_type::to_special(days_); } BOOST_CXX14_CONSTEXPR duration_type operator-(const date_type& d) const { if (!this->is_special() && !d.is_special()) { // The duration underlying type may be wider than the date underlying type. // Thus we calculate the difference in terms of two durations from some common fixed base date. typedef typename duration_type::duration_rep_type duration_rep_type; return duration_type(static_cast< duration_rep_type >(days_) - static_cast< duration_rep_type >(d.days_)); } else { // In this case the difference will be a special value, too date_rep_type val = date_rep_type(days_) - date_rep_type(d.days_); return duration_type(val.as_special()); } } BOOST_CXX14_CONSTEXPR date_type operator-(const duration_type& dd) const { if(dd.is_special()) { return date_type(date_rep_type(days_) - dd.get_rep()); } return date_type(date_rep_type(days_) - static_cast<date_int_type>(dd.days())); } BOOST_CXX14_CONSTEXPR date_type operator-=(const duration_type& dd) { *this = *this - dd; return date_type(days_); } BOOST_CONSTEXPR date_rep_type day_count() const { return days_; } //allow internal access from operators BOOST_CXX14_CONSTEXPR date_type operator+(const duration_type& dd) const { if(dd.is_special()) { return date_type(date_rep_type(days_) + dd.get_rep()); } return date_type(date_rep_type(days_) + static_cast<date_int_type>(dd.days())); } BOOST_CXX14_CONSTEXPR date_type operator+=(const duration_type& dd) { *this = *this + dd; return date_type(days_); } //see reference protected: /*! This is a private constructor which allows for the creation of new dates. It is not exposed to users since that would require class users to understand the inner workings of the date class. */ BOOST_CONSTEXPR explicit date(date_int_type days) : days_(days) {} BOOST_CXX14_CONSTEXPR explicit date(date_rep_type days) : days_(days.as_number()) {} date_int_type days_; }; } } // namespace date_time #endif PK �b�[G�y y special_defs.hppnu �[��� #ifndef DATE_TIME_SPECIAL_DEFS_HPP__ #define DATE_TIME_SPECIAL_DEFS_HPP__ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland * $Date$ */ namespace boost { namespace date_time { enum special_values {not_a_date_time, neg_infin, pos_infin, min_date_time, max_date_time, not_special, NumSpecialValues}; } } //namespace date_time #endif PK �b�[��B B &