1
#ifndef POSIX_TIME_PRE133_OPERATORS_HPP___
2
#define POSIX_TIME_PRE133_OPERATORS_HPP___
4
/* Copyright (c) 2002-2004 CrystalClear Software, Inc.
5
* Use, modification and distribution is subject to the
6
* Boost Software License, Version 1.0. (See accompanying
7
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8
* Author: Jeff Garland, Bart Garst
9
* $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $
12
/*! @file posix_time_pre133_operators.hpp
13
* These input and output operators are for use with the
14
* pre 1.33 version of the date_time libraries io facet code.
15
* The operators used in version 1.33 and later can be found
16
* in posix_time_io.hpp */
21
#include "boost/date_time/compiler_config.hpp"
22
#include "boost/date_time/gregorian/gregorian.hpp"
23
#include "boost/date_time/posix_time/posix_time_duration.hpp"
24
#include "boost/date_time/posix_time/ptime.hpp"
25
#include "boost/date_time/posix_time/time_period.hpp"
26
#include "boost/date_time/time_parsing.hpp"
29
namespace posix_time {
32
//The following code is removed for configurations with poor std::locale support (eg: MSVC6, gcc 2.9x)
33
#ifndef BOOST_DATE_TIME_NO_LOCALE
34
#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
35
//! ostream operator for posix_time::time_duration
36
template <class charT, class traits>
38
std::basic_ostream<charT, traits>&
39
operator<<(std::basic_ostream<charT, traits>& os, const time_duration& td)
41
typedef boost::date_time::ostream_time_duration_formatter<time_duration, charT> duration_formatter;
42
duration_formatter::duration_put(td, os);
46
//! ostream operator for posix_time::ptime
47
template <class charT, class traits>
49
std::basic_ostream<charT, traits>&
50
operator<<(std::basic_ostream<charT, traits>& os, const ptime& t)
52
typedef boost::date_time::ostream_time_formatter<ptime, charT> time_formatter;
53
time_formatter::time_put(t, os);
57
//! ostream operator for posix_time::time_period
58
template <class charT, class traits>
60
std::basic_ostream<charT, traits>&
61
operator<<(std::basic_ostream<charT, traits>& os, const time_period& tp)
63
typedef boost::date_time::ostream_time_period_formatter<time_period, charT> period_formatter;
64
period_formatter::period_put(tp, os);
67
#endif // USE_DATE_TIME_PRE_1_33_FACET_IO
68
/******** input streaming ********/
71
std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_duration& td)
73
// need to create a std::string and parse it
74
std::basic_string<charT> inp_s;
75
std::stringstream out_ss;
77
typename std::basic_string<charT>::iterator b = inp_s.begin();
78
// need to use both iterators because there is no requirement
79
// for the data held by a std::basic_string<> be terminated with
80
// any marker (such as '\0').
81
typename std::basic_string<charT>::iterator e = inp_s.end();
83
out_ss << out_ss.narrow(*b, 0);
87
td = date_time::parse_delimited_time_duration<time_duration>(out_ss.str());
93
std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, ptime& pt)
95
gregorian::date d(not_a_date_time);
96
time_duration td(0,0,0);
103
/** operator>> for time_period. time_period must be in
104
* "[date time_duration/date time_duration]" format. */
105
template<class charT>
107
std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_period& tp)
109
gregorian::date d(not_a_date_time);
110
time_duration td(0,0,0);
113
std::basic_string<charT> s;
114
// get first date string and remove leading '['
117
std::basic_stringstream<charT> ss;
118
ss << s.substr(s.find('[')+1);
121
// get first time_duration & second date string, remove the '/'
122
// and split into 2 strings
125
std::basic_stringstream<charT> ss;
126
ss << s.substr(0, s.find('/'));
131
std::basic_stringstream<charT> ss;
132
ss << s.substr(s.find('/')+1);
135
// get last time_duration and remove the trailing ']'
138
std::basic_stringstream<charT> ss;
139
ss << s.substr(0, s.find(']'));
144
tp = time_period(beg,end);
149
#endif //BOOST_DATE_TIME_NO_LOCALE
153
#endif // POSIX_TIME_PRE133_OPERATORS_HPP___