File indexing completed on 2025-01-18 09:30:40
0001 #ifndef DATE_TIME_TIME_SYSTEM_SPLIT_HPP
0002 #define DATE_TIME_TIME_SYSTEM_SPLIT_HPP
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <string>
0014 #include <boost/cstdint.hpp>
0015 #include <boost/date_time/compiler_config.hpp>
0016 #include <boost/date_time/time_defs.hpp>
0017 #include <boost/date_time/special_defs.hpp>
0018 #include <boost/date_time/wrapping_int.hpp>
0019
0020 namespace boost {
0021 namespace date_time {
0022
0023
0024 #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT))
0025 template<typename config, boost::int32_t ticks_per_second>
0026 #else
0027 template<typename config>
0028 #endif
0029 class split_timedate_system
0030 {
0031 public:
0032 typedef typename config::time_rep_type time_rep_type;
0033 typedef typename config::date_type date_type;
0034 typedef typename config::time_duration_type time_duration_type;
0035 typedef typename config::date_duration_type date_duration_type;
0036 typedef typename config::int_type int_type;
0037 typedef typename config::resolution_traits resolution_traits;
0038
0039
0040 #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT))
0041 typedef date_time::wrapping_int<int_type, INT64_C(86400) * ticks_per_second > wrap_int_type;
0042 #else
0043 private:
0044 BOOST_STATIC_CONSTANT(int_type, ticks_per_day = INT64_C(86400) * config::tick_per_second);
0045 public:
0046 # if BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0X581) )
0047 typedef date_time::wrapping_int< split_timedate_system::int_type, split_timedate_system::ticks_per_day> wrap_int_type;
0048 # else
0049 typedef date_time::wrapping_int<int_type, ticks_per_day> wrap_int_type;
0050 #endif
0051 #endif
0052
0053 static
0054 BOOST_CXX14_CONSTEXPR
0055 time_rep_type get_time_rep(special_values sv)
0056 {
0057 switch (sv) {
0058 case not_a_date_time:
0059 return time_rep_type(date_type(not_a_date_time),
0060 time_duration_type(not_a_date_time));
0061 case pos_infin:
0062 return time_rep_type(date_type(pos_infin),
0063 time_duration_type(pos_infin));
0064 case neg_infin:
0065 return time_rep_type(date_type(neg_infin),
0066 time_duration_type(neg_infin));
0067 case max_date_time: {
0068 time_duration_type td = time_duration_type(24,0,0,0) - time_duration_type(0,0,0,1);
0069 return time_rep_type(date_type(max_date_time), td);
0070 }
0071 case min_date_time:
0072 return time_rep_type(date_type(min_date_time), time_duration_type(0,0,0,0));
0073
0074 default:
0075 return time_rep_type(date_type(not_a_date_time),
0076 time_duration_type(not_a_date_time));
0077
0078 }
0079
0080 }
0081
0082 static
0083 BOOST_CXX14_CONSTEXPR
0084 time_rep_type get_time_rep(const date_type& day,
0085 const time_duration_type& tod,
0086 date_time::dst_flags = not_dst)
0087 {
0088 if(day.is_special() || tod.is_special()) {
0089 if(day.is_not_a_date() || tod.is_not_a_date_time()) {
0090 return time_rep_type(date_type(not_a_date_time),
0091 time_duration_type(not_a_date_time));
0092 }
0093 else if(day.is_pos_infinity()) {
0094 if(tod.is_neg_infinity()) {
0095 return time_rep_type(date_type(not_a_date_time),
0096 time_duration_type(not_a_date_time));
0097 }
0098 else {
0099 return time_rep_type(day, time_duration_type(pos_infin));
0100 }
0101 }
0102 else if(day.is_neg_infinity()) {
0103 if(tod.is_pos_infinity()) {
0104 return time_rep_type(date_type(not_a_date_time),
0105 time_duration_type(not_a_date_time));
0106 }
0107 else {
0108 return time_rep_type(day, time_duration_type(neg_infin));
0109 }
0110 }
0111 else if(tod.is_pos_infinity()) {
0112 if(day.is_neg_infinity()) {
0113 return time_rep_type(date_type(not_a_date_time),
0114 time_duration_type(not_a_date_time));
0115 }
0116 else {
0117 return time_rep_type(date_type(pos_infin), tod);
0118 }
0119 }
0120 else if(tod.is_neg_infinity()) {
0121 if(day.is_pos_infinity()) {
0122 return time_rep_type(date_type(not_a_date_time),
0123 time_duration_type(not_a_date_time));
0124 }
0125 else {
0126 return time_rep_type(date_type(neg_infin), tod);
0127 }
0128 }
0129 }
0130 return time_rep_type(day, tod);
0131 }
0132 static BOOST_CONSTEXPR date_type get_date(const time_rep_type& val)
0133 {
0134 return date_type(val.day);
0135 }
0136 static BOOST_CONSTEXPR time_duration_type get_time_of_day(const time_rep_type& val)
0137 {
0138 return time_duration_type(val.time_of_day);
0139 }
0140 static std::string zone_name(const time_rep_type&)
0141 {
0142 return std::string();
0143 }
0144 static BOOST_CONSTEXPR
0145 bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs)
0146 {
0147 return ((lhs.day == rhs.day) && (lhs.time_of_day == rhs.time_of_day));
0148 }
0149 static BOOST_CXX14_CONSTEXPR
0150 bool is_less(const time_rep_type& lhs, const time_rep_type& rhs)
0151 {
0152 if (lhs.day < rhs.day) return true;
0153 if (lhs.day > rhs.day) return false;
0154 return (lhs.time_of_day < rhs.time_of_day);
0155 }
0156 static BOOST_CXX14_CONSTEXPR
0157 time_rep_type add_days(const time_rep_type& base,
0158 const date_duration_type& dd)
0159 {
0160 return time_rep_type(base.day+dd, base.time_of_day);
0161 }
0162 static BOOST_CXX14_CONSTEXPR
0163 time_rep_type subtract_days(const time_rep_type& base,
0164 const date_duration_type& dd)
0165 {
0166 return split_timedate_system::get_time_rep(base.day-dd, base.time_of_day);
0167 }
0168 static BOOST_CXX14_CONSTEXPR
0169 time_rep_type subtract_time_duration(const time_rep_type& base,
0170 const time_duration_type& td)
0171 {
0172 if(base.day.is_special() || td.is_special())
0173 {
0174 return split_timedate_system::get_time_rep(base.day, -td);
0175 }
0176 if (td.is_negative()) {
0177 time_duration_type td1 = td.invert_sign();
0178 return add_time_duration(base,td1);
0179 }
0180
0181 wrap_int_type day_offset(base.time_of_day.ticks());
0182 date_duration_type day_overflow(static_cast<typename date_duration_type::duration_rep_type>(day_offset.subtract(td.ticks())));
0183
0184 return time_rep_type(base.day-day_overflow,
0185 time_duration_type(0,0,0,day_offset.as_int()));
0186 }
0187 static BOOST_CXX14_CONSTEXPR
0188 time_rep_type add_time_duration(const time_rep_type& base,
0189 time_duration_type td)
0190 {
0191 if(base.day.is_special() || td.is_special()) {
0192 return split_timedate_system::get_time_rep(base.day, td);
0193 }
0194 if (td.is_negative()) {
0195 time_duration_type td1 = td.invert_sign();
0196 return subtract_time_duration(base,td1);
0197 }
0198
0199 wrap_int_type day_offset(base.time_of_day.ticks());
0200 date_duration_type day_overflow(static_cast< typename date_duration_type::duration_rep_type >(day_offset.add(td.ticks())));
0201
0202 return time_rep_type(base.day+day_overflow,
0203 time_duration_type(0,0,0,day_offset.as_int()));
0204 }
0205 static BOOST_CXX14_CONSTEXPR
0206 time_duration_type subtract_times(const time_rep_type& lhs,
0207 const time_rep_type& rhs)
0208 {
0209 date_duration_type dd = lhs.day - rhs.day;
0210 if (BOOST_LIKELY(!dd.is_special())) {
0211 time_duration_type td(dd.days()*24,0,0);
0212 time_duration_type td2 = lhs.time_of_day - rhs.time_of_day;
0213 return td+td2;
0214 } else {
0215 time_duration_type td(dd.as_special());
0216 time_duration_type td2 = lhs.time_of_day - rhs.time_of_day;
0217 return td+td2;
0218 }
0219 }
0220
0221 };
0222
0223 } }
0224
0225
0226 #endif