1#include "cctz/civil_time_detail.h"
2
3#include <iomanip>
4#include <ostream>
5#include <sstream>
6
7namespace cctz {
8namespace detail {
9
10// Output stream operators output a format matching YYYY-MM-DDThh:mm:ss,
11// while omitting fields inferior to the type's alignment. For example,
12// civil_day is formatted only as YYYY-MM-DD.
13std::ostream& operator<<(std::ostream& os, const civil_year& y) {
14 std::stringstream ss;
15 ss << y.year(); // No padding.
16 return os << ss.str();
17}
18std::ostream& operator<<(std::ostream& os, const civil_month& m) {
19 std::stringstream ss;
20 ss << civil_year(m) << '-';
21 ss << std::setfill('0') << std::setw(2) << m.month();
22 return os << ss.str();
23}
24std::ostream& operator<<(std::ostream& os, const civil_day& d) {
25 std::stringstream ss;
26 ss << civil_month(d) << '-';
27 ss << std::setfill('0') << std::setw(2) << d.day();
28 return os << ss.str();
29}
30std::ostream& operator<<(std::ostream& os, const civil_hour& h) {
31 std::stringstream ss;
32 ss << civil_day(h) << 'T';
33 ss << std::setfill('0') << std::setw(2) << h.hour();
34 return os << ss.str();
35}
36std::ostream& operator<<(std::ostream& os, const civil_minute& m) {
37 std::stringstream ss;
38 ss << civil_hour(m) << ':';
39 ss << std::setfill('0') << std::setw(2) << m.minute();
40 return os << ss.str();
41}
42std::ostream& operator<<(std::ostream& os, const civil_second& s) {
43 std::stringstream ss;
44 ss << civil_minute(s) << ':';
45 ss << std::setfill('0') << std::setw(2) << s.second();
46 return os << ss.str();
47}
48
49////////////////////////////////////////////////////////////////////////
50
51std::ostream& operator<<(std::ostream& os, weekday wd) {
52 switch (wd) {
53 case weekday::monday:
54 return os << "Monday";
55 case weekday::tuesday:
56 return os << "Tuesday";
57 case weekday::wednesday:
58 return os << "Wednesday";
59 case weekday::thursday:
60 return os << "Thursday";
61 case weekday::friday:
62 return os << "Friday";
63 case weekday::saturday:
64 return os << "Saturday";
65 case weekday::sunday:
66 return os << "Sunday";
67 }
68 return os; // Should never get here, but -Wreturn-type may warn without this.
69}
70
71} // namespace detail
72} // namespace cctz
73