1 #ifndef POSIXTIME_FORMATTERS_LIMITED_HPP___
2 #define POSIXTIME_FORMATTERS_LIMITED_HPP___
4 /* Copyright (c) 2002,2003 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
12 #include <boost/date_time/gregorian/gregorian.hpp>
13 #include <boost/date_time/compiler_config.hpp>
14 #include <boost/date_time/iso_format.hpp>
15 #include <boost/date_time/date_format_simple.hpp>
16 #include <boost/date_time/posix_time/posix_time_types.hpp>
17 #include <boost/date_time/time_formatting_streams.hpp>
18 #include <boost/date_time/time_resolution_traits.hpp> // absolute_value
22 namespace posix_time {
24 //! Time duration to string -hh::mm::ss.fffffff. Example: 10:09:03.0123456
25 /*!\ingroup time_format
27 inline std::string to_simple_string(time_duration td) {
28 std::ostringstream ss;
30 /* simply using 'ss << td.get_rep()' won't work on compilers
31 * that don't support locales. This way does. */
32 // switch copied from date_names_put.hpp
33 switch(td.get_rep().as_special())
36 //ss << "not-a-number";
37 ss << "not-a-date-time";
50 if(td.is_negative()) {
53 ss << std::setw(2) << std::setfill('0')
54 << date_time::absolute_value(td.hours()) << ":";
55 ss << std::setw(2) << std::setfill('0')
56 << date_time::absolute_value(td.minutes()) << ":";
57 ss << std::setw(2) << std::setfill('0')
58 << date_time::absolute_value(td.seconds());
59 //TODO the following is totally non-generic, yelling FIXME
60 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
61 boost::int64_t frac_sec =
62 date_time::absolute_value(td.fractional_seconds());
63 // JDG [7/6/02 VC++ compatibility]
65 _i64toa(frac_sec, buff, 10);
67 time_duration::fractional_seconds_type frac_sec =
68 date_time::absolute_value(td.fractional_seconds());
71 ss << "." << std::setw(time_duration::num_fractional_digits())
74 // JDG [7/6/02 VC++ compatibility]
75 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
85 //! Time duration in iso format -hhmmss,fffffff Example: 10:09:03,0123456
86 /*!\ingroup time_format
90 to_iso_string(time_duration td)
92 std::ostringstream ss;
94 /* simply using 'ss << td.get_rep()' won't work on compilers
95 * that don't support locales. This way does. */
96 // switch copied from date_names_put.hpp
97 switch(td.get_rep().as_special()) {
99 //ss << "not-a-number";
100 ss << "not-a-date-time";
113 if(td.is_negative()) {
116 ss << std::setw(2) << std::setfill('0')
117 << date_time::absolute_value(td.hours());
118 ss << std::setw(2) << std::setfill('0')
119 << date_time::absolute_value(td.minutes());
120 ss << std::setw(2) << std::setfill('0')
121 << date_time::absolute_value(td.seconds());
122 //TODO the following is totally non-generic, yelling FIXME
123 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
124 boost::int64_t frac_sec =
125 date_time::absolute_value(td.fractional_seconds());
126 // JDG [7/6/02 VC++ compatibility]
128 _i64toa(frac_sec, buff, 10);
130 time_duration::fractional_seconds_type frac_sec =
131 date_time::absolute_value(td.fractional_seconds());
134 ss << "." << std::setw(time_duration::num_fractional_digits())
137 // JDG [7/6/02 VC++ compatibility]
138 #if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
148 //! Time to simple format CCYY-mmm-dd hh:mm:ss.fffffff
149 /*!\ingroup time_format
153 to_simple_string(ptime t)
155 std::string ts = gregorian::to_simple_string(t.date());// + " ";
156 if(!t.time_of_day().is_special()) {
157 return ts + " " + to_simple_string(t.time_of_day());
164 //! Convert to string of form [YYYY-mmm-DD HH:MM::SS.ffffff/YYYY-mmm-DD HH:MM::SS.fffffff]
165 /*!\ingroup time_format
169 to_simple_string(time_period tp)
171 std::string d1(to_simple_string(tp.begin()));
172 std::string d2(to_simple_string(tp.last()));
173 return std::string("[" + d1 + "/" + d2 +"]");
176 //! Convert iso short form YYYYMMDDTHHMMSS where T is the date-time separator
177 /*!\ingroup time_format
180 std::string to_iso_string(ptime t)
182 std::string ts = gregorian::to_iso_string(t.date());// + "T";
183 if(!t.time_of_day().is_special()) {
184 return ts + "T" + to_iso_string(t.time_of_day());
191 //! Convert to form YYYY-MM-DDTHH:MM:SS where T is the date-time separator
192 /*!\ingroup time_format
196 to_iso_extended_string(ptime t)
198 std::string ts = gregorian::to_iso_extended_string(t.date());// + "T";
199 if(!t.time_of_day().is_special()) {
200 return ts + "T" + to_simple_string(t.time_of_day());
208 } } //namespace posix_time