File indexing completed on 2025-01-18 09:30:36
0001 #ifndef POSIX_TIME_PRE133_OPERATORS_HPP___
0002 #define POSIX_TIME_PRE133_OPERATORS_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <iostream>
0019 #include <string>
0020 #include <sstream>
0021 #include "boost/date_time/compiler_config.hpp"
0022 #include "boost/date_time/gregorian/gregorian.hpp"
0023 #include "boost/date_time/posix_time/posix_time_duration.hpp"
0024 #include "boost/date_time/posix_time/ptime.hpp"
0025 #include "boost/date_time/posix_time/time_period.hpp"
0026 #include "boost/date_time/time_parsing.hpp"
0027
0028 namespace boost {
0029 namespace posix_time {
0030
0031
0032
0033 #ifndef BOOST_DATE_TIME_NO_LOCALE
0034 #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
0035
0036 template <class charT, class traits>
0037 inline
0038 std::basic_ostream<charT, traits>&
0039 operator<<(std::basic_ostream<charT, traits>& os, const time_duration& td)
0040 {
0041 typedef boost::date_time::ostream_time_duration_formatter<time_duration, charT> duration_formatter;
0042 duration_formatter::duration_put(td, os);
0043 return os;
0044 }
0045
0046
0047 template <class charT, class traits>
0048 inline
0049 std::basic_ostream<charT, traits>&
0050 operator<<(std::basic_ostream<charT, traits>& os, const ptime& t)
0051 {
0052 typedef boost::date_time::ostream_time_formatter<ptime, charT> time_formatter;
0053 time_formatter::time_put(t, os);
0054 return os;
0055 }
0056
0057
0058 template <class charT, class traits>
0059 inline
0060 std::basic_ostream<charT, traits>&
0061 operator<<(std::basic_ostream<charT, traits>& os, const time_period& tp)
0062 {
0063 typedef boost::date_time::ostream_time_period_formatter<time_period, charT> period_formatter;
0064 period_formatter::period_put(tp, os);
0065 return os;
0066 }
0067 #endif
0068
0069 template<class charT>
0070 inline
0071 std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_duration& td)
0072 {
0073
0074 std::basic_string<charT> inp_s;
0075 std::stringstream out_ss;
0076 is >> inp_s;
0077 typename std::basic_string<charT>::iterator b = inp_s.begin();
0078
0079
0080
0081 typename std::basic_string<charT>::iterator e = inp_s.end();
0082 while(b != e){
0083 out_ss << is.narrow(*b, 0);
0084 ++b;
0085 }
0086
0087 td = date_time::parse_delimited_time_duration<time_duration>(out_ss.str());
0088 return is;
0089 }
0090
0091 template<class charT>
0092 inline
0093 std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, ptime& pt)
0094 {
0095 gregorian::date d(not_a_date_time);
0096 time_duration td(0,0,0);
0097 is >> d >> td;
0098 pt = ptime(d, td);
0099
0100 return is;
0101 }
0102
0103
0104
0105 template<class charT>
0106 inline
0107 std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_period& tp)
0108 {
0109 gregorian::date d(not_a_date_time);
0110 time_duration td(0,0,0);
0111 ptime beg(d, td);
0112 ptime end(beg);
0113 std::basic_string<charT> s;
0114
0115 is >> s;
0116 {
0117 std::basic_stringstream<charT> ss;
0118 ss << s.substr(s.find('[')+1);
0119 ss >> d;
0120 }
0121
0122
0123 is >> s;
0124 {
0125 std::basic_stringstream<charT> ss;
0126 ss << s.substr(0, s.find('/'));
0127 ss >> td;
0128 }
0129 beg = ptime(d, td);
0130 {
0131 std::basic_stringstream<charT> ss;
0132 ss << s.substr(s.find('/')+1);
0133 ss >> d;
0134 }
0135
0136 is >> s;
0137 {
0138 std::basic_stringstream<charT> ss;
0139 ss << s.substr(0, s.find(']'));
0140 ss >> td;
0141 }
0142 end = ptime(d, td);
0143
0144 tp = time_period(beg,end);
0145 return is;
0146 }
0147
0148
0149 #endif
0150
0151 } }
0152
0153 #endif