1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#ifndef DATE_TIME_TIME_FORMATTING_STREAMS_HPP___
#define DATE_TIME_TIME_FORMATTING_STREAMS_HPP___
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
* Use, modification and distribution is subject to the
* Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
* Author: Jeff Garland, Bart Garst
* $Date: 2008-11-12 14:37:53 -0500 (Wed, 12 Nov 2008) $
*/
#include <boost/date_time/compiler_config.hpp>
#ifndef BOOST_DATE_TIME_NO_LOCALE
#include <locale>
#include <iomanip>
#include <iostream>
#include <boost/date_time/date_formatting_locales.hpp>
#include <boost/date_time/time_resolution_traits.hpp>
namespace boost {
namespace date_time {
//! Put a time type into a stream using appropriate facets
template<class time_duration_type,
class charT = char>
class ostream_time_duration_formatter
{
public:
typedef std::basic_ostream<charT> ostream_type;
typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type;
//! Put time into an ostream
static void duration_put(const time_duration_type& td,
ostream_type& os)
{
if(td.is_special()) {
os << td.get_rep();
}
else {
charT fill_char = '0';
if(td.is_negative()) {
os << '-';
}
os << std::setw(2) << std::setfill(fill_char)
<< absolute_value(td.hours()) << ":";
os << std::setw(2) << std::setfill(fill_char)
<< absolute_value(td.minutes()) << ":";
os << std::setw(2) << std::setfill(fill_char)
<< absolute_value(td.seconds());
fractional_seconds_type frac_sec =
absolute_value(td.fractional_seconds());
if (frac_sec != 0) {
os << "."
<< std::setw(time_duration_type::num_fractional_digits())
<< std::setfill(fill_char)
<< frac_sec;
}
} // else
} // duration_put
}; //class ostream_time_duration_formatter
//! Put a time type into a stream using appropriate facets
template<class time_type,
class charT = char>
class ostream_time_formatter
{
public:
typedef std::basic_ostream<charT> ostream_type;
typedef typename time_type::date_type date_type;
typedef typename time_type::time_duration_type time_duration_type;
typedef ostream_time_duration_formatter<time_duration_type, charT> duration_formatter;
//! Put time into an ostream
static void time_put(const time_type& t,
ostream_type& os)
{
date_type d = t.date();
os << d;
if(!d.is_infinity() && !d.is_not_a_date())
{
os << " "; //TODO: fix the separator here.
duration_formatter::duration_put(t.time_of_day(), os);
}
} // time_to_ostream
}; //class ostream_time_formatter
//! Put a time period into a stream using appropriate facets
template<class time_period_type,
class charT = char>
class ostream_time_period_formatter
{
public:
typedef std::basic_ostream<charT> ostream_type;
typedef typename time_period_type::point_type time_type;
typedef ostream_time_formatter<time_type, charT> time_formatter;
//! Put time into an ostream
static void period_put(const time_period_type& tp,
ostream_type& os)
{
os << '['; //TODO: facet or manipulator for periods?
time_formatter::time_put(tp.begin(), os);
os << '/'; //TODO: facet or manipulator for periods?
time_formatter::time_put(tp.last(), os);
os << ']';
} // period_put
}; //class ostream_time_period_formatter
} } //namespace date_time
#endif //BOOST_DATE_TIME_NO_LOCALE
#endif
|