/src/quantlib/ql/time/weekday.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
5 | | Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl |
6 | | Copyright (C) 2004, 2005, 2006 Ferdinando Ametrano |
7 | | Copyright (C) 2006 Katiuscia Manzoni |
8 | | Copyright (C) 2006 Toyin Akin |
9 | | |
10 | | This file is part of QuantLib, a free-software/open-source library |
11 | | for financial quantitative analysts and developers - http://quantlib.org/ |
12 | | |
13 | | QuantLib is free software: you can redistribute it and/or modify it |
14 | | under the terms of the QuantLib license. You should have received a |
15 | | copy of the license along with this program; if not, please email |
16 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
17 | | <https://www.quantlib.org/license.shtml>. |
18 | | |
19 | | This program is distributed in the hope that it will be useful, but WITHOUT |
20 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
21 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
22 | | */ |
23 | | |
24 | | #include <ql/time/weekday.hpp> |
25 | | #include <ql/types.hpp> |
26 | | #include <ql/errors.hpp> |
27 | | |
28 | | namespace QuantLib { |
29 | | |
30 | | // weekday formatting |
31 | | |
32 | 0 | std::ostream& operator<<(std::ostream& out, const Weekday& w) { |
33 | 0 | return out << io::long_weekday(w); |
34 | 0 | } |
35 | | |
36 | | namespace detail { |
37 | | |
38 | | std::ostream& operator<<(std::ostream& out, |
39 | 0 | const long_weekday_holder& holder) { |
40 | 0 | switch (holder.d) { |
41 | 0 | case Sunday: |
42 | 0 | return out << "Sunday"; |
43 | 0 | case Monday: |
44 | 0 | return out << "Monday"; |
45 | 0 | case Tuesday: |
46 | 0 | return out << "Tuesday"; |
47 | 0 | case Wednesday: |
48 | 0 | return out << "Wednesday"; |
49 | 0 | case Thursday: |
50 | 0 | return out << "Thursday"; |
51 | 0 | case Friday: |
52 | 0 | return out << "Friday"; |
53 | 0 | case Saturday: |
54 | 0 | return out << "Saturday"; |
55 | 0 | default: |
56 | 0 | QL_FAIL("unknown weekday"); |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | | std::ostream& operator<<(std::ostream& out, |
61 | 0 | const short_weekday_holder& holder) { |
62 | 0 | switch (holder.d) { |
63 | 0 | case Sunday: |
64 | 0 | return out << "Sun"; |
65 | 0 | case Monday: |
66 | 0 | return out << "Mon"; |
67 | 0 | case Tuesday: |
68 | 0 | return out << "Tue"; |
69 | 0 | case Wednesday: |
70 | 0 | return out << "Wed"; |
71 | 0 | case Thursday: |
72 | 0 | return out << "Thu"; |
73 | 0 | case Friday: |
74 | 0 | return out << "Fri"; |
75 | 0 | case Saturday: |
76 | 0 | return out << "Sat"; |
77 | 0 | default: |
78 | 0 | QL_FAIL("unknown weekday"); |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | std::ostream& operator<<(std::ostream& out, |
83 | 0 | const shortest_weekday_holder& holder) { |
84 | 0 | switch (holder.d) { |
85 | 0 | case Sunday: |
86 | 0 | return out << "Su"; |
87 | 0 | case Monday: |
88 | 0 | return out << "Mo"; |
89 | 0 | case Tuesday: |
90 | 0 | return out << "Tu"; |
91 | 0 | case Wednesday: |
92 | 0 | return out << "We"; |
93 | 0 | case Thursday: |
94 | 0 | return out << "Th"; |
95 | 0 | case Friday: |
96 | 0 | return out << "Fr"; |
97 | 0 | case Saturday: |
98 | 0 | return out << "Sa"; |
99 | 0 | default: |
100 | 0 | QL_FAIL("unknown weekday"); |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | } |
105 | | |
106 | | namespace io { |
107 | | |
108 | 0 | detail::long_weekday_holder long_weekday(Weekday d) { |
109 | 0 | return detail::long_weekday_holder(d); |
110 | 0 | } |
111 | | |
112 | 0 | detail::short_weekday_holder short_weekday(Weekday d) { |
113 | 0 | return detail::short_weekday_holder(d); |
114 | 0 | } |
115 | | |
116 | 0 | detail::shortest_weekday_holder shortest_weekday(Weekday d) { |
117 | 0 | return detail::shortest_weekday_holder(d); |
118 | 0 | } |
119 | | |
120 | | } |
121 | | |
122 | | } |