3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Time/BrokenDateTime.hpp"
24 #include "TestUtil.hpp"
31 ok1(BrokenDate(2010, 1, 2).year
== 2010);
32 ok1(BrokenDate(2010, 1, 2).month
== 1);
33 ok1(BrokenDate(2010, 1, 2).day
== 2);
35 ok1(BrokenDate(2010, 1, 1) == BrokenDate(2010, 1, 1));
36 ok1(!(BrokenDate(2010, 1, 1) == BrokenDate(2010, 1, 2)));
37 ok1(!(BrokenDate(2010, 1, 1) == BrokenDate(2010, 2, 1)));
38 ok1(!(BrokenDate(2010, 1, 1) == BrokenDate(2011, 1, 1)));
40 ok1(!(BrokenDate(2010, 1, 1) > BrokenDate(2010, 1, 1)));
41 ok1(!(BrokenDate(2010, 1, 1) > BrokenDate(2010, 1, 2)));
42 ok1(BrokenDate(2010, 1, 2) > BrokenDate(2010, 1, 1));
44 ok1(!(BrokenDate(2010, 1, 1) > BrokenDate(2010, 1, 1)));
45 ok1(!(BrokenDate(2010, 1, 1) > BrokenDate(2010, 1, 2)));
46 ok1(BrokenDate(2010, 2, 1) > BrokenDate(2010, 1, 1));
48 ok1(!(BrokenDate(2010, 1, 1) > BrokenDate(2010, 1, 1)));
49 ok1(!(BrokenDate(2010, 1, 1) > BrokenDate(2011, 1, 1)));
50 ok1(BrokenDate(2011, 1, 1) > BrokenDate(2010, 1, 1));
52 ok1(BrokenDate(2011, 1, 1).Plausible());
53 ok1(BrokenDate(2011, 12, 31).Plausible());
54 ok1(BrokenDate(2500, 1, 1).Plausible());
55 ok1(BrokenDate(1800, 1, 1).Plausible());
56 ok1(!BrokenDate(2501, 1, 1).Plausible());
57 ok1(!BrokenDate(1799, 1, 1).Plausible());
58 ok1(!BrokenDate(2011, 1, 0).Plausible());
59 ok1(!BrokenDate(2011, 0, 1).Plausible());
60 ok1(!BrokenDate(2011, 13, 1).Plausible());
61 ok1(!BrokenDate(2011, 1, 32).Plausible());
63 BrokenDate
d(2010, 2, 27);
65 ok1(d
== BrokenDate(2010, 2, 28));
67 ok1(d
== BrokenDate(2010, 3, 1));
69 d
= BrokenDate(2010, 12, 31);
71 ok1(d
== BrokenDate(2011, 1, 1));
73 d
= BrokenDate(2012, 2, 27);
75 ok1(d
== BrokenDate(2012, 2, 28));
77 ok1(d
== BrokenDate(2012, 2, 29));
79 ok1(d
== BrokenDate(2012, 3, 1));
85 ok1(BrokenTime(12, 15).hour
== 12);
86 ok1(BrokenTime(12, 15).minute
== 15);
87 ok1(BrokenTime(12, 15).second
== 0);
89 ok1(BrokenTime(12, 15, 30).hour
== 12);
90 ok1(BrokenTime(12, 15, 30).minute
== 15);
91 ok1(BrokenTime(12, 15, 30).second
== 30);
93 ok1(BrokenTime(12, 15, 30) == BrokenTime(12, 15, 30));
94 ok1(!(BrokenTime(12, 15, 30) == BrokenTime(12, 15, 31)));
95 ok1(!(BrokenTime(12, 15, 30) == BrokenTime(12, 16, 30)));
96 ok1(!(BrokenTime(12, 15, 30) == BrokenTime(13, 15, 30)));
98 ok1(!(BrokenTime(12, 15, 30) > BrokenTime(12, 15, 30)));
99 ok1(!(BrokenTime(12, 15, 30) > BrokenTime(12, 15, 31)));
100 ok1(BrokenTime(12, 15, 31) > BrokenTime(12, 15, 30));
102 ok1(!(BrokenTime(12, 15, 30) > BrokenTime(12, 15, 30)));
103 ok1(!(BrokenTime(12, 15, 30) > BrokenTime(2010, 16, 30)));
104 ok1(BrokenTime(12, 16, 30) > BrokenTime(12, 15, 30));
106 ok1(!(BrokenTime(12, 15, 30) > BrokenTime(12, 15, 30)));
107 ok1(!(BrokenTime(12, 15, 30) > BrokenTime(13, 15, 30)));
108 ok1(BrokenTime(13, 15, 30) > BrokenTime(12, 15, 30));
110 ok1(BrokenTime(23, 59, 59).Plausible());
111 ok1(BrokenTime(0, 0, 0).Plausible());
112 ok1(!BrokenTime(24, 0, 0).Plausible());
113 ok1(!BrokenTime(12, 60, 1).Plausible());
114 ok1(!BrokenTime(12, 15, 60).Plausible());
116 ok1(BrokenTime(12, 15, 30).GetSecondOfDay() == 44130);
117 ok1(BrokenTime::FromSecondOfDay(44130) == BrokenTime(12, 15, 30));
118 ok1(BrokenTime::FromSecondOfDayChecked(130530) == BrokenTime(12, 15, 30));
120 ok1(BrokenTime(12, 15) + 120 == BrokenTime(12, 17));
121 ok1(BrokenTime(23, 59) + 120 == BrokenTime(0, 1));
122 ok1(BrokenTime(23, 59) + 120 == BrokenTime(0, 1));
123 ok1(BrokenTime(0, 1) - 120 == BrokenTime(23, 59));
124 ok1(BrokenTime(0, 1) - 120u == BrokenTime(23, 59));
130 ok1(BrokenDateTime(2010, 1, 2).year
== 2010);
131 ok1(BrokenDateTime(2010, 1, 2).month
== 1);
132 ok1(BrokenDateTime(2010, 1, 2).day
== 2);
133 ok1(BrokenDateTime(2010, 1, 2).hour
== 0);
134 ok1(BrokenDateTime(2010, 1, 2).minute
== 0);
135 ok1(BrokenDateTime(2010, 1, 2).second
== 0);
137 ok1(BrokenDateTime(2010, 1, 2, 12, 15).year
== 2010);
138 ok1(BrokenDateTime(2010, 1, 2, 12, 15).month
== 1);
139 ok1(BrokenDateTime(2010, 1, 2, 12, 15).day
== 2);
140 ok1(BrokenDateTime(2010, 1, 2, 12, 15).hour
== 12);
141 ok1(BrokenDateTime(2010, 1, 2, 12, 15).minute
== 15);
142 ok1(BrokenDateTime(2010, 1, 2, 12, 15).second
== 0);
144 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).year
== 2010);
145 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).month
== 1);
146 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).day
== 2);
147 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).hour
== 12);
148 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).minute
== 15);
149 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).second
== 30);
151 ok1(BrokenDateTime(2010, 2, 28, 23, 0, 0) == BrokenDateTime(2010, 2, 28, 23, 0, 0));
152 ok1(BrokenDateTime(2010, 2, 28, 23, 0, 0) + 3600 == BrokenDateTime(2010, 3, 1));
153 ok1(BrokenDateTime(2010, 2, 28, 23, 59, 59) + 1 == BrokenDateTime(2010, 3, 1));
154 ok1(BrokenDateTime(2010, 2, 28, 23, 59, 59) + 2 == BrokenDateTime(2010, 3, 1, 0, 0, 1));
155 ok1(BrokenDateTime(2010, 12, 31, 23, 59, 59) + 1 == BrokenDateTime(2011, 1, 1));
157 ok1(BrokenDateTime(2010, 1, 2, 12, 15, 30).ToUnixTimeUTC() == 1262434530);
159 ok1(BrokenDateTime(2010, 1, 1, 0, 0 ,1) -
160 BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 1);
161 ok1(BrokenDateTime(2010, 1, 1, 0, 1 ,0) -
162 BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 60);
163 ok1(BrokenDateTime(2010, 1, 1, 1, 0 ,0) -
164 BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 60 * 60);
165 ok1(BrokenDateTime(2010, 1, 2, 0, 0 ,0) -
166 BrokenDateTime(2010, 1, 1, 0, 0 ,0) == 60 * 60 * 24);
169 int main(int argc
, char **argv
)
177 return exit_status();