2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 * @brief time related functions. Week module
23 * @copyright Copyright © 2001-2009 by Intra2net AG
36 * @brief represents some days of a week.
42 /// Bitset storing the active days. Zero is Sunday.
44 /// Flag to indicate if this Week is valid
48 enum WeekDay { Su=0, Mo=1, Tu=2, We=3, Th=4, Fr=5, Sa=6, _WeekDay_END=7 };
51 Week(const std::string& daystring);
52 Week(const std::bitset<7> &_days);
54 bool is_valid() const;
58 operator std::bitset<7>() const
61 bool set(const std::string& daystring);
62 bool set(const WeekDay day, bool value=true);
64 bool get(WeekDay day) const;
65 bool is_set(WeekDay day) const;
68 bool none_set() const;
70 unsigned int days_till_set(WeekDay day) const;
71 unsigned int days_since_set(WeekDay day) const;
73 std::string get_daystring() const;
74 std::string get_displaystring() const;
75 std::string get_netfilterstring() const;
77 static std::string get_day_display(WeekDay day);
78 static std::string get_english_display(WeekDay day);
80 // some operators for convenience:
82 Week& operator&=(const Week& rhs)
88 Week& operator|=(const Week& rhs)
94 Week& operator^=(const Week& rhs)
100 bool operator==(const Week& rhs) const
102 return Days == rhs.Days;
105 bool operator!=(const Week& rhs) const
107 return Days != rhs.Days;
113 * @brief delivers a week containing the days which are in both weeks.
114 * @param lhs first week.
115 * @param rhs second week.
116 * @return week which has only those days which are in both weeks.
118 inline Week operator&(const Week& lhs, const Week& rhs)
120 I2n::Time::Week result(lhs);
121 return result &= rhs;
126 * @brief delivers a week containing the days which are at least in one of both weeks.
127 * @param lhs first week.
128 * @param rhs second week.
129 * @return week which has only those days which are at least in one of both weeks.
131 inline Week operator|(const Week& lhs, const Week& rhs)
133 I2n::Time::Week result(lhs);
134 return result |= rhs;
139 * @brief delivers a week containing the days which are in only one of both weeks.
140 * @param lhs first week.
141 * @param rhs second week.
142 * @return week which has only those days which are in only one of both weeks.
144 inline Week operator^(const Week& lhs, const Week& rhs)
146 I2n::Time::Week result(lhs);
147 return result ^= rhs;