| 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 | <http://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 | std::ostream& operator<<(std::ostream& out, const Weekday& w) { |
| 33 | return out << io::long_weekday(w); |
| 34 | } |
| 35 | |
| 36 | namespace detail { |
| 37 | |
| 38 | std::ostream& operator<<(std::ostream& out, |
| 39 | const long_weekday_holder& holder) { |
| 40 | switch (holder.d) { |
| 41 | case Sunday: |
| 42 | return out << "Sunday" ; |
| 43 | case Monday: |
| 44 | return out << "Monday" ; |
| 45 | case Tuesday: |
| 46 | return out << "Tuesday" ; |
| 47 | case Wednesday: |
| 48 | return out << "Wednesday" ; |
| 49 | case Thursday: |
| 50 | return out << "Thursday" ; |
| 51 | case Friday: |
| 52 | return out << "Friday" ; |
| 53 | case Saturday: |
| 54 | return out << "Saturday" ; |
| 55 | default: |
| 56 | QL_FAIL("unknown weekday" ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | std::ostream& operator<<(std::ostream& out, |
| 61 | const short_weekday_holder& holder) { |
| 62 | switch (holder.d) { |
| 63 | case Sunday: |
| 64 | return out << "Sun" ; |
| 65 | case Monday: |
| 66 | return out << "Mon" ; |
| 67 | case Tuesday: |
| 68 | return out << "Tue" ; |
| 69 | case Wednesday: |
| 70 | return out << "Wed" ; |
| 71 | case Thursday: |
| 72 | return out << "Thu" ; |
| 73 | case Friday: |
| 74 | return out << "Fri" ; |
| 75 | case Saturday: |
| 76 | return out << "Sat" ; |
| 77 | default: |
| 78 | QL_FAIL("unknown weekday" ); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | std::ostream& operator<<(std::ostream& out, |
| 83 | const shortest_weekday_holder& holder) { |
| 84 | switch (holder.d) { |
| 85 | case Sunday: |
| 86 | return out << "Su" ; |
| 87 | case Monday: |
| 88 | return out << "Mo" ; |
| 89 | case Tuesday: |
| 90 | return out << "Tu" ; |
| 91 | case Wednesday: |
| 92 | return out << "We" ; |
| 93 | case Thursday: |
| 94 | return out << "Th" ; |
| 95 | case Friday: |
| 96 | return out << "Fr" ; |
| 97 | case Saturday: |
| 98 | return out << "Sa" ; |
| 99 | default: |
| 100 | QL_FAIL("unknown weekday" ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | |
| 106 | namespace io { |
| 107 | |
| 108 | detail::long_weekday_holder long_weekday(Weekday d) { |
| 109 | return detail::long_weekday_holder(d); |
| 110 | } |
| 111 | |
| 112 | detail::short_weekday_holder short_weekday(Weekday d) { |
| 113 | return detail::short_weekday_holder(d); |
| 114 | } |
| 115 | |
| 116 | detail::shortest_weekday_holder shortest_weekday(Weekday d) { |
| 117 | return detail::shortest_weekday_holder(d); |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |