11 #include "gnc-module.h"
12 #include "test-stuff.h"
17 check_time (
Timespec ts, gboolean always_print)
23 ts.tv_nsec = MIN (ts.tv_nsec, 999999999);
38 if (!ok || always_print)
41 "\n%" G_GINT64_FORMAT
":%ld -> %s ->\n"
42 "\t%" G_GINT64_FORMAT
":%ld"
43 " (diff of %" G_GINT64_FORMAT
" secs %ld nsecs)\n",
44 ts.tv_sec, ts.tv_nsec, str,
45 ts_2.tv_sec, ts_2.tv_nsec,
46 ts.tv_sec - ts_2.tv_sec, ts.tv_nsec - ts_2.tv_nsec);
50 failure (
"timespec to iso8601 string conversion failed");
55 success (
"timespec to iso8601 string conversion passes");
61 check_conversion (
const char * str,
Timespec expected_ts)
75 if ((g_date_compare(&d1, &d2) != 0)
76 || (g_date_get_day(&d1) != day)
77 || (g_date_get_month(&d1) != month)
78 || (g_date_get_year(&d1) != year))
81 "\nmis-converted \"%s\" to GDate\n",
83 failure (
"misconverted timespec");
87 if ((expected_ts.tv_sec != ts.tv_sec) || (expected_ts.tv_nsec != ts.tv_nsec))
90 "\nmis-converted \"%s\" to %" G_GUINT64_FORMAT
".%09ld seconds\n"
91 "\twas expecting %" G_GUINT64_FORMAT
".%09ld seconds\n",
92 str, ts.tv_sec, ts.tv_nsec,
93 expected_ts.tv_sec, expected_ts.tv_nsec);
94 failure (
"misconverted timespec");
97 success (
"good conversion");
106 gboolean do_print = FALSE;
125 ts.tv_sec = 10 * 365 * 24 * 3600 + 2 * 24 * 3600;
127 check_conversion (
"1979-12-31 15:00:00.000000 -0900", ts);
128 check_conversion (
"1979-12-31 16:00:00.000000 -0800", ts);
129 check_conversion (
"1979-12-31 17:00:00.000000 -0700", ts);
130 check_conversion (
"1979-12-31 18:00:00.000000 -0600", ts);
131 check_conversion (
"1979-12-31 19:00:00.000000 -0500", ts);
132 check_conversion (
"1979-12-31 20:00:00.000000 -0400", ts);
133 check_conversion (
"1979-12-31 21:00:00.000000 -0300", ts);
134 check_conversion (
"1979-12-31 22:00:00.000000 -0200", ts);
135 check_conversion (
"1979-12-31 23:00:00.000000 -0100", ts);
137 check_conversion (
"1980-01-01 00:00:00.000000 -0000", ts);
138 check_conversion (
"1980-01-01 00:00:00.000000 +0000", ts);
140 check_conversion (
"1980-01-01 01:00:00.000000 +0100", ts);
141 check_conversion (
"1980-01-01 02:00:00.000000 +0200", ts);
142 check_conversion (
"1980-01-01 03:00:00.000000 +0300", ts);
143 check_conversion (
"1980-01-01 04:00:00.000000 +0400", ts);
144 check_conversion (
"1980-01-01 05:00:00.000000 +0500", ts);
145 check_conversion (
"1980-01-01 06:00:00.000000 +0600", ts);
146 check_conversion (
"1980-01-01 07:00:00.000000 +0700", ts);
147 check_conversion (
"1980-01-01 08:00:00.000000 +0800", ts);
150 check_conversion (
"1980-01-01 08:01:00.000000 +0801", ts);
151 check_conversion (
"1980-01-01 08:02:00.000000 +0802", ts);
152 check_conversion (
"1980-01-01 08:03:00.000000 +0803", ts);
153 check_conversion (
"1980-01-01 08:23:00.000000 +0823", ts);
154 check_conversion (
"1980-01-01 08:35:00.000000 +0835", ts);
155 check_conversion (
"1980-01-01 08:47:00.000000 +0847", ts);
156 check_conversion (
"1980-01-01 08:59:00.000000 +0859", ts);
158 check_conversion (
"1979-12-31 15:01:00.000000 -0859", ts);
159 check_conversion (
"1979-12-31 15:02:00.000000 -0858", ts);
160 check_conversion (
"1979-12-31 15:03:00.000000 -0857", ts);
161 check_conversion (
"1979-12-31 15:23:00.000000 -0837", ts);
162 check_conversion (
"1979-12-31 15:45:00.000000 -0815", ts);
166 ts.tv_sec = 20 * 365 * 24 * 3600 + 5 * 24 * 3600;
168 check_conversion (
"1989-12-31 15:00:00.000000 -0900", ts);
169 check_conversion (
"1989-12-31 16:00:00.000000 -0800", ts);
170 check_conversion (
"1989-12-31 17:00:00.000000 -0700", ts);
171 check_conversion (
"1989-12-31 18:00:00.000000 -0600", ts);
172 check_conversion (
"1989-12-31 19:00:00.000000 -0500", ts);
173 check_conversion (
"1989-12-31 20:00:00.000000 -0400", ts);
174 check_conversion (
"1989-12-31 21:00:00.000000 -0300", ts);
175 check_conversion (
"1989-12-31 22:00:00.000000 -0200", ts);
176 check_conversion (
"1989-12-31 23:00:00.000000 -0100", ts);
178 check_conversion (
"1990-01-01 00:00:00.000000 -0000", ts);
179 check_conversion (
"1990-01-01 00:00:00.000000 +0000", ts);
181 check_conversion (
"1990-01-01 01:00:00.000000 +0100", ts);
182 check_conversion (
"1990-01-01 02:00:00.000000 +0200", ts);
183 check_conversion (
"1990-01-01 03:00:00.000000 +0300", ts);
184 check_conversion (
"1990-01-01 04:00:00.000000 +0400", ts);
185 check_conversion (
"1990-01-01 05:00:00.000000 +0500", ts);
186 check_conversion (
"1990-01-01 06:00:00.000000 +0600", ts);
187 check_conversion (
"1990-01-01 07:00:00.000000 +0700", ts);
188 check_conversion (
"1990-01-01 08:00:00.000000 +0800", ts);
191 check_conversion (
"1990-01-01 08:01:00.000000 +0801", ts);
192 check_conversion (
"1990-01-01 08:02:00.000000 +0802", ts);
193 check_conversion (
"1990-01-01 08:03:00.000000 +0803", ts);
194 check_conversion (
"1990-01-01 08:23:00.000000 +0823", ts);
195 check_conversion (
"1990-01-01 08:35:00.000000 +0835", ts);
196 check_conversion (
"1990-01-01 08:47:00.000000 +0847", ts);
197 check_conversion (
"1990-01-01 08:59:00.000000 +0859", ts);
199 check_conversion (
"1989-12-31 15:01:00.000000 -0859", ts);
200 check_conversion (
"1989-12-31 15:02:00.000000 -0858", ts);
201 check_conversion (
"1989-12-31 15:03:00.000000 -0857", ts);
202 check_conversion (
"1989-12-31 15:23:00.000000 -0837", ts);
203 check_conversion (
"1989-12-31 15:45:00.000000 -0815", ts);
207 ts.tv_sec = 30 * 365 * 24 * 3600 + 7 * 24 * 3600;
209 check_conversion (
"1999-12-31 15:00:00.000000 -0900", ts);
210 check_conversion (
"1999-12-31 16:00:00.000000 -0800", ts);
211 check_conversion (
"1999-12-31 17:00:00.000000 -0700", ts);
212 check_conversion (
"1999-12-31 18:00:00.000000 -0600", ts);
213 check_conversion (
"1999-12-31 19:00:00.000000 -0500", ts);
214 check_conversion (
"1999-12-31 20:00:00.000000 -0400", ts);
215 check_conversion (
"1999-12-31 21:00:00.000000 -0300", ts);
216 check_conversion (
"1999-12-31 22:00:00.000000 -0200", ts);
217 check_conversion (
"1999-12-31 23:00:00.000000 -0100", ts);
219 check_conversion (
"2000-01-01 00:00:00.000000 -0000", ts);
220 check_conversion (
"2000-01-01 00:00:00.000000 +0000", ts);
222 check_conversion (
"2000-01-01 01:00:00.000000 +0100", ts);
223 check_conversion (
"2000-01-01 02:00:00.000000 +0200", ts);
224 check_conversion (
"2000-01-01 03:00:00.000000 +0300", ts);
225 check_conversion (
"2000-01-01 04:00:00.000000 +0400", ts);
226 check_conversion (
"2000-01-01 05:00:00.000000 +0500", ts);
227 check_conversion (
"2000-01-01 06:00:00.000000 +0600", ts);
228 check_conversion (
"2000-01-01 07:00:00.000000 +0700", ts);
229 check_conversion (
"2000-01-01 08:00:00.000000 +0800", ts);
232 check_conversion (
"2000-01-01 08:01:00.000000 +0801", ts);
233 check_conversion (
"2000-01-01 08:02:00.000000 +0802", ts);
234 check_conversion (
"2000-01-01 08:03:00.000000 +0803", ts);
235 check_conversion (
"2000-01-01 08:23:00.000000 +0823", ts);
236 check_conversion (
"2000-01-01 08:35:00.000000 +0835", ts);
237 check_conversion (
"2000-01-01 08:47:00.000000 +0847", ts);
238 check_conversion (
"2000-01-01 08:59:00.000000 +0859", ts);
240 check_conversion (
"1999-12-31 15:01:00.000000 -0859", ts);
241 check_conversion (
"1999-12-31 15:02:00.000000 -0858", ts);
242 check_conversion (
"1999-12-31 15:03:00.000000 -0857", ts);
243 check_conversion (
"1999-12-31 15:23:00.000000 -0837", ts);
244 check_conversion (
"1999-12-31 15:45:00.000000 -0815", ts);
248 ts.tv_sec = 35 * 365 * 24 * 3600 + 9 * 24 * 3600;
250 check_conversion (
"2004-12-31 15:00:00.000000 -0900", ts);
251 check_conversion (
"2004-12-31 16:00:00.000000 -0800", ts);
252 check_conversion (
"2004-12-31 17:00:00.000000 -0700", ts);
253 check_conversion (
"2004-12-31 18:00:00.000000 -0600", ts);
254 check_conversion (
"2004-12-31 19:00:00.000000 -0500", ts);
255 check_conversion (
"2004-12-31 20:00:00.000000 -0400", ts);
256 check_conversion (
"2004-12-31 21:00:00.000000 -0300", ts);
257 check_conversion (
"2004-12-31 22:00:00.000000 -0200", ts);
258 check_conversion (
"2004-12-31 23:00:00.000000 -0100", ts);
260 check_conversion (
"2005-01-01 00:00:00.000000 -0000", ts);
261 check_conversion (
"2005-01-01 00:00:00.000000 +0000", ts);
263 check_conversion (
"2005-01-01 01:00:00.000000 +0100", ts);
264 check_conversion (
"2005-01-01 02:00:00.000000 +0200", ts);
265 check_conversion (
"2005-01-01 03:00:00.000000 +0300", ts);
266 check_conversion (
"2005-01-01 04:00:00.000000 +0400", ts);
267 check_conversion (
"2005-01-01 05:00:00.000000 +0500", ts);
268 check_conversion (
"2005-01-01 06:00:00.000000 +0600", ts);
269 check_conversion (
"2005-01-01 07:00:00.000000 +0700", ts);
270 check_conversion (
"2005-01-01 08:00:00.000000 +0800", ts);
273 check_conversion (
"2005-01-01 08:01:00.000000 +0801", ts);
274 check_conversion (
"2005-01-01 08:02:00.000000 +0802", ts);
275 check_conversion (
"2005-01-01 08:03:00.000000 +0803", ts);
276 check_conversion (
"2005-01-01 08:23:00.000000 +0823", ts);
277 check_conversion (
"2005-01-01 08:35:00.000000 +0835", ts);
278 check_conversion (
"2005-01-01 08:47:00.000000 +0847", ts);
279 check_conversion (
"2005-01-01 08:59:00.000000 +0859", ts);
281 check_conversion (
"2004-12-31 15:01:00.000000 -0859", ts);
282 check_conversion (
"2004-12-31 15:02:00.000000 -0858", ts);
283 check_conversion (
"2004-12-31 15:03:00.000000 -0857", ts);
284 check_conversion (
"2004-12-31 15:23:00.000000 -0837", ts);
285 check_conversion (
"2004-12-31 15:45:00.000000 -0815", ts);
290 check_time (ts, do_print);
293 check_time (ts, do_print);
296 check_time (ts, do_print);
299 check_time (ts, do_print);
302 check_time (ts, do_print);
305 check_time (ts, do_print);
308 check_time (ts, do_print);
311 check_time (ts, do_print);
314 check_time (ts, do_print);
319 ts.tv_sec = (
long long int) 0x7fffffff + 3600 * 24 * 10;
320 check_time(ts, do_print);
323 ts.tv_sec = 152098136;
325 check_time (ts, do_print);
327 ts.tv_sec = 1162088421;
328 ts.tv_nsec = 12548000;
329 check_time (ts, do_print);
331 ts.tv_sec = 325659000 - 6500;
333 check_time (ts, do_print);
335 ts.tv_sec = 1143943200;
337 check_time (ts, do_print);
339 ts.tv_sec = 1603591171;
340 ts.tv_nsec = 595311000;
341 check_time (ts, do_print);
343 ts.tv_sec = 1738909365;
344 ts.tv_nsec = 204102000;
345 check_time (ts, do_print);
347 ts.tv_sec = 1603591171;
348 ts.tv_nsec = 595311000;
349 check_time (ts, do_print);
351 ts.tv_sec = 1143943200 - 1;
353 check_time (ts, do_print);
355 ts.tv_sec = 1143943200;
357 check_time (ts, do_print);
359 ts.tv_sec = 1143943200 + (7 * 60 * 60);
361 check_time (ts, do_print);
363 ts.tv_sec = 1143943200 + (8 * 60 * 60);
365 check_time (ts, do_print);
367 ts = *get_random_timespec ();
369 for (i = 0; i < 10000; i++)
372 if (!check_time (ts, FALSE))
376 for (i = 0; i < 5000; i++)
378 ts = *get_random_timespec ();
380 if (!check_time (ts, FALSE))
386 main (
int argc,
char **argv)
390 success (
"dates seem to work");
392 print_test_results();
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
Date and Time handling routines.
gboolean timespec_equal(const Timespec *ta, const Timespec *tb)
Use a 64-bit unsigned int timespec.
GDate timespec_to_gdate(Timespec ts)
Timespec gnc_iso8601_to_timespec_gmt(const gchar *)
Timespec gdate_to_timespec(GDate d)
void gnc_timespec2dmy(Timespec ts, gint *day, gint *month, gint *year)