4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_BROKEN_TIME_HPP
25 #define XCSOAR_BROKEN_TIME_HPP
29 #include <type_traits>
34 * A broken-down representation of a time.
53 * Non-initializing default constructor.
55 BrokenTime() = default;
58 BrokenTime(unsigned _hour
, unsigned _minute
, unsigned _second
=0)
59 :hour(_hour
), minute(_minute
), second(_second
) {}
62 bool operator==(const BrokenTime other
) const {
63 return hour
== other
.hour
&& minute
== other
.minute
&&
64 second
== other
.second
;
68 bool operator>(const BrokenTime other
) const {
69 return hour
> other
.hour
||
70 (hour
== other
.hour
&& (minute
> other
.minute
||
71 (minute
== other
.minute
&& second
> other
.second
)));
75 * Returns an instance that fails the Plausible() check.
78 static BrokenTime
Invalid() {
79 return BrokenTime(24, 60, 60);
83 * Does this object contain plausible values?
86 bool Plausible() const {
87 return hour
< 24 && minute
< 60 && second
< 60;
91 * Returns the number of seconds which have passed on this day.
94 unsigned GetSecondOfDay() const {
95 return hour
* 3600u + minute
* 60u + second
;
99 * Construct a BrokenTime object from the specified number of
100 * seconds which have passed on this day.
102 * @param second_of_day 0 .. 3600*24-1
105 static BrokenTime
FromSecondOfDay(unsigned second_of_day
);
108 * A wrapper for FromSecondOfDay() which allows values bigger than
109 * or equal to 3600*24.
112 static BrokenTime
FromSecondOfDayChecked(unsigned second_of_day
);
115 * Returns a BrokenTime that has the specified number of seconds
116 * added to it. It properly wraps around midnight.
118 * @param seconds the number of seconds to add
121 BrokenTime
operator+(unsigned seconds
) const;
124 * Returns a BrokenTime that has the specified number of seconds
125 * added to it. It properly wraps around midnight.
127 * @param seconds the number of seconds to add; may be negative
130 BrokenTime
operator+(int seconds
) const;
133 BrokenTime
operator-(int seconds
) const {
134 return *this + (-seconds
);
138 BrokenTime
operator-(unsigned seconds
) const {
139 return *this - int(seconds
);
143 static_assert(std::is_trivial
<BrokenTime
>::value
, "type is not trivial");