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.
23 * @copyright Copyright © 2001-2008 by Intra2net AG
26 #ifndef __TIMEFUNC_HXX
27 #define __TIMEFUNC_HXX
34 double prec_time(void);
36 time_t date_to_seconds(const std::string &date);
38 std::string make_nice_time(int seconds);
39 std::string format_full_time(time_t seconds);
40 std::string format_date(time_t seconds);
41 void seconds_to_hour_minute(int seconds, int *hour, int *minute);
42 void split_daysec(int daysec, int *outhours=NULL, int *outminutes=NULL, int *outseconds=NULL);
43 std::string output_hour_minute(int hour, int minute, bool h_for_00=true, int seconds=0);
45 inline std::string output_hour_minute_from_seconds(int seconds)
48 split_daysec(seconds,&hour,&minute);
49 return output_hour_minute(hour,minute);
52 std::string get_month_name(unsigned char month);
55 * @brief structure representing a single (half-open) interval.
68 Interval( unsigned int start, unsigned int end, int weak_mark= 0 )
69 : m_lower_bound(start)
71 , m_weak_mark(weak_mark)
81 return m_lower_bound <= m_upper_bound;
82 } // eo is_valid() const
86 return m_lower_bound == m_upper_bound;
90 unsigned int lower_bound() const { return m_lower_bound; }
91 unsigned int upper_bound() const { return m_upper_bound; }
93 int weak_mark() const { return m_weak_mark; }
95 bool changed() const { return m_changed; }
98 bool operator== (const Interval& other) const
100 return m_lower_bound == other.m_lower_bound and m_upper_bound == other.m_upper_bound;
101 } // eo operator==(const Interval&)
104 bool operator!=(const Interval& other) const
106 return not (*this == other);
107 } // eo operator!=(const Interval&)
111 * @brief less operator. compares only the start times!
112 * @param other the other interval to compare with.
113 * @return @a true if the current start is less than the other start.
115 bool operator<(const Interval& other) const
117 return m_lower_bound < other.m_lower_bound;
118 } // eo operator<(const Interval&)
121 bool intersects(const Interval& other) const;
122 bool contains(const Interval& other) const;
127 friend class Intervals;
129 unsigned int m_lower_bound;
130 unsigned int m_upper_bound;
140 * @brief structure representing a combination of single disjoint (half open) intervals.
142 * Basic idea is that this structure provides an interface for adding and
143 * subtracting single intervals and keeps the internal list of intervals as
144 * a list of disjoint intervals.
146 * @note the list is sorted by the start; lower comes first.
148 * @note the class provides some methods similar to STL container classes;
149 * i.e. it can be used with (at least some) STL algorithms.
152 * we use a std::list for the intervals; this means we don't invalidate all
153 * iterators when we insert or delete within loops...
154 * And we use that fact!!
159 typedef std::list< Interval > IntervalList;
160 typedef IntervalList::value_type value_type;
161 typedef IntervalList::const_iterator const_iterator;
162 typedef IntervalList::const_iterator iterator; // we allow only const...
163 typedef IntervalList::size_type size_type;
168 void add(const Interval& new_frame);
169 void sub(const Interval& new_frame);
173 const_iterator begin() const { return m_intervals.begin(); }
174 const_iterator end() const { return m_intervals.end(); }
176 bool empty() const { return m_intervals.empty(); }
177 const Interval& front() const { return m_intervals.front(); }
178 const Interval& back() const { return m_intervals.back(); }
180 size_type size() const { return m_intervals.size(); }
182 bool intersects(const Interval& other) const;
183 bool intersects(const Intervals& other) const;
185 bool contains(const Interval& other) const;
186 bool contains(const Intervals& other) const;
188 bool contains_exact(const Interval& other) const;
190 bool operator==(const Intervals& other) const;
191 bool operator!=(const Intervals& other) const { return not (*this == other) ; }
193 Intervals& operator+=(const Interval& other);
194 Intervals& operator-=(const Interval& other);
196 Intervals& operator+=(const Intervals& other);
197 Intervals& operator-=(const Intervals& other);
201 std::list< Interval > m_intervals;
211 bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds);
212 long long monotonic_clock_gettime_nano();
214 bool realtime_clock_gettime(long int& seconds, long int& nano_seconds);