2 * @brief time related functions.
4 * @copyright Copyright © 2001-2008 by Intra2net AG
6 * @contact info@intra2net.com
10 #ifndef __TIMEFUNC_HXX
11 #define __TIMEFUNC_HXX
18 double prec_time(void);
20 int date_to_seconds(const std::string &date);
22 std::string make_nice_time(int seconds);
23 std::string format_full_time(int seconds);
24 void seconds_to_hour_minute(int seconds, int *hour, int *minute);
25 std::string output_hour_minute(int hour, int minute, bool h_for_00=true);
27 inline std::string output_hour_minute_from_seconds(int seconds)
30 seconds_to_hour_minute(seconds,&hour,&minute);
31 return output_hour_minute(hour,minute);
34 std::string get_month_name(unsigned char month);
42 enum WEEKDAY { SU=0, MO=1, TU=2, WE=3, TH=4, FR=5, SA=6 };
44 // throws out_of_range if illegal week
45 WEEK(const std::string& daystring);
47 WEEK(const std::bitset<7> &days)
57 operator std::bitset<7>() const
60 void set(WEEKDAY d, bool value=true)
64 { return (days.count()==7); }
66 { return days.none(); }
68 std::string get_daystring() const;
69 std::string get_displaystring() const;
70 std::string get_netfilterstring() const;
72 static std::string get_day_display(WEEKDAY day);
73 static std::string get_english_display(WEEKDAY day);
78 * @brief structure representing a single (half-open) interval.
89 Interval( unsigned int start, unsigned int end )
90 : m_lower_bound(start)
100 return m_lower_bound <= m_upper_bound;
101 } // eo is_valid() const
105 return m_lower_bound == m_upper_bound;
106 } // eo empty() const
109 unsigned int lower_bound() const { return m_lower_bound; }
110 unsigned int upper_bound() const { return m_upper_bound; }
113 bool operator== (const Interval& other) const
115 return m_lower_bound == other.m_lower_bound and m_upper_bound == other.m_upper_bound;
116 } // eo operator==(const Interval&)
120 * @brief less operator. compares only the start times!
121 * @param other the other interval to compare with.
122 * @return @a true if the current start is less than the other start.
124 bool operator<(const Interval& other) const
126 return m_lower_bound < other.m_lower_bound;
127 } // eo operator<(const Interval&)
130 bool intersects(const Interval& other) const;
131 bool contains(const Interval& other) const;
136 friend class Intervals;
138 unsigned int m_lower_bound;
139 unsigned int m_upper_bound;
146 * @brief structure representing a combination of single disjoint (half open) intervals.
148 * Basic idea is that this structure provides an interface for adding and
149 * subtracting single intervals and keeps the internal list of intervals as
150 * a list of disjoint intervals.
152 * @note the list is sorted by the start; lower comes first.
154 * @note the class provides some methods similar to STL container classes;
155 * i.e. it can be used with (at least some) STL algorithms.
158 * we use a std::list for the intervals; this means we don't invalidate all
159 * iterators when we insert or delete within loops...
160 * And we use that fact!!
165 typedef std::list< Interval > IntervalList;
166 typedef IntervalList::value_type value_type;
167 typedef IntervalList::const_iterator const_iterator;
168 typedef IntervalList::const_iterator iterator; // we allow only const...
169 typedef IntervalList::size_type size_type;
174 void add(const Interval& new_frame);
175 void sub(const Interval& new_frame);
179 const_iterator begin() const { return m_intervals.begin(); }
180 const_iterator end() const { return m_intervals.end(); }
182 bool empty() const { return m_intervals.empty(); }
183 const Interval& front() const { return m_intervals.front(); }
184 const Interval& back() const { return m_intervals.back(); }
186 size_type size() const { return m_intervals.size(); }
188 bool intersects(const Interval& other) const;
189 bool intersects(const Intervals& other) const;
191 bool contains(const Interval& other) const;
192 bool contains(const Intervals& other) const;
194 bool operator==(const Intervals& other) const;
195 bool operator!=(const Intervals& other) const {return not (*this == other) ; }
197 Intervals& operator+=(const Interval& other);
198 Intervals& operator-=(const Interval& other);
200 Intervals& operator+=(const Intervals& other);
201 Intervals& operator-=(const Intervals& other);
205 std::list< Interval > m_intervals;