File indexing completed on 2025-01-18 09:30:39
0001 #ifndef DATE_TIME_TIME_FORMATTING_STREAMS_HPP___
0002 #define DATE_TIME_TIME_FORMATTING_STREAMS_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <boost/date_time/compiler_config.hpp>
0013
0014 #ifndef BOOST_DATE_TIME_NO_LOCALE
0015
0016 #include <locale>
0017 #include <iomanip>
0018 #include <iostream>
0019 #include <boost/date_time/date_formatting_locales.hpp>
0020 #include <boost/date_time/time_resolution_traits.hpp>
0021
0022 namespace boost {
0023 namespace date_time {
0024
0025
0026
0027 template<class time_duration_type,
0028 class charT = char>
0029 class ostream_time_duration_formatter
0030 {
0031 public:
0032 typedef std::basic_ostream<charT> ostream_type;
0033 typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type;
0034
0035
0036 static void duration_put(const time_duration_type& td,
0037 ostream_type& os)
0038 {
0039 if(td.is_special()) {
0040 os << td.get_rep();
0041 }
0042 else {
0043 charT fill_char = '0';
0044 if(td.is_negative()) {
0045 os << '-';
0046 }
0047 os << std::setw(2) << std::setfill(fill_char)
0048 << absolute_value(td.hours()) << ":";
0049 os << std::setw(2) << std::setfill(fill_char)
0050 << absolute_value(td.minutes()) << ":";
0051 os << std::setw(2) << std::setfill(fill_char)
0052 << absolute_value(td.seconds());
0053 fractional_seconds_type frac_sec =
0054 absolute_value(td.fractional_seconds());
0055 if (frac_sec != 0) {
0056 os << "."
0057 << std::setw(time_duration_type::num_fractional_digits())
0058 << std::setfill(fill_char)
0059 << frac_sec;
0060 }
0061 }
0062 }
0063 };
0064
0065
0066 template<class time_type,
0067 class charT = char>
0068 class ostream_time_formatter
0069 {
0070 public:
0071 typedef std::basic_ostream<charT> ostream_type;
0072 typedef typename time_type::date_type date_type;
0073 typedef typename time_type::time_duration_type time_duration_type;
0074 typedef ostream_time_duration_formatter<time_duration_type, charT> duration_formatter;
0075
0076
0077 static void time_put(const time_type& t,
0078 ostream_type& os)
0079 {
0080 date_type d = t.date();
0081 os << d;
0082 if(!d.is_infinity() && !d.is_not_a_date())
0083 {
0084 os << " ";
0085 duration_formatter::duration_put(t.time_of_day(), os);
0086 }
0087
0088 }
0089 };
0090
0091
0092
0093 template<class time_period_type,
0094 class charT = char>
0095 class ostream_time_period_formatter
0096 {
0097 public:
0098 typedef std::basic_ostream<charT> ostream_type;
0099 typedef typename time_period_type::point_type time_type;
0100 typedef ostream_time_formatter<time_type, charT> time_formatter;
0101
0102
0103 static void period_put(const time_period_type& tp,
0104 ostream_type& os)
0105 {
0106 os << '[';
0107 time_formatter::time_put(tp.begin(), os);
0108 os << '/';
0109 time_formatter::time_put(tp.last(), os);
0110 os << ']';
0111
0112 }
0113
0114 };
0115
0116
0117
0118 } }
0119
0120 #endif
0121
0122 #endif