123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #ifndef POSIX_TIME_PRE133_OPERATORS_HPP___
- #define POSIX_TIME_PRE133_OPERATORS_HPP___
- #include <iostream>
- #include <string>
- #include <sstream>
- #include "boost/date_time/compiler_config.hpp"
- #include "boost/date_time/gregorian/gregorian.hpp"
- #include "boost/date_time/posix_time/posix_time_duration.hpp"
- #include "boost/date_time/posix_time/ptime.hpp"
- #include "boost/date_time/posix_time/time_period.hpp"
- #include "boost/date_time/time_parsing.hpp"
- namespace boost {
- namespace posix_time {
- #ifndef BOOST_DATE_TIME_NO_LOCALE
- #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
-
- template <class charT, class traits>
- inline
- std::basic_ostream<charT, traits>&
- operator<<(std::basic_ostream<charT, traits>& os, const time_duration& td)
- {
- typedef boost::date_time::ostream_time_duration_formatter<time_duration, charT> duration_formatter;
- duration_formatter::duration_put(td, os);
- return os;
- }
-
- template <class charT, class traits>
- inline
- std::basic_ostream<charT, traits>&
- operator<<(std::basic_ostream<charT, traits>& os, const ptime& t)
- {
- typedef boost::date_time::ostream_time_formatter<ptime, charT> time_formatter;
- time_formatter::time_put(t, os);
- return os;
- }
-
- template <class charT, class traits>
- inline
- std::basic_ostream<charT, traits>&
- operator<<(std::basic_ostream<charT, traits>& os, const time_period& tp)
- {
- typedef boost::date_time::ostream_time_period_formatter<time_period, charT> period_formatter;
- period_formatter::period_put(tp, os);
- return os;
- }
- #endif
- template<class charT>
- inline
- std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_duration& td)
- {
-
- std::basic_string<charT> inp_s;
- std::stringstream out_ss;
- is >> inp_s;
- typename std::basic_string<charT>::iterator b = inp_s.begin();
-
-
-
- typename std::basic_string<charT>::iterator e = inp_s.end();
- while(b != e){
- out_ss << is.narrow(*b, 0);
- ++b;
- }
- td = date_time::parse_delimited_time_duration<time_duration>(out_ss.str());
- return is;
- }
- template<class charT>
- inline
- std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, ptime& pt)
- {
- gregorian::date d(not_a_date_time);
- time_duration td(0,0,0);
- is >> d >> td;
- pt = ptime(d, td);
- return is;
- }
-
- template<class charT>
- inline
- std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_period& tp)
- {
- gregorian::date d(not_a_date_time);
- time_duration td(0,0,0);
- ptime beg(d, td);
- ptime end(beg);
- std::basic_string<charT> s;
-
- is >> s;
- {
- std::basic_stringstream<charT> ss;
- ss << s.substr(s.find('[')+1);
- ss >> d;
- }
-
-
- is >> s;
- {
- std::basic_stringstream<charT> ss;
- ss << s.substr(0, s.find('/'));
- ss >> td;
- }
- beg = ptime(d, td);
- {
- std::basic_stringstream<charT> ss;
- ss << s.substr(s.find('/')+1);
- ss >> d;
- }
-
- is >> s;
- {
- std::basic_stringstream<charT> ss;
- ss << s.substr(0, s.find(']'));
- ss >> td;
- }
- end = ptime(d, td);
- tp = time_period(beg,end);
- return is;
- }
- #endif
- } }
- #endif
|