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);
37 * @brief structure representing a single (half-open) interval.
50 Interval( unsigned int start, unsigned int end, int weak_mark= 0 )
51 : m_lower_bound(start)
53 , m_weak_mark(weak_mark)
63 return m_lower_bound <= m_upper_bound;
64 } // eo is_valid() const
68 return m_lower_bound == m_upper_bound;
72 unsigned int lower_bound() const { return m_lower_bound; }
73 unsigned int upper_bound() const { return m_upper_bound; }
75 int weak_mark() const { return m_weak_mark; }
77 bool changed() const { return m_changed; }
80 bool operator== (const Interval& other) const
82 return m_lower_bound == other.m_lower_bound and m_upper_bound == other.m_upper_bound;
83 } // eo operator==(const Interval&)
86 bool operator!=(const Interval& other) const
88 return not (*this == other);
89 } // eo operator!=(const Interval&)
93 * @brief less operator. compares only the start times!
94 * @param other the other interval to compare with.
95 * @return @a true if the current start is less than the other start.
97 bool operator<(const Interval& other) const
99 return m_lower_bound < other.m_lower_bound;
100 } // eo operator<(const Interval&)
103 bool intersects(const Interval& other) const;
104 bool contains(const Interval& other) const;
109 friend class Intervals;
111 unsigned int m_lower_bound;
112 unsigned int m_upper_bound;
122 * @brief structure representing a combination of single disjoint (half open) intervals.
124 * Basic idea is that this structure provides an interface for adding and
125 * subtracting single intervals and keeps the internal list of intervals as
126 * a list of disjoint intervals.
128 * @note the list is sorted by the start; lower comes first.
130 * @note the class provides some methods similar to STL container classes;
131 * i.e. it can be used with (at least some) STL algorithms.
134 * we use a std::list for the intervals; this means we don't invalidate all
135 * iterators when we insert or delete within loops...
136 * And we use that fact!!
141 typedef std::list< Interval > IntervalList;
142 typedef IntervalList::value_type value_type;
143 typedef IntervalList::const_iterator const_iterator;
144 typedef IntervalList::const_iterator iterator; // we allow only const...
145 typedef IntervalList::size_type size_type;
150 void add(const Interval& new_frame);
151 void sub(const Interval& new_frame);
155 const_iterator begin() const { return m_intervals.begin(); }
156 const_iterator end() const { return m_intervals.end(); }
158 bool empty() const { return m_intervals.empty(); }
159 const Interval& front() const { return m_intervals.front(); }
160 const Interval& back() const { return m_intervals.back(); }
162 size_type size() const { return m_intervals.size(); }
164 bool intersects(const Interval& other) const;
165 bool intersects(const Intervals& other) const;
167 bool contains(const Interval& other) const;
168 bool contains(const Intervals& other) const;
170 bool contains_exact(const Interval& other) const;
172 bool operator==(const Intervals& other) const;
173 bool operator!=(const Intervals& other) const { return not (*this == other) ; }
175 Intervals& operator+=(const Interval& other);
176 Intervals& operator-=(const Interval& other);
178 Intervals& operator+=(const Intervals& other);
179 Intervals& operator-=(const Intervals& other);
183 std::list< Interval > m_intervals;
193 bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds);
194 long long monotonic_clock_gettime_nano();
196 bool realtime_clock_gettime(long int& seconds, long int& nano_seconds);