GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-gnc-date.c
1 /********************************************************************
2  * utest-gnc-date.c: GLib g_test test suite for gnc-date.c. *
3  * Copyright 2012 John Ralls <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, you can retrieve it from *
17  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html *
18  * or contact: *
19  * *
20  * Free Software Foundation Voice: +1-617-542-5942 *
21  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
22  * Boston, MA 02110-1301, USA [email protected] *
23  ********************************************************************/
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
29 #include <config.h>
30 #include <string.h>
31 #include <glib.h>
32 #include <unittest-support.h>
33 /* Add specific headers for this class */
34 
35 #ifdef __cplusplus
36 }
37 #endif
38 
39 #include "../gnc-date.h"
40 #include "../gnc-date-p.h"
41 #include <locale.h>
42 #include <glib/gprintf.h>
43 #ifndef HAVE_STRPTIME
44 # include "strptime.h"
45 #endif
46 
47 #ifdef HAVE_GLIB_2_38
48 #define _Q "'"
49 #else
50 #define _Q "`"
51 #endif
52 
53 static const gchar *suitename = "/qof/gnc-date";
54 void test_suite_gnc_date ( void );
55 
56 typedef struct
57 {
58  GDateTime *(*new_local)(gint, gint, gint, gint, gint, gdouble);
59  GDateTime *(*adjust_for_dst)(GDateTime *, GTimeZone *);
60  GDateTime *(*new_from_unix_local)(time64);
61  GDateTime *(*new_from_timeval_local)(GTimeVal *);
62  GDateTime *(*new_now_local)(void);
63  GDateTime *(*to_local)(GDateTime *);
64 } _GncDateTime;
65 
66 static _GncDateTime gncdt;
67 #ifdef __cplusplus
68 extern "C"
69 {
70 #endif
71 
72 extern void _gnc_date_time_init (_GncDateTime *);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 /* gnc_localtime just creates a tm on the heap and calls
79  * gnc_localtime_r with it, so this suffices to test both.
80  */
81 static void
82 test_gnc_localtime (void)
83 {
84  time64 secs[6] = {-43238956734LL, -1123692LL, 432761LL,
85  723349832LL, 887326459367LL,
86  1364160236LL // This is "Sunday 2013-03-24" (to verify the Sunday
87  // difference between g_date_time and tm->tm_wday)
88  };
89  guint ind;
90 #if defined(__clang__)
91 #define _func "struct tm *gnc_localtime_r(const time64 *, struct tm *)"
92 #else
93 #define _func "tm* gnc_localtime_r(const time64*, tm*)"
94 //#define _func "gnc_localtime_r"
95 #endif
96  gchar *msg = _func ": assertion " _Q "gdt != NULL' failed";
97 #undef _func
98  gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
99  gchar *logdomain = "qof";
100  TestErrorStruct check = {loglevel, logdomain, msg, 0};
101  GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
102  g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
103 
104  for (ind = 0; ind < G_N_ELEMENTS (secs); ind++)
105  {
106  struct tm* time = gnc_localtime (&secs[ind]);
107  GDateTime *gdt = gncdt.new_from_unix_local (secs[ind]);
108  if (gdt == NULL)
109  {
110  g_assert (time == NULL);
111  continue;
112  }
113  g_assert_cmpint (time->tm_year + 1900, ==, g_date_time_get_year (gdt));
114  g_assert_cmpint (time->tm_mon + 1, ==, g_date_time_get_month (gdt));
115  g_assert_cmpint (time->tm_mday, ==, g_date_time_get_day_of_month (gdt));
116  g_assert_cmpint (time->tm_hour, ==, g_date_time_get_hour (gdt));
117  g_assert_cmpint (time->tm_min, ==, g_date_time_get_minute (gdt));
118  g_assert_cmpint (time->tm_sec, ==, g_date_time_get_second (gdt));
119  // Watch out: struct tm has wday=0..6 with Sunday=0, but GDateTime has wday=1..7 with Sunday=7.
120  g_assert_cmpint (time->tm_wday, ==, (g_date_time_get_day_of_week (gdt) % 7));
121  g_assert_cmpint (time->tm_yday, ==, g_date_time_get_day_of_year (gdt));
122  if (g_date_time_is_daylight_savings (gdt))
123  g_assert_cmpint (time->tm_isdst, ==, 1);
124  else
125  g_assert_cmpint (time->tm_isdst, ==, 0);
126 #ifdef HAVE_STRUCT_TM_GMTOFF
127  g_assert_cmpint (time->tm_gmtoff, ==,
128  g_date_time_get_utc_offset (gdt) / G_TIME_SPAN_SECOND);
129 #endif
130  g_date_time_unref (gdt);
131  gnc_tm_free (time);
132  }
133  g_assert_cmpint (check.hits, ==, 1);
134  g_log_set_default_handler (hdlr, NULL);
135 }
136 
137 static void
138 test_gnc_gmtime (void)
139 {
140  time64 secs[6] = {-43238956734LL, -1123692LL, 432761LL,
141  723349832LL, 887326459367LL, 1175964426LL
142  };
143  struct tm answers[6] =
144  {
145 #ifdef HAVE_STRUCT_TM_GMTOFF
146  { 6, 41, 2, 24, 9, -1301, 4, 297, 0, 0, NULL },
147  { 48, 51, 23, 18, 11, 69, 4, 352, 0, 0, NULL },
148  { 41, 12, 0, 6, 0, 70, 2, 6, 0, 0, NULL },
149  { 32, 30, 2, 3, 11, 92, 4, 338, 0, 0, NULL },
150  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
151  { 6, 47, 16, 7, 3, 107, 6, 97, 0, 0, NULL },
152 #else
153  { 6, 41, 2, 24, 9, -1301, 4, 297, 0 },
154  { 48, 51, 23, 18, 11, 69, 4, 352, 0 },
155  { 41, 12, 0, 6, 0, 70, 2, 6, 0 },
156  { 32, 30, 2, 3, 11, 92, 4, 338, 0 },
157  { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
158  { 6, 47, 16, 7, 3, 107, 6, 97, 0 },
159 #endif
160  };
161  guint ind;
162 #if defined(__clang__)
163 #define _func "struct tm *gnc_gmtime(const time64 *)"
164 #else
165 #define _func "tm* gnc_gmtime(const time64*)"
166 //#define _func "gnc_gmtime"
167 #endif
168  gchar *msg = _func ": assertion " _Q "gdt != NULL' failed";
169 #undef _func
170  gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
171  gchar *logdomain = "qof";
172  TestErrorStruct check = {loglevel, logdomain, msg, 0};
173  GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
174  g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
175 
176  for (ind = 0; ind < G_N_ELEMENTS (secs); ind++)
177  {
178  struct tm* time = gnc_gmtime (&secs[ind]);
179  GDateTime *gdt = g_date_time_new_from_unix_utc (secs[ind]);
180  if (gdt == NULL)
181  {
182  g_assert (time == NULL);
183  continue;
184  }
185  g_assert_cmpint (time->tm_year, ==, answers[ind].tm_year);
186  g_assert_cmpint (time->tm_mon, ==, answers[ind].tm_mon);
187  g_assert_cmpint (time->tm_mday, ==, answers[ind].tm_mday);
188  g_assert_cmpint (time->tm_hour, ==, answers[ind].tm_hour);
189  g_assert_cmpint (time->tm_min, ==, answers[ind].tm_min);
190  g_assert_cmpint (time->tm_sec, ==, answers[ind].tm_sec);
191  g_assert_cmpint (time->tm_wday, ==, answers[ind].tm_wday);
192  g_assert_cmpint (time->tm_yday, ==, answers[ind].tm_yday);
193  g_assert_cmpint (time->tm_isdst, ==, 0);
194 #ifdef HAVE_STRUCT_TM_GMTOFF
195  g_assert_cmpint (time->tm_gmtoff, ==, 0);
196 #endif
197  g_date_time_unref (gdt);
198  gnc_tm_free (time);
199  }
200  g_assert_cmpint (check.hits, ==, 1);
201  g_log_set_default_handler (hdlr, NULL);
202 }
203 
204 static void
205 test_gnc_mktime (void)
206 {
207  struct
208  {
209  time64 secs;
210  gint wday;
211  gint yday;
212  } ans[5] =
213  {
214  { -43238956734LL, 4, 297 },
215  { -1123692LL, 4, 352 },
216  { 432761LL, 2, 6 },
217  { 723349832LL, 4, 338 },
218  { 1175964426LL, 6, 97 }
219  };
220 
221  struct tm time[5] =
222  {
223 #ifdef HAVE_STRUCT_TM_GMTOFF
224  { 6, 41, 2, 24, 9, -1301, 0, 0, -1, 0, NULL },
225  { 48, 51, 23, 18, 11, 69, 0, 0, -1, 0, NULL },
226  { 41, 12, 0, 6, 0, 70, 0, 0, -1, 0, NULL },
227  { 32, 30, 2, 3, 11, 92, 0, 0, -1, 0, NULL },
228  { 6, 47, 16, 7, 3, 107, 0, 0, -1, 0, NULL },
229 #else
230  { 6, 41, 2, 24, 9, -1301, 0, 0, -1 },
231  { 48, 51, 23, 18, 11, 69, 0, 0, -1 },
232  { 41, 12, 0, 6, 0, 70, 0, 0, -1 },
233  { 32, 30, 2, 3, 11, 92, 0, 0, -1 },
234  { 6, 47, 16, 7, 3, 107, 0, 0, -1 },
235 #endif
236  };
237  guint ind;
238 
239  for (ind = 0; ind < G_N_ELEMENTS (time); ind++)
240  {
241  time64 secs = gnc_mktime (&time[ind]);
242  GDateTime *gdt = gncdt.new_local (time[ind].tm_year + 1900,
243  time[ind].tm_mon + 1,
244  time[ind].tm_mday,
245  time[ind].tm_hour,
246  time[ind].tm_min,
247  (gdouble)time[ind].tm_sec);
248  time64 offset = g_date_time_get_utc_offset (gdt) / G_TIME_SPAN_SECOND;
249  g_assert_cmpint (secs, ==, ans[ind].secs - offset);
250  g_assert_cmpint (time[ind].tm_wday, ==, ans[ind].wday);
251  g_assert_cmpint (time[ind].tm_yday, ==, ans[ind].yday);
252  if (g_date_time_is_daylight_savings (gdt))
253  g_assert_cmpint (time[ind].tm_isdst, ==, 1);
254  else
255  g_assert_cmpint (time[ind].tm_isdst, ==, 0);
256 
257 #ifdef HAVE_STRUCT_TM_GMTOFF
258  g_assert_cmpint (time[ind].tm_gmtoff, ==, offset);
259 #endif
260  g_date_time_unref (gdt);
261  }
262 }
263 
264 /* In addition to computing a time offset from a struct tm, mktime is
265  * supposed to normalize struct tms with out-of-range values. This
266  * second test exercises that facility in gnc_mktime.
267  */
268 static void
269 test_gnc_mktime_normalization (void)
270 {
271  struct answer
272  {
273  time64 secs;
274  gint wday;
275  gint yday;
276  } ans = { 723349832LL, 4, 338 };
277 
278  struct tm normal_time =
279 #ifdef HAVE_STRUCT_TM_GMTOFF
280  {
281  32, 30, 2, 3, 11, 92, 0, 0, -1, 0, NULL
282  };
283 #else
284  {
285  32, 30, 2, 3, 11, 92, 0, 0, -1
286  };
287 #endif
288 
289  struct tm time[4] =
290  {
291 #ifdef HAVE_STRUCT_TM_GMTOFF
292  { 92, -31, 27, -29, 24, 91, 0, 0, -1, 0, NULL },
293  { -28, 91, -47, 35, -2, 93, 0, 0, -1, 0, NULL },
294  { -28, 91, -47, 66, -3, 93, 0, 0, -1, 0, NULL },
295  { -28, 91, -47, 35, -26, 95, 0, 0, -1, 0, NULL },
296 #else
297  { 92, -31, 27, -29, 24, 91, 0, 0, -1 },
298  { -28, 91, -47, 35, -2, 93, 0, 0, -1 },
299  { -28, 91, -47, 66, -3, 93, 0, 0, -1 },
300  { -28, 91, -47, 35, -26, 95, 0, 0, -1 },
301 #endif
302  };
303  guint ind;
304  for (ind = 0; ind < G_N_ELEMENTS (time); ind++)
305  {
306  time64 secs = gnc_mktime (&time[ind]);
307  GDateTime *gdt = gncdt.new_local (time[ind].tm_year + 1900,
308  time[ind].tm_mon + 1,
309  time[ind].tm_mday,
310  time[ind].tm_hour,
311  time[ind].tm_min,
312  (gdouble)time[ind].tm_sec);
313  time64 offset = g_date_time_get_utc_offset (gdt) / G_TIME_SPAN_SECOND;
314  g_assert_cmpfloat (time[ind].tm_sec, ==, normal_time.tm_sec);
315  g_assert_cmpint (time[ind].tm_min, ==, normal_time.tm_min);
316  g_assert_cmpint (time[ind].tm_hour, ==, normal_time.tm_hour);
317  g_assert_cmpint (time[ind].tm_mday, ==, normal_time.tm_mday);
318  g_assert_cmpint (time[ind].tm_mon, ==, normal_time.tm_mon);
319  g_assert_cmpint (time[ind].tm_year, ==, normal_time.tm_year);
320  g_assert_cmpint (secs, ==, ans.secs - offset);
321  g_assert_cmpint (time[ind].tm_wday, ==, ans.wday);
322  g_assert_cmpint (time[ind].tm_yday, ==, ans.yday);
323  if (g_date_time_is_daylight_savings (gdt))
324  g_assert_cmpint (time[ind].tm_isdst, ==, 1);
325  else
326  g_assert_cmpint (time[ind].tm_isdst, ==, 0);
327 #ifdef HAVE_STRUCT_TM_GMTOFF
328  g_assert_cmpint (time[ind].tm_gmtoff, ==, offset);
329 #endif
330  g_date_time_unref (gdt);
331  }
332 }
333 
334 static void
335 test_gnc_ctime (void)
336 {
337  time64 secs[5] = {-43238956734LL, -1123692LL, 432761LL,
338  723349832LL, 1175964426LL
339  };
340  guint ind;
341  for (ind = 0; ind < G_N_ELEMENTS (secs); ind++)
342  {
343  GDateTime *gdt = gncdt.new_from_unix_local (secs[ind]);
344  gchar* datestr = gnc_ctime (&secs[ind]);
345  g_assert_cmpstr (datestr, ==,
346  g_date_time_format (gdt, "%a %b %e %H:%M:%S %Y"));
347  g_date_time_unref (gdt);
348  g_free (datestr);
349  }
350 }
351 
352 static void
353 test_gnc_time (void)
354 {
355  time64 secs1, secs2;
356  GDateTime *gdt;
357  secs1 = gnc_time (NULL);
358  secs1 = gnc_time (&secs2);
359  gdt = gncdt.new_now_local ();
360  g_assert_cmpint (secs1, ==, secs2);
361  g_assert_cmpint (secs1, ==, g_date_time_to_unix (gdt));
362  g_date_time_unref (gdt);
363 }
364 
365 /* gnc_difftime and gnc_tm_free are just too simple to bother testing. */
366 
367 /* gnc_date_dateformat_to_string
368 const char *gnc_default_strftime_date_format =
369 const char*
370 gnc_date_dateformat_to_string(QofDateFormat format)// C: 1 Local: 0:0:0
371 */
372 
373 static void
374 test_gnc_date_dateformat_to_string (void)
375 {
376  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_US), ==, "us");
377  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_UK), ==, "uk");
378  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_CE), ==, "ce");
379  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_ISO), ==, "iso");
380  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_UTC), ==, "utc");
381  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_LOCALE), ==, "locale");
382  g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_CUSTOM), ==, "custom");
383 
384 }
385 /* gnc_date_string_to_dateformat
386 gboolean
387 gnc_date_string_to_dateformat(const char* fmt_str, QofDateFormat *format)// C: 3 in 3 Local: 0:0:0
388 */
389 static void
390 test_gnc_date_string_to_dateformat (void)
391 {
392  QofDateFormat fmt = 123;
393  g_assert (gnc_date_string_to_dateformat (NULL, &fmt));
394  g_assert_cmpint (fmt, ==, 123);
395  g_assert (!gnc_date_string_to_dateformat ("us", &fmt));
396  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_US);
397  g_assert (!gnc_date_string_to_dateformat ("uk", &fmt));
398  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_UK);
399  g_assert (!gnc_date_string_to_dateformat ("ce", &fmt));
400  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_CE);
401  g_assert (!gnc_date_string_to_dateformat ("iso", &fmt));
402  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_ISO);
403  g_assert (!gnc_date_string_to_dateformat ("utc", &fmt));
404  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_UTC);
405  g_assert (!gnc_date_string_to_dateformat ("locale", &fmt));
406  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_LOCALE);
407  g_assert (!gnc_date_string_to_dateformat ("custom", &fmt));
408  g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_CUSTOM);
409  fmt = 123;
410  g_assert (gnc_date_string_to_dateformat ("", &fmt));
411  g_assert_cmpint (fmt, ==, 123);
412  g_assert (gnc_date_string_to_dateformat ("foo", &fmt));
413  g_assert_cmpint (fmt, ==, 123);
414 
415 }
416 /* gnc_date_monthformat_to_string
417 const char*
418 gnc_date_monthformat_to_string(GNCDateMonthFormat format)// C: 1 Local: 0:0:0
419 */
420 static void
421 test_gnc_date_monthformat_to_string (void)
422 {
423  g_assert_cmpstr (gnc_date_monthformat_to_string (GNCDATE_MONTH_NUMBER), ==, "number");
424  g_assert_cmpstr (gnc_date_monthformat_to_string (GNCDATE_MONTH_ABBREV), ==, "abbrev");
425  g_assert_cmpstr (gnc_date_monthformat_to_string (GNCDATE_MONTH_NAME), ==, "name");
426  g_assert (gnc_date_monthformat_to_string (93) == NULL);
427 }
428 /* gnc_date_string_to_monthformat
429 gboolean
430 gnc_date_string_to_monthformat(const char *fmt_str, GNCDateMonthFormat *format)// C: 1 Local: 0:0:0
431 */
432 static void
433 test_gnc_date_string_to_monthformat (void)
434 {
435  GNCDateMonthFormat fmt = 123;
436  g_assert (gnc_date_string_to_monthformat (NULL, &fmt));
437  g_assert_cmpint (fmt, ==, 123);
438  g_assert (!gnc_date_string_to_monthformat ("number", &fmt));
439  g_assert_cmpint (fmt, ==, GNCDATE_MONTH_NUMBER);
440  g_assert (!gnc_date_string_to_monthformat ("abbrev", &fmt));
441  g_assert_cmpint (fmt, ==, GNCDATE_MONTH_ABBREV);
442  g_assert (!gnc_date_string_to_monthformat ("name", &fmt));
443  g_assert_cmpint (fmt, ==, GNCDATE_MONTH_NAME);
444  fmt = 123;
445  g_assert (gnc_date_string_to_monthformat ("", &fmt));
446  g_assert_cmpint (fmt, ==, 123);
447  g_assert (gnc_date_string_to_monthformat ("foo", &fmt));
448  g_assert_cmpint (fmt, ==, 123);
449 }
450 
451 static void
452 test_gnc_setlocale (int category, gchar *locale)
453 {
454  gchar *suffixes[] = {"utf8", "UTF-8"};
455  guint i;
456  /* Msys defines a different set of locales */
457 #ifdef G_OS_WIN32
458  if (g_strcmp0 (locale, "en_US") == 0
459  && setlocale (category, "English_US"))
460  return;
461  if (g_strcmp0 (locale, "en_GB") == 0
462  && setlocale (category, "English_UK"))
463  return;
464  if (g_strcmp0 (locale, "fr_FR") == 0
465  && setlocale (category, "French_France"))
466  return;
467 
468 #endif
469  if (setlocale (category, locale) != NULL)
470  return;
471 
472  for (i = 0; i < G_N_ELEMENTS (suffixes); i++)
473  {
474  gchar * modlocale = g_strdup_printf ("%s.%s", locale, suffixes[i]);
475  gchar *localeval = setlocale (category, modlocale);
476  g_free (modlocale);
477  if (localeval != NULL)
478  return;
479  }
480  g_fprintf (stderr, "There are some differences between distros in the way they name"
481  "locales, and this can cause trouble with the locale-based"
482  "formatting. If you get the assert in this function, run locale -a"
483  "and make sure that en_US, en_GB, and fr_FR are installed and that"
484  "if a suffix is needed it's in the suffixes array.");
485  g_assert_not_reached ();
486 }
487 /* timespec_normalize
488 static void
489 timespec_normalize(Timespec *t)// Local: 2:0:0
490 */
491 static void
492 test_timespec_normalize (void)
493 {
494  const int offset = 4396432;
495  const int factor = 2;
496  int base = 50;
497  Timespec t = { base, factor * NANOS_PER_SECOND + offset };
498  Testfuncs *tf = gnc_date_load_funcs ();
499 
500  tf->timespec_normalize (&t);
501  g_assert_cmpint (t.tv_sec, ==, base + factor);
502  g_assert_cmpint (t.tv_nsec, ==, offset);
503 
504  t.tv_sec = base;
505  t.tv_nsec = - factor * NANOS_PER_SECOND - offset;
506  tf->timespec_normalize (&t);
507  g_assert_cmpint (t.tv_sec, ==, base - factor - 1);
508  g_assert_cmpint (t.tv_nsec, ==, NANOS_PER_SECOND - offset);
509 
510  t.tv_sec = - base;
511  t.tv_nsec = factor * NANOS_PER_SECOND + offset;
512  tf->timespec_normalize (&t);
513  g_assert_cmpint (t.tv_sec, ==, - base + factor + 1);
514  g_assert_cmpint (t.tv_nsec, ==, - NANOS_PER_SECOND + offset);
515 
516  t.tv_sec = - base;
517  t.tv_nsec = - factor * NANOS_PER_SECOND - offset;
518  tf->timespec_normalize (&t);
519  g_assert_cmpint (t.tv_sec, ==, - base - factor);
520  g_assert_cmpint (t.tv_nsec, ==, - offset);
521 
522  g_slice_free (Testfuncs, tf);
523 }
524 
525 
526 /* timespec_equal
527 gboolean
528 timespec_equal (const Timespec *ta, const Timespec *tb)// C: 19 in 8 Local: 0:0:0
529 */
530 static void
531 test_timespec_equal (void)
532 {
533  const int sec_per_day = 24 * 3600;
534  const int sec_per_mo = 30 * sec_per_day;
535  const time64 sec_per_yr = 365 * sec_per_day;
536  const int nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
537  const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
538  const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
539  const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day;
540  Timespec ta = { secs1, nsec1 };
541  Timespec tb = { secs2, nsec2 };
542  Timespec tc = { secs1, nsec1 };
543  Timespec td = { secs3, nsec1 };
544  Timespec te = { secs1, nsec2 };
545  Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
546 
547  g_assert (timespec_equal (&ta, &ta));
548  g_assert (timespec_equal (&ta, &tc));
549  g_assert (!timespec_equal (&ta, &tb));
550  g_assert (!timespec_equal (&ta, &td));
551  g_assert (!timespec_equal (&ta, &te));
552  g_assert (timespec_equal (&tb, &tf));
553 }
554 /* timespec_cmp
555 gint
556 timespec_cmp(const Timespec *ta, const Timespec *tb)// C: 28 in 11 Local: 0:0:0
557 */
558 static void
559 test_timespec_cmp (void)
560 {
561  const int sec_per_day = 24 * 3600;
562  const int sec_per_mo = 30 * sec_per_day;
563  const time64 sec_per_yr = 365 * sec_per_day;
564  const int nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
565  const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
566  const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
567  const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day;
568  Timespec ta = { secs1, nsec1 };
569  Timespec tb = { secs2, nsec2 };
570  Timespec tc = { secs1, nsec1 };
571  Timespec td = { secs3, nsec1 };
572  Timespec te = { secs1, nsec2 };
573  Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
574  Timespec tg = { -secs2, nsec2 };
575  Timespec th = { secs1, -nsec1 };
576 
577  g_assert_cmpint (timespec_cmp (&ta, &ta), ==, 0);
578  g_assert_cmpint (timespec_cmp (&ta, &tc), ==, 0);
579  g_assert_cmpint (timespec_cmp (&tf, &tb), ==, 0);
580  g_assert_cmpint (timespec_cmp (&ta, &tb), ==, 1);
581  g_assert_cmpint (timespec_cmp (&te, &ta), ==, 1);
582  g_assert_cmpint (timespec_cmp (&td, &ta), ==, 1);
583  g_assert_cmpint (timespec_cmp (&ta, &te), ==, -1);
584  g_assert_cmpint (timespec_cmp (&ta, &tg), ==, 1);
585  g_assert_cmpint (timespec_cmp (&th, &ta), ==, -1);
586 
587 }
588 /* timespec_diff
589 Timespec
590 timespec_diff(const Timespec *ta, const Timespec *tb)// C: 4 in 1 Local: 0:0:0
591 */
592 static void
593 test_timespec_diff (void)
594 {
595  const gint sec_per_day = 24 * 3600;
596  const gint sec_per_mo = 30 * sec_per_day;
597  const time64 sec_per_yr = 365 * sec_per_day;
598  const time64 nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
599  const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
600  const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
601  const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day;
602  Timespec ta = { secs1, nsec1 };
603  Timespec tb = { secs2, nsec2 };
604  Timespec td = { secs3, nsec1 };
605  Timespec te = { secs1, nsec2 };
606  Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
607  Timespec tg = { -secs2, nsec2 };
608  Timespec th = { secs1, -nsec3 };
609 
610  Timespec tt = timespec_diff (&ta, &ta);
611 
612  g_assert_cmpint (tt.tv_sec, ==, 0);
613  g_assert_cmpint (tt.tv_nsec, ==, 0);
614 
615  tt = timespec_diff (&ta, &tb);
616  g_assert_cmpint (tt.tv_sec, ==, secs1 - secs2 - 1);
617  g_assert_cmpint (tt.tv_nsec, ==, nsec1 - nsec2 + NANOS_PER_SECOND);
618 
619  tt = timespec_diff (&ta, &te);
620  g_assert_cmpint (tt.tv_sec, ==, 0);
621  g_assert_cmpint (tt.tv_nsec, ==, nsec1 - nsec2);
622 
623  tt = timespec_diff (&tb, &tf);
624  g_assert_cmpint (tt.tv_sec, ==, 0);
625  g_assert_cmpint (tt.tv_nsec, ==, 0);
626 
627  tt = timespec_diff (&tf, &th);
628  if (sizeof (glong) > 4)
629  {
630  glong nsec_diff_norm = 2 * nsec3 - 2 * NANOS_PER_SECOND - NANOS_PER_SECOND;
631  g_assert_cmpint (tt.tv_sec, ==, secs2 - secs1 + 2);
632  g_assert_cmpint (tt.tv_nsec, ==, nsec_diff_norm);
633  }
634  else
635  {
636  g_assert_cmpint (tt.tv_sec, ==, secs2 - secs1 - 3);
637  g_assert_cmpint (tt.tv_nsec, <, 0); /* Overflow nanosecs */
638  }
639  tt = timespec_diff (&tg, &td);
640  g_assert_cmpint (tt.tv_sec, ==, -secs2 - secs3 + 1);
641  g_assert_cmpint (tt.tv_nsec, ==, nsec2 - nsec1 - NANOS_PER_SECOND);
642 
643 }
644 /* timespec_abs
645 Timespec
646 timespec_abs(const Timespec *t)// C: 4 in 1 Local: 0:0:0
647 */
648 static void
649 test_timespec_abs (void)
650 {
651  const int sec_per_day = 24 * 3600;
652  const int sec_per_mo = 30 * sec_per_day;
653  const int sec_per_yr = 365 * sec_per_day;
654  const int nsec1 = 439652, nsec2 = 132794892, nsec3 = 1132794892;
655  const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day;
656  const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day;
657  Timespec ta = { secs1, nsec1 };
658  Timespec tf = { secs2 - 1, nsec3 }; /* When normalized, equal to tb */
659  Timespec tg = { -secs2, nsec2 };
660  Timespec th = { secs1, -nsec1 };
661 
662  Timespec tt = timespec_abs (&ta);
663  g_assert_cmpint (tt.tv_sec, ==, secs1);
664  g_assert_cmpint (tt.tv_nsec, ==, nsec1);
665 
666  tt = timespec_abs (&tf);
667  g_assert_cmpint (tt.tv_sec, ==, secs2);
668  g_assert_cmpint (tt.tv_nsec, ==, nsec2);
669 
670  tt = timespec_abs (&tg);
671  g_assert_cmpint (tt.tv_sec, ==, secs2 - 1);
672  g_assert_cmpint (tt.tv_nsec, ==, NANOS_PER_SECOND - nsec2);
673 
674  tt = timespec_abs (&th);
675  g_assert_cmpint (tt.tv_sec, ==, secs1 - 1);
676  g_assert_cmpint (tt.tv_nsec, ==, NANOS_PER_SECOND - nsec1);
677 
678 }
679 /* timespecCanonicalDayTime
680 Timespec
681 timespecCanonicalDayTime(Timespec t)// C: 12 in 5 SCM: 19 in 10 Local: 0:0:0
682 */
683 static Timespec
684 compute_noon_of_day (Timespec *ts)
685 {
686  GDateTime *g = gncdt.new_from_unix_local (ts->tv_sec);
687  gint yr = g_date_time_get_year (g);
688  gint mo = g_date_time_get_month (g);
689  gint da = g_date_time_get_day_of_month (g);
690  Timespec nt = {0, 0 };
691 
692  g_date_time_unref (g);
693  g = gncdt.new_local (yr, mo, da, 12, 0, 0.0);
694  nt.tv_sec = g_date_time_to_unix (g);
695  g_date_time_unref (g);
696  return nt;
697 }
698 
699 static void
700 test_timespecCanonicalDayTime (void)
701 {
702  const int sec_per_day = 24 * 3600;
703  const int sec_per_mo = 30 * sec_per_day;
704  const time64 sec_per_yr = 365 * sec_per_day;
705  const time64 secs = 8 * 3600 + 43 * 60 + 11;
706  const time64 secs1 = 23 * sec_per_yr + 5 * sec_per_mo + 11 * sec_per_day + 8 * 3600 + 43 * 60 + 11;
707  const time64 secs2 = 21 * sec_per_yr + 11 * sec_per_mo + 19 * sec_per_day + 21 * 3600 + 9 * 60 + 48;
708  const time64 secs3 = 72 * sec_per_yr + 2 * sec_per_mo + 26 * sec_per_day + 12 * 60;
709  Timespec t0 = { secs, 0 };
710  Timespec ta = { secs1, 0 };
711  Timespec tb = { secs2, 0 };
712  Timespec tc = { secs3, 0 };
713 
714  Timespec n0 = compute_noon_of_day (&t0);
715  Timespec na = compute_noon_of_day (&ta);
716  Timespec nb = compute_noon_of_day (&tb);
717  Timespec nc = compute_noon_of_day (&tc);
718 
723 
724  g_assert_cmpint (n0.tv_sec, ==, r0.tv_sec);
725  g_assert_cmpint (na.tv_sec, ==, ra.tv_sec);
726  g_assert_cmpint (nb.tv_sec, ==, rb.tv_sec);
727  g_assert_cmpint (nc.tv_sec, ==, rc.tv_sec);
728 }
729 
730 /* gnc_date_get_last_mday
731 int gnc_date_get_last_mday (int month, int year)// C: 1 Local: 1:0:0
732 */
733 static void
734 test_gnc_date_get_last_mday (void)
735 {
736  g_assert_cmpint (gnc_date_get_last_mday (1, 1975), ==, 31);
737  g_assert_cmpint (gnc_date_get_last_mday (1, 1980), ==, 31);
738  g_assert_cmpint (gnc_date_get_last_mday (2, 1975), ==, 28);
739  g_assert_cmpint (gnc_date_get_last_mday (2, 1980), ==, 29);
740  g_assert_cmpint (gnc_date_get_last_mday (3, 1975), ==, 31);
741  g_assert_cmpint (gnc_date_get_last_mday (3, 1980), ==, 31);
742  g_assert_cmpint (gnc_date_get_last_mday (4, 1975), ==, 30);
743  g_assert_cmpint (gnc_date_get_last_mday (4, 1980), ==, 30);
744  g_assert_cmpint (gnc_date_get_last_mday (5, 1975), ==, 31);
745  g_assert_cmpint (gnc_date_get_last_mday (5, 1980), ==, 31);
746  g_assert_cmpint (gnc_date_get_last_mday (6, 1975), ==, 30);
747  g_assert_cmpint (gnc_date_get_last_mday (6, 1980), ==, 30);
748  g_assert_cmpint (gnc_date_get_last_mday (7, 1975), ==, 31);
749  g_assert_cmpint (gnc_date_get_last_mday (7, 1980), ==, 31);
750  g_assert_cmpint (gnc_date_get_last_mday (8, 1975), ==, 31);
751  g_assert_cmpint (gnc_date_get_last_mday (8, 1980), ==, 31);
752  g_assert_cmpint (gnc_date_get_last_mday (9, 1975), ==, 30);
753  g_assert_cmpint (gnc_date_get_last_mday (9, 1980), ==, 30);
754  g_assert_cmpint (gnc_date_get_last_mday (10, 1975), ==, 31);
755  g_assert_cmpint (gnc_date_get_last_mday (10, 1980), ==, 31);
756  g_assert_cmpint (gnc_date_get_last_mday (11, 1975), ==, 30);
757  g_assert_cmpint (gnc_date_get_last_mday (11, 1980), ==, 30);
758  g_assert_cmpint (gnc_date_get_last_mday (12, 1975), ==, 31);
759  g_assert_cmpint (gnc_date_get_last_mday (12, 1980), ==, 31);
760  g_assert_cmpint (gnc_date_get_last_mday (2, 2000), ==, 29);
761  g_assert_cmpint (gnc_date_get_last_mday (2, 2400), ==, 28);
762 }
763 /* Getter, no testing needed.
764 QofDateFormat qof_date_format_get (void)// C: 5 in 3 Local: 0:0:0
765 */
766 /* qof_date_format_set
767 set date format to one of US, UK, CE, ISO OR UTC
768 checks to make sure it's a legal value
769 param QofDateFormat: enumeration indicating preferred format
770 return void
771 Globals: dateFormat
772 void qof_date_format_set(QofDateFormat df)// C: 3 in 2 Local: 0:0:0
773 */
774 static void
775 test_qof_date_format_set (void)
776 {
777  gchar *msg = "[qof_date_format_set()] non-existent date format set attempted. Setting ISO default";
778  gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
779  gchar *logdomain = "qof.engine";
780  TestErrorStruct check = {loglevel, logdomain, msg, 0};
781  GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
782  g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
783  qof_date_format_set ((QofDateFormat)((guint)DATE_FORMAT_LAST + 97));
784  g_assert_cmpint (qof_date_format_get (), ==, QOF_DATE_FORMAT_ISO);
785  g_assert_cmpint (check.hits, ==,1);
786 
788  g_assert_cmpint (qof_date_format_get (), ==, QOF_DATE_FORMAT_UK);
789  g_assert_cmpint (check.hits, ==,1);
790  g_log_set_default_handler (hdlr, NULL);
791 }
792 /* qof_date_completion_set
793 set dateCompletion to one of QOF_DATE_COMPLETION_THISYEAR (for
794 completing the year to the current calendar year) or
795 QOF_DATE_COMPLETION_SLIDING (for using a sliding 12-month window). The
796 sliding window starts 'backmonth' months before the current month (0-11).
797 checks to make sure it's a legal value
798 param QofDateCompletion: indicates preferred completion method
799 param int: the number of months to go back in time (0-11)
800 return void
801 Globals: dateCompletion dateCompletionBackMonths
802 void qof_date_completion_set(QofDateCompletion dc, int backmonths)// C: 1 Local: 0:0:0
803 */
804 /* static void
805 test_qof_date_completion_set (void)
806 {
807 }*/
808 /* qof_print_date_dmy_buff
809 size_t
810 qof_print_date_dmy_buff (char * buff, size_t len, int day, int month, int year)// C: 12 in 3 Local: 2:0:0
811 */
812 
813 #ifdef HAVE_LANGINFO_D_FMT
814 #include <langinfo.h>
815 # define GNC_D_FMT (nl_langinfo (D_FMT))
816 # define GNC_D_T_FMT (nl_langinfo (D_T_FMT))
817 # define GNC_T_FMT (nl_langinfo (T_FMT))
818 #elif defined(G_OS_WIN32)
819 # define GNC_D_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATE))
820 # define GNC_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_TIME))
821 # define GNC_D_T_FMT (qof_win32_get_time_format(QOF_WIN32_PICTURE_DATETIME))
822 #else
823 # define GNC_D_FMT "%Y-%m-%d"
824 # define GNC_D_T_FMT "%Y-%m-%d %r"
825 # define GNC_T_FMT "%r"
826 #endif
827 
828 static void tm_set_dmy (struct tm *tm, gint year, gint month, gint mday)
829 {
830  tm->tm_year = year - 1900;
831  tm->tm_mon = month - 1;
832  tm->tm_mday = mday;
833 }
834 
835 static void
836 test_qof_print_date_dmy_buff (void)
837 {
838  gchar buff[MAX_DATE_LENGTH], t_buff[MAX_DATE_LENGTH];
839  gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
840  struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0
841 #ifdef HAVE_STRUCT_TM_GMTOFF
842  , 0, 0
843 #endif
844  };
845 
847  memset ((gpointer)buff, 0, sizeof (buff));
848  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 23, 11, 1974), ==, strlen (buff));
849  g_assert_cmpstr (buff, ==, "23/11/1974");
850  memset ((gpointer)buff, 0, sizeof (buff));
851  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 2, 2, 1961), ==, strlen (buff));
852  g_assert_cmpstr (buff, ==, "02/02/1961");
853  memset ((gpointer)buff, 0, sizeof (buff));
854  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 16, 6, 2045), ==, strlen (buff));
855  g_assert_cmpstr (buff, ==, "16/06/2045");
856 
858  memset ((gpointer)buff, 0, sizeof (buff));
859  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 23, 11, 1974), ==, strlen (buff));
860  g_assert_cmpstr (buff, ==, "23.11.1974");
861  memset ((gpointer)buff, 0, sizeof (buff));
862  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 2, 2, 1961), ==, strlen (buff));
863  g_assert_cmpstr (buff, ==, "02.02.1961");
864  memset ((gpointer)buff, 0, sizeof (buff));
865  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 16, 6, 2045), ==, strlen (buff));
866  g_assert_cmpstr (buff, ==, "16.06.2045");
867 
869  memset ((gpointer)buff, 0, sizeof (buff));
870  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 23, 11, 1974), ==, strlen (buff));
871  g_assert_cmpstr (buff, ==, "11/23/1974");
872  memset ((gpointer)buff, 0, sizeof (buff));
873  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 2, 2, 1961), ==, strlen (buff));
874  g_assert_cmpstr (buff, ==, "02/02/1961");
875  memset ((gpointer)buff, 0, sizeof (buff));
876  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 16, 6, 2045), ==, strlen (buff));
877  g_assert_cmpstr (buff, ==, "06/16/2045");
878 
880  memset ((gpointer)buff, 0, sizeof (buff));
881  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 23, 11, 1974), ==, strlen (buff));
882  g_assert_cmpstr (buff, ==, "1974-11-23");
883  memset ((gpointer)buff, 0, sizeof (buff));
884  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 2, 2, 1961),
885  ==, strlen (buff));
886  g_assert_cmpstr (buff, ==, "1961-02-02");
887  memset ((gpointer)buff, 0, sizeof (buff));
888  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), 16, 6, 2045),
889  ==, strlen (buff));
890  g_assert_cmpstr (buff, ==, "2045-06-16");
891 
893  test_gnc_setlocale (LC_TIME, "en_US");
894  tm_set_dmy (&tm, 1974, 11, 23);
895  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
896  memset ((gpointer)buff, 0, sizeof (buff));
897  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
898  tm.tm_mon + 1, tm.tm_year + 1900),
899  ==, strlen (buff));
900  g_assert_cmpstr (buff, ==, t_buff);
901 
902 
903  tm_set_dmy (&tm, 1961, 2, 2);
904  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
905  memset ((gpointer)buff, 0, sizeof (buff));
906  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
907  tm.tm_mon + 1, tm.tm_year + 1900),
908  ==, strlen (buff));
909  g_assert_cmpstr (buff, ==, t_buff);
910  memset ((gpointer)buff, 0, sizeof (buff));
911  tm_set_dmy (&tm, 2045, 6, 16);
912  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
913  memset ((gpointer)buff, 0, sizeof (buff));
914  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
915  tm.tm_mon + 1, tm.tm_year + 1900),
916  ==, strlen (buff));
917  g_assert_cmpstr (buff, ==, t_buff);
918 
919  test_gnc_setlocale (LC_TIME, "en_GB");
920  tm_set_dmy (&tm, 1974, 11, 23);
921  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
922  memset ((gpointer)buff, 0, sizeof (buff));
923  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
924  tm.tm_mon + 1, tm.tm_year + 1900),
925  ==, strlen (buff));
926  g_assert_cmpstr (buff, ==, t_buff);
927  tm_set_dmy (&tm, 1961, 2, 2);
928  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
929  memset ((gpointer)buff, 0, sizeof (buff));
930  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
931  tm.tm_mon + 1, tm.tm_year + 1900),
932  ==, strlen (buff));
933  g_assert_cmpstr (buff, ==, t_buff);
934  memset ((gpointer)buff, 0, sizeof (buff));
935  tm_set_dmy (&tm, 2045, 6, 16);
936  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
937  memset ((gpointer)buff, 0, sizeof (buff));
938  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
939  tm.tm_mon + 1, tm.tm_year + 1900),
940  ==, strlen (buff));
941  g_assert_cmpstr (buff, ==, t_buff);
942 
943  test_gnc_setlocale (LC_TIME, "fr_FR");
944  tm_set_dmy (&tm, 1974, 11, 23);
945  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
946  memset ((gpointer)buff, 0, sizeof (buff));
947  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
948  tm.tm_mon + 1, tm.tm_year + 1900),
949  ==, strlen (buff));
950  g_assert_cmpstr (buff, ==, t_buff);
951  tm_set_dmy (&tm, 1961, 2, 2);
952  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
953  memset ((gpointer)buff, 0, sizeof (buff));
954  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
955  tm.tm_mon + 1, tm.tm_year + 1900),
956  ==, strlen (buff));
957  g_assert_cmpstr (buff, ==, t_buff);
958  memset ((gpointer)buff, 0, sizeof (buff));
959  tm_set_dmy (&tm, 2045, 6, 16);
960  strftime(t_buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
961  memset ((gpointer)buff, 0, sizeof (buff));
962  g_assert_cmpint (qof_print_date_dmy_buff (buff, sizeof (buff), tm.tm_mday,
963  tm.tm_mon + 1, tm.tm_year + 1900),
964  ==, strlen (buff));
965  g_assert_cmpstr (buff, ==, t_buff);
966 
967  setlocale (LC_TIME, locale);
968  g_free (locale);
969 }
970 
971 /* Different distros/OSes define localization date formats. Apple, for
972  * example, uses %d.%m.%Y for fr_FR and %d/%m/%Y for en_GB, while
973  * Debian uses %d/%m/%Y and %d/%m/%y respectively. So to get a test
974  * that works on all of them, we need to check the localized
975  * strftime().
976  *
977  * This is a macro so that the line number in the assert message will
978  * be right.
979  */
980 
981 #define test_assert_localized_timestring(time, datestr) \
982  { \
983  gchar t_buff[MAX_DATE_LENGTH]; \
984  struct tm *ltime = gnc_localtime ((time64 *)(&time)); \
985  strftime (t_buff, sizeof (t_buff), GNC_D_FMT, ltime); \
986  gnc_tm_free (ltime); \
987  g_assert_cmpstr (datestr, ==, t_buff); \
988  }
989 
990 
991 /* qof_print_date_buff
992 size_t
993 qof_print_date_buff (char * buff, size_t len, time64 t)// C: 3 in 1 Local: 2:0:0
994 */
995 static void
996 test_qof_print_date_buff (void)
997 {
998  gchar buff[MAX_DATE_LENGTH];
999  gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
1000  GDateTime *gd1 = gncdt.new_local (1974, 11, 23, 12, 0, 0.0);
1001  GDateTime *gd2 = gncdt.new_local (1961, 2, 2, 12, 0, 0.0);
1002  GDateTime *gd3 = gncdt.new_local (2045, 6, 16, 12, 0, 0.0);
1003 
1004  time64 tm1 = g_date_time_to_unix (gd1);
1005  time64 tm2 = g_date_time_to_unix (gd2);
1006  time64 tm3 = g_date_time_to_unix (gd3);
1007 
1009  memset ((gpointer)buff, 0, sizeof (buff));
1010  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1011  ==, strlen (buff));
1012  g_assert_cmpstr (buff, ==, "23/11/1974");
1013  memset ((gpointer)buff, 0, sizeof (buff));
1014  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1015  ==, strlen (buff));
1016  g_assert_cmpstr (buff, ==, "02/02/1961");
1017 
1018  memset ((gpointer)buff, 0, sizeof (buff));
1019  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1020  ==, strlen (buff));
1021  g_assert_cmpstr (buff, ==, "16/06/2045");
1022 
1024  memset ((gpointer)buff, 0, sizeof (buff));
1025  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1026  ==, strlen (buff));
1027  g_assert_cmpstr (buff, ==, "23.11.1974");
1028  memset ((gpointer)buff, 0, sizeof (buff));
1029  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1030  ==, strlen (buff));
1031  g_assert_cmpstr (buff, ==, "02.02.1961");
1032 
1033  memset ((gpointer)buff, 0, sizeof (buff));
1034  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1035  ==, strlen (buff));
1036  g_assert_cmpstr (buff, ==, "16.06.2045");
1037 
1039  memset ((gpointer)buff, 0, sizeof (buff));
1040  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1041  ==, strlen (buff));
1042  g_assert_cmpstr (buff, ==, "11/23/1974");
1043  memset ((gpointer)buff, 0, sizeof (buff));
1044  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1045  ==, strlen (buff));
1046  g_assert_cmpstr (buff, ==, "02/02/1961");
1047 
1048  memset ((gpointer)buff, 0, sizeof (buff));
1049  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1050  ==, strlen (buff));
1051  g_assert_cmpstr (buff, ==, "06/16/2045");
1052 
1054  memset ((gpointer)buff, 0, sizeof (buff));
1055  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1056  ==, strlen (buff));
1057  g_assert_cmpstr (buff, ==, "1974-11-23");
1058  memset ((gpointer)buff, 0, sizeof (buff));
1059  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1060  ==, strlen (buff));
1061  g_assert_cmpstr (buff, ==, "1961-02-02");
1062 
1063  memset ((gpointer)buff, 0, sizeof (buff));
1064  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1065  ==, strlen (buff));
1066  g_assert_cmpstr (buff, ==, "2045-06-16");
1067 
1069  test_gnc_setlocale (LC_TIME, "en_US");
1070  memset ((gpointer)buff, 0, sizeof (buff));
1071  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1072  ==, strlen (buff));
1073  g_assert_cmpstr (buff, ==, g_date_time_format (gd1, GNC_D_FMT));
1074  memset ((gpointer)buff, 0, sizeof (buff));
1075  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1076  ==, strlen (buff));
1077  g_assert_cmpstr (buff, ==, g_date_time_format (gd2, GNC_D_FMT));
1078 
1079  memset ((gpointer)buff, 0, sizeof (buff));
1080  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1081  ==, strlen (buff));
1082  g_assert_cmpstr (buff, ==, g_date_time_format (gd3, GNC_D_FMT));
1083 
1084  test_gnc_setlocale (LC_TIME, "en_GB");
1085  memset ((gpointer)buff, 0, sizeof (buff));
1086  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1087  ==, strlen (buff));
1088  g_assert_cmpstr (buff, ==, g_date_time_format (gd1, GNC_D_FMT));
1089  memset ((gpointer)buff, 0, sizeof (buff));
1090  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1091  ==, strlen (buff));
1092  g_assert_cmpstr (buff, ==, g_date_time_format (gd2, GNC_D_FMT));
1093  memset ((gpointer)buff, 0, sizeof (buff));
1094  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1095  ==, strlen (buff));
1096  g_assert_cmpstr (buff, ==, g_date_time_format (gd3, GNC_D_FMT));
1097 
1098  test_gnc_setlocale (LC_TIME, "fr_FR");
1099  memset ((gpointer)buff, 0, sizeof (buff));
1100  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm1),
1101  ==, strlen (buff));
1102  g_assert_cmpstr (buff, ==, g_date_time_format (gd1, GNC_D_FMT));
1103  memset ((gpointer)buff, 0, sizeof (buff));
1104  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm2),
1105  ==, strlen (buff));
1106  g_assert_cmpstr (buff, ==, g_date_time_format (gd2, GNC_D_FMT));
1107  memset ((gpointer)buff, 0, sizeof (buff));
1108  g_assert_cmpint (qof_print_date_buff (buff, sizeof (buff), tm3),
1109  ==, strlen (buff));
1110  g_assert_cmpstr (buff, ==, g_date_time_format (gd3, GNC_D_FMT));
1111 
1112  setlocale (LC_TIME, locale);
1113  g_free (locale);
1114  g_date_time_unref (gd1);
1115  g_date_time_unref (gd2);
1116  g_date_time_unref (gd3);
1117 }
1118 /* qof_print_gdate
1119 size_t
1120 qof_print_gdate( char *buf, size_t len, const GDate *gd )// C: 6 in 5 Local: 0:0:0
1121 */
1122 static void
1123 test_qof_print_gdate (void)
1124 {
1125  gchar buff[MAX_DATE_LENGTH], t_buff[MAX_DATE_LENGTH];
1126  gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
1127  GDate *gd1 = g_date_new_dmy (23, 11, 1974);
1128  GDate *gd2 = g_date_new_dmy (2, 2, 1961);
1129  GDate *gd3 = g_date_new_dmy (16, 6, 2045);
1130 
1132  memset ((gpointer)buff, 0, sizeof (buff));
1133  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1134  ==, strlen (buff));
1135  g_assert_cmpstr (buff, ==, "23/11/1974");
1136  memset ((gpointer)buff, 0, sizeof (buff));
1137  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1138  ==, strlen (buff));
1139  g_assert_cmpstr (buff, ==, "02/02/1961");
1140  memset ((gpointer)buff, 0, sizeof (buff));
1141  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1142  ==, strlen (buff));
1143  g_assert_cmpstr (buff, ==, "16/06/2045");
1144 
1146  memset ((gpointer)buff, 0, sizeof (buff));
1147  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1148  ==, strlen (buff));
1149  g_assert_cmpstr (buff, ==, "23.11.1974");
1150  memset ((gpointer)buff, 0, sizeof (buff));
1151  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1152  ==, strlen (buff));
1153  g_assert_cmpstr (buff, ==, "02.02.1961");
1154  memset ((gpointer)buff, 0, sizeof (buff));
1155  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1156  ==, strlen (buff));
1157  g_assert_cmpstr (buff, ==, "16.06.2045");
1158 
1159 
1161  memset ((gpointer)buff, 0, sizeof (buff));
1162  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1163  ==, strlen (buff));
1164  g_assert_cmpstr (buff, ==, "11/23/1974");
1165  memset ((gpointer)buff, 0, sizeof (buff));
1166  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1167  ==, strlen (buff));
1168  g_assert_cmpstr (buff, ==, "02/02/1961");
1169  memset ((gpointer)buff, 0, sizeof (buff));
1170  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1171  ==, strlen (buff));
1172  g_assert_cmpstr (buff, ==, "06/16/2045");
1173 
1174 
1176  memset ((gpointer)buff, 0, sizeof (buff));
1177  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1178  ==, strlen (buff));
1179  g_assert_cmpstr (buff, ==, "1974-11-23");
1180  memset ((gpointer)buff, 0, sizeof (buff));
1181  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1182  ==, strlen (buff));
1183  g_assert_cmpstr (buff, ==, "1961-02-02");
1184  memset ((gpointer)buff, 0, sizeof (buff));
1185  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1186  ==, strlen (buff));
1187  g_assert_cmpstr (buff, ==, "2045-06-16");
1188 
1189 
1191  test_gnc_setlocale (LC_TIME, "en_US");
1192  memset ((gpointer)buff, 0, sizeof (buff));
1193  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1194  ==, strlen (buff));
1195  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
1196  g_assert_cmpstr (buff, ==, t_buff);
1197  memset ((gpointer)buff, 0, sizeof (buff));
1198  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1199  ==, strlen (buff));
1200  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
1201  g_assert_cmpstr (buff, ==, t_buff);
1202  memset ((gpointer)buff, 0, sizeof (buff));
1203  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1204  ==, strlen (buff));
1205  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
1206  g_assert_cmpstr (buff, ==, t_buff);
1207 
1208  test_gnc_setlocale (LC_TIME, "en_GB");
1209  memset ((gpointer)buff, 0, sizeof (buff));
1210  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1211  ==, strlen (buff));
1212  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
1213  g_assert_cmpstr (buff, ==, t_buff);
1214  memset ((gpointer)buff, 0, sizeof (buff));
1215  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1216  ==, strlen (buff));
1217  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
1218  g_assert_cmpstr (buff, ==, t_buff);
1219  memset ((gpointer)buff, 0, sizeof (buff));
1220  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1221  ==, strlen (buff));
1222  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
1223  g_assert_cmpstr (buff, ==, t_buff);
1224 
1225 
1226  test_gnc_setlocale (LC_TIME, "fr_FR");
1227  memset ((gpointer)buff, 0, sizeof (buff));
1228  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd1),
1229  ==, strlen (buff));
1230  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
1231  g_assert_cmpstr (buff, ==, t_buff);
1232  memset ((gpointer)buff, 0, sizeof (buff));
1233  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd2),
1234  ==, strlen (buff));
1235  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
1236  g_assert_cmpstr (buff, ==, t_buff);
1237  memset ((gpointer)buff, 0, sizeof (buff));
1238  g_assert_cmpint (qof_print_gdate (buff, sizeof (buff), gd3),
1239  ==, strlen (buff));
1240  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
1241  g_assert_cmpstr (buff, ==, t_buff);
1242 
1243  setlocale (LC_TIME, locale);
1244  g_free (locale);
1245  g_date_free (gd1);
1246  g_date_free (gd2);
1247  g_date_free (gd3);
1248 }
1249 
1250 #define test_assert_qof_print_date(time, datestr) \
1251  { \
1252  gchar *buf = qof_print_date (time); \
1253  g_assert_cmpstr (buf, ==, datestr); \
1254  g_free (buf); \
1255  }
1256 
1257 #define test_assert_qof_print_date_outside_range(time, datestr) \
1258  { \
1259  gchar *buf = qof_print_date (time); \
1260  g_assert_cmpstr (buf, ==, datestr); \
1261  g_free (buf); \
1262  }
1263 
1264 #define test_assert_localized_qof_print_date(time) \
1265  { \
1266  gchar *buf = qof_print_date (time); \
1267  test_assert_localized_timestring (time, buf); \
1268  g_free (buf); \
1269  }
1270 
1271 /* qof_print_date
1272 char *
1273 qof_print_date (time64 t)// C: 29 in 13 Local: 0:0:0
1274 */
1275 static void
1276 test_qof_print_date (void)
1277 {
1278  gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
1279  GDateTime *gd1 = gncdt.new_local (1974, 11, 23, 12, 0, 0.0);
1280  GDateTime *gd2 = gncdt.new_local (1961, 2, 2, 12, 0, 0.0);
1281  GDateTime *gd3 = gncdt.new_local (2045, 6, 16, 12, 0, 0.0);
1282 
1283  time64 tm1 = g_date_time_to_unix (gd1);
1284  time64 tm2 = g_date_time_to_unix (gd2);
1285  time64 tm3 = g_date_time_to_unix (gd3);
1286 
1288  test_assert_qof_print_date (tm1, "23/11/1974");
1289  test_assert_qof_print_date_outside_range (tm2, "02/02/1961");
1290  test_assert_qof_print_date_outside_range (tm3, "16/06/2045");
1291 
1293  test_assert_qof_print_date (tm1, "23.11.1974");
1294  test_assert_qof_print_date_outside_range (tm2, "02.02.1961");
1295  test_assert_qof_print_date_outside_range (tm3, "16.06.2045");
1296 
1298  test_assert_qof_print_date (tm1, "11/23/1974");
1299  test_assert_qof_print_date_outside_range (tm2, "02/02/1961");
1300  test_assert_qof_print_date_outside_range (tm3, "06/16/2045");
1301 
1303  test_assert_qof_print_date (tm1, "1974-11-23");
1304  test_assert_qof_print_date_outside_range (tm2, "1961-02-02");
1305  test_assert_qof_print_date_outside_range (tm3, "2045-06-16");
1306 
1308  test_gnc_setlocale (LC_TIME, "en_US");
1309  test_assert_qof_print_date (tm1,
1310  g_date_time_format (gd1, GNC_D_FMT));
1311  test_assert_qof_print_date_outside_range (tm2,
1312  g_date_time_format (gd2, GNC_D_FMT));
1313  test_assert_qof_print_date_outside_range (tm3,
1314  g_date_time_format (gd3, GNC_D_FMT));
1315 
1316  test_gnc_setlocale (LC_TIME, "en_GB");
1317  test_assert_qof_print_date (tm1,
1318  g_date_time_format (gd1, GNC_D_FMT));
1319  test_assert_qof_print_date_outside_range (tm2,
1320  g_date_time_format (gd2, GNC_D_FMT));
1321  test_assert_qof_print_date_outside_range (tm3,
1322  g_date_time_format (gd3, GNC_D_FMT));
1323 
1324  test_gnc_setlocale (LC_TIME, "fr_FR");
1325  test_assert_qof_print_date (tm1,
1326  g_date_time_format (gd1, GNC_D_FMT));
1327  test_assert_qof_print_date_outside_range (tm2,
1328  g_date_time_format (gd2, GNC_D_FMT));
1329  test_assert_qof_print_date_outside_range (tm3,
1330  g_date_time_format (gd3, GNC_D_FMT));
1331 
1332  setlocale (LC_TIME, locale);
1333  g_free (locale);
1334  g_date_time_unref (gd1);
1335  g_date_time_unref (gd2);
1336  g_date_time_unref (gd3);
1337 }
1338 /* gnc_print_date
1339 const char *
1340 gnc_print_date (Timespec ts)// C: 11 in 9 SCM: 166 in 59 Local: 0:0:0
1341 */
1342 static void
1343 test_gnc_print_date (void)
1344 {
1345  gchar t_buff[MAX_DATE_LENGTH];
1346  gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
1347  GDate *gd1 = g_date_new_dmy (23, 11, 1974);
1348  GDate *gd2 = g_date_new_dmy (2, 2, 1961);
1349  GDate *gd3 = g_date_new_dmy (16, 6, 2045);
1350  Timespec tm1 = gdate_to_timespec (*gd1);
1351  Timespec tm2 = gdate_to_timespec (*gd2);
1352  Timespec tm3 = gdate_to_timespec (*gd3);
1353 
1354 
1356  g_assert_cmpstr (gnc_print_date (tm1), ==, "23/11/1974");
1357  g_assert_cmpstr (gnc_print_date (tm2), ==, "02/02/1961");
1358  g_assert_cmpstr (gnc_print_date (tm3), ==, "16/06/2045");
1359 
1361  g_assert_cmpstr (gnc_print_date (tm1), ==, "23.11.1974");
1362  g_assert_cmpstr (gnc_print_date (tm2), ==, "02.02.1961");
1363  g_assert_cmpstr (gnc_print_date (tm3), ==, "16.06.2045");
1364 
1366  g_assert_cmpstr (gnc_print_date (tm1), ==, "11/23/1974");
1367  g_assert_cmpstr (gnc_print_date (tm2), ==, "02/02/1961");
1368  g_assert_cmpstr (gnc_print_date (tm3), ==, "06/16/2045");
1369 
1371  g_assert_cmpstr (gnc_print_date (tm1), ==, "1974-11-23");
1372  g_assert_cmpstr (gnc_print_date (tm2), ==, "1961-02-02");
1373  g_assert_cmpstr (gnc_print_date (tm3), ==, "2045-06-16");
1374 
1376  test_gnc_setlocale (LC_TIME, "en_US");
1377  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
1378  g_assert_cmpstr (gnc_print_date (tm1), ==, t_buff);
1379  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
1380  g_assert_cmpstr (gnc_print_date (tm2), ==, t_buff);
1381  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
1382  g_assert_cmpstr (gnc_print_date (tm3), ==, t_buff);
1383 
1384  test_gnc_setlocale (LC_TIME, "en_GB");
1385  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
1386  g_assert_cmpstr (gnc_print_date (tm1), ==, t_buff);
1387  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
1388  g_assert_cmpstr (gnc_print_date (tm2), ==, t_buff);
1389  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
1390  g_assert_cmpstr (gnc_print_date (tm3), ==, t_buff);
1391 
1392  test_gnc_setlocale (LC_TIME, "fr_FR");
1393  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd1);
1394  g_assert_cmpstr (gnc_print_date (tm1), ==, t_buff);
1395  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd2);
1396  g_assert_cmpstr (gnc_print_date (tm2), ==, t_buff);
1397  g_date_strftime (t_buff, MAX_DATE_LENGTH, GNC_D_FMT, gd3);
1398  g_assert_cmpstr (gnc_print_date (tm3), ==, t_buff);
1399 
1400  setlocale (LC_TIME, locale);
1401  g_free (locale);
1402  g_date_free (gd1);
1403  g_date_free (gd2);
1404  g_date_free (gd3);
1405 }
1406 /* floordiv
1407 static int
1408 floordiv(int a, int b)// Local: 1:0:0
1409 */
1410 /* static void
1411 test_floordiv (void)
1412 {
1413 }*/
1414 /* qof_scan_date_internal
1415 qof_scan_date just does passes this through, passing the pre-set QOF_DATE_FORMAT, so we test there rather than exposing this via Testfuncs.
1416 qof_scan_date_internal (const char *buff, int *day, int *month, int *year,// Local: 3:0:0
1417 */
1418 /* static void
1419 test_qof_scan_date_internal (void)
1420 {
1421 } */
1422 /* qof_scan_date
1423 gboolean
1424 qof_scan_date (const char *buff, int *day, int *month, int *year)// C: 7 in 3 Local: 0:0:0
1425 */
1426 static void
1427 test_qof_scan_date (void)
1428 {
1429  gchar *locale = g_strdup (setlocale (LC_TIME, NULL));
1430  int day = 0, mo = 0, yr = 0;
1431  GDateTime *gdt = gncdt.new_now_local ();
1432  gint year = g_date_time_get_year (gdt);
1433  gint month = g_date_time_get_month (gdt);
1434  struct tm tm = { 0, 0, 0, 0, 0, 0, 0, 0, 0
1435 #ifndef G_OS_WIN32
1436  , 0, 0
1437 #endif
1438  };
1439  gchar buff[MAX_DATE_LENGTH];
1440  g_date_time_unref (gdt);
1441 
1442  g_assert (!qof_scan_date (NULL, &day, &mo, &yr));
1443  g_assert_cmpint (day, ==, 0);
1444  g_assert_cmpint (mo, ==, 0);
1445  g_assert_cmpint (yr, ==, 0);
1446 
1448  g_assert (qof_scan_date ("1974-11-23", &day, &mo, &yr));
1449  g_assert_cmpint (day, ==, 23);
1450  g_assert_cmpint (mo, ==, 11);
1451  g_assert_cmpint (yr, ==, 1974);
1452 
1453  g_assert (qof_scan_date ("1961-2-2", &day, &mo, &yr));
1454  g_assert_cmpint (day, ==, 2);
1455  g_assert_cmpint (mo, ==, 2);
1456  g_assert_cmpint (yr, ==, 1961);
1457 
1458  g_assert (qof_scan_date ("2045-6-16", &day, &mo, &yr));
1459  g_assert_cmpint (day, ==, 16);
1460  g_assert_cmpint (mo, ==, 6);
1461  g_assert_cmpint (yr, ==, 2045);
1462 
1464  g_assert (qof_scan_date ("11/23/1974", &day, &mo, &yr));
1465  g_assert_cmpint (day, ==, 23);
1466  g_assert_cmpint (mo, ==, 11);
1467  g_assert_cmpint (yr, ==, 1974);
1468 
1469  g_assert (qof_scan_date ("2/2/1961", &day, &mo, &yr));
1470  g_assert_cmpint (day, ==, 2);
1471  g_assert_cmpint (mo, ==, 2);
1472  g_assert_cmpint (yr, ==, 1961);
1473 
1474  g_assert (qof_scan_date ("6/16/2045", &day, &mo, &yr));
1475  g_assert_cmpint (day, ==, 16);
1476  g_assert_cmpint (mo, ==, 6);
1477  g_assert_cmpint (yr, ==, 2045);
1478 
1479  g_assert (qof_scan_date ("11ì›”23ë…„1974", &day, &mo, &yr));
1480  g_assert_cmpint (day, ==, 23);
1481  g_assert_cmpint (mo, ==, 11);
1482  g_assert_cmpint (yr, ==, 1974);
1483 
1484  g_assert (qof_scan_date ("11月23å¹´1974", &day, &mo, &yr));
1485  g_assert_cmpint (day, ==, 23);
1486  g_assert_cmpint (mo, ==, 11);
1487  g_assert_cmpint (yr, ==, 1974);
1488 
1490 
1491  g_assert (qof_scan_date ("11-23", &day, &mo, &yr));
1492  g_assert_cmpint (day, ==, 23);
1493  g_assert_cmpint (mo, ==, 11);
1494  g_assert_cmpint (yr, ==, year);
1495 
1496  g_assert (qof_scan_date ("23-11", &day, &mo, &yr));
1497  g_assert_cmpint (day, ==, 23);
1498  g_assert_cmpint (mo, ==, 11);
1499  g_assert_cmpint (yr, ==, year);
1500 
1501  if (month < 10) /* Sliding window won't test well after October */
1502  {
1504 
1505  g_assert (qof_scan_date ("12-23", &day, &mo, &yr));
1506  g_assert_cmpint (day, ==, 23);
1507  g_assert_cmpint (mo, ==, 12);
1508  g_assert_cmpint (yr, ==, year - 1);
1509 
1511  }
1512 
1514  g_assert (qof_scan_date ("23/11/1974", &day, &mo, &yr));
1515  g_assert_cmpint (day, ==, 23);
1516  g_assert_cmpint (mo, ==, 11);
1517  g_assert_cmpint (yr, ==, 1974);
1518 
1519  g_assert (qof_scan_date ("2/2/1961", &day, &mo, &yr));
1520  g_assert_cmpint (day, ==, 2);
1521  g_assert_cmpint (mo, ==, 2);
1522  g_assert_cmpint (yr, ==, 1961);
1523 
1524  g_assert (qof_scan_date ("16/6/2045", &day, &mo, &yr));
1525  g_assert_cmpint (day, ==, 16);
1526  g_assert_cmpint (mo, ==, 6);
1527  g_assert_cmpint (yr, ==, 2045);
1528 
1530  test_gnc_setlocale (LC_TIME, "en_GB");
1531  tm_set_dmy (&tm, 1974, 11, 23);
1532  strftime (buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
1533  g_assert (qof_scan_date (buff, &day, &mo, &yr));
1534  g_assert_cmpint (day, ==, tm.tm_mday);
1535  g_assert_cmpint (mo, ==, tm.tm_mon + 1);
1536  g_assert_cmpint (yr, ==, tm.tm_year + 1900);
1537 
1538  tm_set_dmy (&tm, 1961,2, 2);
1539  strftime (buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
1540  g_assert (qof_scan_date (buff, &day, &mo, &yr));
1541  g_assert_cmpint (day, ==, tm.tm_mday);
1542  g_assert_cmpint (mo, ==, tm.tm_mon + 1);
1543  /* Some locale date formats result in a 2-digit year, which strptime
1544  * interprets as being in the current century.
1545  */
1546  g_assert_cmpint (yr % 100, ==, tm.tm_year % 100);
1547 
1548  tm_set_dmy (&tm, 2045, 6, 16);
1549  strftime (buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm);
1550  g_assert (qof_scan_date (buff, &day, &mo, &yr));
1551  g_assert_cmpint (day, ==, tm.tm_mday);
1552  g_assert_cmpint (mo, ==, tm.tm_mon + 1);
1553  g_assert_cmpint (yr, ==, tm.tm_year + 1900);
1554 
1555  setlocale (LC_TIME, locale);
1556  g_free (locale);
1557 }
1558 /* dateSeparator
1559 return date character
1560 char dateSeparator (void)// C: 1 Local: 0:0:0
1561 src/register/register-gnome/datecell-gnome.h
1562 */
1563 /* static void
1564 test_dateSeparator (void)
1565 {
1566 }*/
1567 /* qof_time_format_from_utf8
1568 gchar *
1569 qof_time_format_from_utf8(const gchar *utf8_format)// C: 1 Local: 1:0:0
1570 */
1571 /* static void
1572 test_qof_time_format_from_utf8 (void)
1573 {
1574 }*/
1575 /* qof_formatted_time_to_utf8
1576 gchar *
1577 qof_formatted_time_to_utf8(const gchar *locale_string)// C: 1 Local: 1:0:0
1578 */
1579 /* static void
1580 test_qof_formatted_time_to_utf8 (void)
1581 {
1582 }*/
1583 /* qof_format_time
1584 static gchar *
1585 qof_format_time(const gchar *format, const struct tm *tm)// Local: 1:0:0
1586 */
1587 /* static void
1588 test_qof_format_time (void)
1589 {
1590 }*/
1591 /* qof_strftime
1592 gsize
1593 qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)// C: 16 in 9 Local: 5:0:0
1594 */
1595 /* static void
1596 test_qof_strftime (void)
1597 {
1598 }*/
1599 /* gnc_date_timestamp
1600 gchar *
1601 gnc_date_timestamp (void)// C: 2 in 2 Local: 0:0:0
1602 */
1603 static void
1604 test_gnc_date_timestamp (void)
1605 {
1606  GDateTime *gdt = gncdt.new_now_local ();
1607  gchar *timestr = gnc_date_timestamp ();
1608  struct tm tm;
1609 
1610  g_assert (strptime (timestr, "%Y%m%d%H%M%S", &tm));
1611  g_assert_cmpint (g_date_time_get_year (gdt), ==, tm.tm_year + 1900);
1612  g_assert_cmpint (g_date_time_get_month (gdt), ==, tm.tm_mon + 1);
1613  g_assert_cmpint (g_date_time_get_day_of_month (gdt), ==, tm.tm_mday);
1614  g_assert_cmpint (g_date_time_get_hour (gdt), ==, tm.tm_hour);
1615  g_assert_cmpint (g_date_time_get_minute (gdt), ==, tm.tm_min);
1616  g_assert_cmpint (g_date_time_get_second (gdt), ==, tm.tm_sec);
1617 
1618  g_date_time_unref (gdt);
1619  g_free (timestr);
1620 }
1621 /* gnc_iso8601_to_timespec_gmt
1622 Timespec
1623 gnc_iso8601_to_timespec_gmt(const char *str)// C: 6 in 3 Local: 0:0:0
1624 */
1625 static gint
1626 get_nanoseconds (GDateTime *gdt)
1627 {
1628  return g_date_time_get_microsecond (gdt) * 1000;
1629 }
1630 
1631 static void
1632 test_gnc_iso8601_to_timespec_gmt (void)
1633 {
1634  GTimeZone *zulu = g_time_zone_new ("Z");
1635  GTimeZone *tz05 = g_time_zone_new ("-05");
1636  GTimeZone *tz0840 = g_time_zone_new ("+08:40");
1637  GDateTime *gdt1 = g_date_time_new (zulu, 1989, 3, 27, 13, 43, 27.345678);
1638  GDateTime *gdt2 = g_date_time_new (tz05, 2020, 11, 7, 6, 21, 19.0);
1639  GDateTime *gdt3 = g_date_time_new (tz0840, 2012, 7, 4, 19, 27, 44.0);
1640  GDateTime *gdt4 = g_date_time_new (tz05, 1961, 9, 22, 17, 53, 19.0);
1641  GDateTime *gdt5 = g_date_time_new (tz05, 2061, 1, 25, 23, 21, 19.0);
1642 
1643  Timespec t;
1644 
1645  t = gnc_iso8601_to_timespec_gmt (NULL);
1646  g_assert_cmpint (t.tv_sec, ==, 0);
1647  g_assert_cmpint (t.tv_nsec, ==, 0);
1648 
1649  t = gnc_iso8601_to_timespec_gmt ("");
1650  g_assert_cmpint (t.tv_sec, ==, 0);
1651  g_assert_cmpint (t.tv_nsec, ==, 0);
1652 
1653  t = gnc_iso8601_to_timespec_gmt ("1989-03-27 13:43:27.345678");
1654  g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt1));
1655  /* MinGW has some precision issues in the last microsecond digit */
1656 #ifdef G_OS_WIN32
1657  g_assert_cmpint (t.tv_nsec - 2000, <=, get_nanoseconds (gdt1));
1658  g_assert_cmpint (t.tv_nsec + 2000, >=, get_nanoseconds (gdt1));
1659 #else
1660  g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt1));
1661 #endif
1662  t = gnc_iso8601_to_timespec_gmt ("2020-11-7 06:21:19 -05");
1663  g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt2));
1664  g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt2));
1665 
1666  t = gnc_iso8601_to_timespec_gmt ("2012-07-04 19:27:44.0+08:40");
1667  g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt3));
1668  g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt3));
1669 
1670  t = gnc_iso8601_to_timespec_gmt ("1961-09-22 17:53:19 -05");
1671  g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt4));
1672  g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt4));
1673 
1674  t = gnc_iso8601_to_timespec_gmt ("2061-01-25 23:21:19.0 -05:00");
1675  g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt5));
1676  g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt5));
1677 
1678  g_date_time_unref (gdt1);
1679  g_date_time_unref (gdt2);
1680  g_date_time_unref (gdt3);
1681  g_date_time_unref (gdt4);
1682  g_date_time_unref (gdt5);
1683  g_time_zone_unref (zulu);
1684  g_time_zone_unref (tz05);
1685  g_time_zone_unref (tz0840);
1686 }
1687 /* gnc_timespec_to_iso8601_buff
1688 char *
1689 gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)// C: 18 in 7 Local: 0:0:0
1690 */
1691 #define ISO8601_SIZE MAX_DATE_LENGTH + 4
1692 static Timespec
1693 g_date_time_to_timespec (GDateTime *gdt)
1694 {
1695  Timespec t;
1696  t.tv_sec = g_date_time_to_unix (gdt);
1697  t.tv_nsec = g_date_time_get_microsecond (gdt) * 1000;
1698  return t;
1699 }
1700 
1701 static gchar*
1702 format_timestring (GDateTime *gdt)
1703 {
1704  static const unsigned tzlen = MAX_DATE_LENGTH - 26;
1705  gchar *fmt = "%Y-%m-%d %H:%M";
1706  GDateTime *ngdt = gncdt.to_local (gdt);
1707  gchar *date_base = g_date_time_format (ngdt, fmt);
1708  gchar buf[tzlen], *retval;
1709 #ifdef G_OS_WIN32
1710  gchar *tz = g_date_time_format (ngdt, "%Z");
1711 #else
1712  gchar *tz = g_date_time_format (ngdt, "%z");
1713 #endif
1714  memset (buf, 0, tzlen);
1715  g_snprintf (buf, tzlen, "%s", tz);
1716  retval = g_strdup_printf ("%s:%02d.%06d %s", date_base,
1717  g_date_time_get_second (ngdt),
1718  g_date_time_get_microsecond (ngdt), buf);
1719  g_date_time_unref (ngdt);
1720  g_free (date_base);
1721  g_free (tz);
1722  return retval;
1723 }
1724 
1725 static void
1726 test_gnc_timespec_to_iso8601_buff (void)
1727 {
1728  GTimeZone *zulu = g_time_zone_new ("Z");
1729  GTimeZone *tz05 = g_time_zone_new ("-05");
1730  GTimeZone *tz0840 = g_time_zone_new ("+08:40");
1731  GDateTime *gdt0 = g_date_time_new_from_unix_utc (0);
1732  GDateTime *gdt1 = g_date_time_new (zulu, 1989, 3, 27, 13, 43, 27.345678);
1733  GDateTime *gdt2 = g_date_time_new (tz05, 2020, 11, 7, 6, 21, 19.0);
1734  GDateTime *gdt3 = g_date_time_new (tz0840, 2012, 7, 4, 19, 27, 44.0);
1735  GDateTime *gdt4 = g_date_time_new (tz05, 1961, 9, 22, 17, 53, 19.0);
1736  GDateTime *gdt5 = g_date_time_new (tz05, 2061, 1, 25, 23, 21, 19.0);
1737 
1738  gchar buff[ISO8601_SIZE];
1739  gchar *time_str;
1740  Timespec t = { 0, 0 };
1741  gchar *end;
1742  gchar *logdomain = "qof";
1743  guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
1744 #if defined(__clang__)
1745 #define _func "char *gnc_timespec_to_iso8601_buff(Timespec, char *)"
1746 #else
1747 #define _func "char* gnc_timespec_to_iso8601_buff(Timespec, char*)"
1748 //#define _func "gnc_timespec_to_iso8601_buff"
1749 #endif
1750  gchar *msg = _func ": assertion " _Q "buff != NULL' failed";
1751 #undef _func
1752  TestErrorStruct check = { loglevel, logdomain, msg, 0 };
1753  GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler,
1754  &check);
1755  g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
1756 
1757  memset (buff, 0, sizeof buff);
1758 
1759  end = gnc_timespec_to_iso8601_buff (t, NULL);
1760  g_assert (end == NULL);
1761  g_assert_cmpint (check.hits, ==, 1);
1762 
1763  g_log_set_default_handler (oldlogger, NULL);
1764 
1765  end = gnc_timespec_to_iso8601_buff (t, buff);
1766  g_assert_cmpint (end - buff, ==, strlen (buff));
1767  time_str = format_timestring (gdt0);
1768  g_assert_cmpstr (buff, ==, time_str);
1769  g_free (time_str);
1770 
1771  t = g_date_time_to_timespec (gdt1);
1772  end = gnc_timespec_to_iso8601_buff (t, buff);
1773  time_str = format_timestring (gdt1);
1774  g_assert_cmpstr (buff, ==, time_str);
1775  g_free (time_str);
1776 
1777 
1778  t = g_date_time_to_timespec (gdt2);
1779  end = gnc_timespec_to_iso8601_buff (t, buff);
1780  time_str = format_timestring (gdt2);
1781  g_assert_cmpstr (buff, ==, time_str);
1782  g_free (time_str);
1783 
1784  t = g_date_time_to_timespec (gdt3);
1785  end = gnc_timespec_to_iso8601_buff (t, buff);
1786  time_str = format_timestring (gdt3);
1787  g_assert_cmpstr (buff, ==, time_str);
1788  g_free (time_str);
1789 
1790  t = g_date_time_to_timespec (gdt4);
1791  end = gnc_timespec_to_iso8601_buff (t, buff);
1792  time_str = format_timestring (gdt4);
1793  g_assert_cmpstr (buff, ==, time_str);
1794  g_free (time_str);
1795 
1796  t = g_date_time_to_timespec (gdt5);
1797  end = gnc_timespec_to_iso8601_buff (t, buff);
1798  time_str = format_timestring (gdt5);
1799  g_assert_cmpstr (buff, ==, time_str);
1800  g_free (time_str);
1801 
1802  g_date_time_unref (gdt0);
1803  g_date_time_unref (gdt1);
1804  g_date_time_unref (gdt2);
1805  g_date_time_unref (gdt3);
1806  g_date_time_unref (gdt4);
1807  g_date_time_unref (gdt5);
1808  g_time_zone_unref (zulu);
1809  g_time_zone_unref (tz05);
1810  g_time_zone_unref (tz0840);
1811 }
1812 /* gnc_timespec2dmy
1813 void
1814 gnc_timespec2dmy (Timespec t, int *day, int *month, int *year)// C: 1 Local: 0:0:0
1815 */
1816 static void
1817 test_gnc_timespec2dmy (void)
1818 {
1819  GTimeZone *zulu = g_time_zone_new ("Z");
1820  GTimeZone *tz05 = g_time_zone_new ("-05");
1821  GTimeZone *tz0840 = g_time_zone_new ("+08:40");
1822  GDateTime *gdt0 = g_date_time_new_from_unix_utc (0);
1823  GDateTime *gdt1 = g_date_time_new (zulu, 1989, 3, 27, 13, 43, 27.345678);
1824  GDateTime *gdt2 = g_date_time_new (tz05, 2020, 11, 7, 6, 21, 19.0);
1825  GDateTime *gdt3 = g_date_time_new (tz0840, 2012, 7, 4, 19, 27, 44.0);
1826  GDateTime *gdt4 = g_date_time_new (tz05, 1961, 9, 22, 17, 53, 19.0);
1827  GDateTime *gdt5 = g_date_time_new (tz05, 2061, 1, 25, 23, 21, 19.0);
1828  GDateTime *gdt_local;
1829 
1830  int day, r_day, mo, r_mo, yr, r_yr;
1831  Timespec t;
1832 
1833  t = g_date_time_to_timespec (gdt0);
1834  gnc_timespec2dmy (t, &r_day, &r_mo, &r_yr);
1835  gdt_local = gncdt.to_local (gdt0);
1836  g_date_time_get_ymd (gdt_local, &yr, &mo, &day);
1837  g_date_time_unref (gdt_local);
1838  g_assert_cmpint (r_day, ==, day);
1839  g_assert_cmpint (r_mo, ==, mo);
1840  g_assert_cmpint (r_yr, ==, yr);
1841 
1842  t = g_date_time_to_timespec (gdt1);
1843  gnc_timespec2dmy (t, &r_day, &r_mo, &r_yr);
1844  gdt_local = gncdt.to_local (gdt1);
1845  g_date_time_get_ymd (gdt_local, &yr, &mo, &day);
1846  g_date_time_unref (gdt_local);
1847  g_assert_cmpint (r_day, ==, day);
1848  g_assert_cmpint (r_mo, ==, mo);
1849  g_assert_cmpint (r_yr, ==, yr);
1850 
1851  t = g_date_time_to_timespec (gdt2);
1852  gnc_timespec2dmy (t, &r_day, &r_mo, &r_yr);
1853  gdt_local = gncdt.to_local (gdt2);
1854  g_date_time_get_ymd (gdt_local, &yr, &mo, &day);
1855  g_date_time_unref (gdt_local);
1856  g_assert_cmpint (r_day, ==, day);
1857  g_assert_cmpint (r_mo, ==, mo);
1858  g_assert_cmpint (r_yr, ==, yr);
1859 
1860  t = g_date_time_to_timespec (gdt3);
1861  gnc_timespec2dmy (t, &r_day, &r_mo, &r_yr);
1862  gdt_local = gncdt.to_local (gdt3);
1863  g_date_time_get_ymd (gdt_local, &yr, &mo, &day);
1864  g_date_time_unref (gdt_local);
1865  g_assert_cmpint (r_day, ==, day);
1866  g_assert_cmpint (r_mo, ==, mo);
1867  g_assert_cmpint (r_yr, ==, yr);
1868 
1869  t = g_date_time_to_timespec (gdt4);
1870  gnc_timespec2dmy (t, &r_day, &r_mo, &r_yr);
1871  gdt_local = gncdt.to_local (gdt4);
1872  g_date_time_get_ymd (gdt_local, &yr, &mo, &day);
1873  g_date_time_unref (gdt_local);
1874  g_assert_cmpint (r_day, ==, day);
1875  g_assert_cmpint (r_mo, ==, mo);
1876  g_assert_cmpint (r_yr, ==, yr);
1877 
1878  t = g_date_time_to_timespec (gdt5);
1879  gnc_timespec2dmy (t, &r_day, &r_mo, &r_yr);
1880  gdt_local = gncdt.to_local (gdt5);
1881  g_date_time_get_ymd (gdt_local, &yr, &mo, &day);
1882  g_date_time_unref (gdt_local);
1883  /* 2038 Bug */
1884  g_assert_cmpint (r_day, ==, day);
1885  g_assert_cmpint (r_mo, ==, mo);
1886  g_assert_cmpint (r_yr, ==, yr);
1887 
1888  g_date_time_unref (gdt0);
1889  g_date_time_unref (gdt1);
1890  g_date_time_unref (gdt2);
1891  g_date_time_unref (gdt3);
1892  g_date_time_unref (gdt4);
1893  g_date_time_unref (gdt5);
1894  g_time_zone_unref (zulu);
1895  g_time_zone_unref (tz05);
1896  g_time_zone_unref (tz0840);
1897 }
1898 /* gnc_dmy2timespec_internal
1899 static Timespec
1900 gnc_dmy2timespec_internal (int day, int month, int year, gboolean start_of_day)// Local: 2:0:0
1901 */
1902 /* static void
1903 test_gnc_dmy2timespec_internal (void)
1904 {
1905 }*/
1906 /* gnc_dmy2timespec
1907 Timespec
1908 gnc_dmy2timespec (int day, int month, int year)// C: 8 in 5 Local: 1:0:0
1909 */
1910 static void
1911 test_gnc_dmy2timespec (void)
1912 {
1913  GDateTime *gdt1 = gncdt.new_local (1999, 7, 21, 0, 0, 0);
1914  GDateTime *gdt2 = gncdt.new_local (1918, 3, 31, 0, 0, 0);
1915  GDateTime *gdt3 = gncdt.new_local (1918, 4, 1, 0, 0, 0);
1916  GDateTime *gdt4 = gncdt.new_local (2057, 11, 20, 0, 0, 0);
1917 
1918  gint day, mon, yr;
1919  Timespec t, r_t;
1920 
1921  t = g_date_time_to_timespec (gdt1);
1922  g_date_time_get_ymd (gdt1, &yr, &mon, &day);
1923  r_t = gnc_dmy2timespec (day, mon, yr);
1924  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1925  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1926 
1927  t = g_date_time_to_timespec (gdt2);
1928  g_date_time_get_ymd (gdt2, &yr, &mon, &day);
1929  r_t = gnc_dmy2timespec (day, mon, yr);
1930  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1931  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1932 
1933  t = g_date_time_to_timespec (gdt3);
1934  g_date_time_get_ymd (gdt3, &yr, &mon, &day);
1935  r_t = gnc_dmy2timespec (day, mon, yr);
1936  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1937  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1938 
1939  t = g_date_time_to_timespec (gdt4);
1940  g_date_time_get_ymd (gdt4, &yr, &mon, &day);
1941  r_t = gnc_dmy2timespec (day, mon, yr);
1942  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1943  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1944 
1945  g_date_time_unref (gdt1);
1946  g_date_time_unref (gdt2);
1947  g_date_time_unref (gdt3);
1948  g_date_time_unref (gdt4);
1949 }
1950 /* gnc_dmy2timespec_end
1951 Timespec
1952 gnc_dmy2timespec_end (int day, int month, int year)// C: 1 Local: 0:0:0
1953 */
1954 static void
1955 test_gnc_dmy2timespec_end (void)
1956 {
1957  GDateTime *gdt1 = gncdt.new_local (1999, 7, 21,23,59, 59);
1958  GDateTime *gdt2 = gncdt.new_local (1918, 3, 30, 23, 59, 59);
1959  GDateTime *gdt3 = gncdt.new_local (1918, 3, 31, 23, 59, 59);
1960  GDateTime *gdt4 = gncdt.new_local (2057, 11, 20, 23, 59, 59);
1961 
1962  gint day, mon, yr;
1963  Timespec t, r_t;
1964 
1965  t = g_date_time_to_timespec (gdt1);
1966  g_date_time_get_ymd (gdt1, &yr, &mon, &day);
1967  r_t = gnc_dmy2timespec_end (day, mon, yr);
1968  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1969  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1970 
1971  t = g_date_time_to_timespec (gdt2);
1972  g_date_time_get_ymd (gdt2, &yr, &mon, &day);
1973  r_t = gnc_dmy2timespec_end (day, mon, yr);
1974  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1975  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1976 
1977  t = g_date_time_to_timespec (gdt3);
1978  g_date_time_get_ymd (gdt3, &yr, &mon, &day);
1979  r_t = gnc_dmy2timespec_end (day, mon, yr);
1980  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1981  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1982 
1983  t = g_date_time_to_timespec (gdt4);
1984  g_date_time_get_ymd (gdt4, &yr, &mon, &day);
1985  r_t = gnc_dmy2timespec_end (day, mon, yr);
1986  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1987  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1988 
1989  g_date_time_unref (gdt1);
1990  g_date_time_unref (gdt2);
1991  g_date_time_unref (gdt3);
1992  g_date_time_unref (gdt4);
1993 }
1994 /* gnc_timezone
1995 long int
1996 gnc_timezone (const struct tm *tm)// C: 5 in 2 Local: 2:0:0
1997 */
1998 /* static void
1999 test_gnc_timezone (void)
2000 {
2001 }*/
2002 /* timespecFromtime64
2003 void
2004 timespecFromtime64( Timespec *ts, time64 t )// C: 22 in 11 Local: 0:0:0
2005 */
2006 /* static void
2007 test_timespecFromtime64 (void)
2008 {
2009 }*/
2010 /* timespec_now
2011 Timespec
2012 timespec_now()// C: 2 in 2 Local: 0:0:0
2013 */
2014 /* static void
2015 test_timespec_now (void)
2016 {
2017 }*/
2018 /* timespecTotime64
2019 time64
2020 timespecTotime64 (Timespec ts)// C: 10 in 6 Local: 1:0:0
2021 */
2022 /* static void
2023 test_timespecTotime64 (void)
2024 {
2025 }*/
2026 /* timespec_to_gdate
2027 GDate timespec_to_gdate (Timespec ts)// C: 5 in 4 Local: 0:0:0
2028 */
2029 static void
2030 test_timespec_to_gdate (void)
2031 {
2032  GTimeZone *zulu = g_time_zone_new ("Z");
2033  GTimeZone *tz05 = g_time_zone_new ("-05");
2034  GTimeZone *tz0840 = g_time_zone_new ("+08:40");
2035  GDateTime *gdt0 = g_date_time_new_from_unix_utc (0);
2036  GDateTime *gdt1 = g_date_time_new (zulu, 1989, 3, 27, 13, 43, 27.345678);
2037  GDateTime *gdt2 = g_date_time_new (tz05, 2020, 11, 7, 6, 21, 19.0);
2038  GDateTime *gdt3 = g_date_time_new (tz0840, 2012, 7, 4, 19, 27, 44.0);
2039  GDateTime *gdt4 = g_date_time_new (tz05, 1961, 9, 22, 17, 53, 19.0);
2040  GDateTime *gdt5 = g_date_time_new (tz05, 2061, 1, 25, 23, 21, 19.0);
2041  GDateTime *gdt_local;
2042 
2043  gint day, mon, yr;
2044  GDate date1, date2;
2045  Timespec t;
2046 
2047  g_date_clear (&date2, 1);
2048 
2049  t = g_date_time_to_timespec (gdt0);
2050  date1 = timespec_to_gdate (t);
2051  gdt_local = gncdt.to_local (gdt0);
2052  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2053  g_date_time_unref (gdt_local);
2054  g_date_set_dmy (&date2, day, mon, yr);
2055  g_assert_cmpint (g_date_get_julian (&date1), ==, g_date_get_julian (&date2));
2056 
2057  t = g_date_time_to_timespec (gdt1);
2058  date1 = timespec_to_gdate (t);
2059  gdt_local = gncdt.to_local (gdt1);
2060  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2061  g_date_time_unref (gdt_local);
2062  g_date_set_dmy (&date2, day, mon, yr);
2063  g_assert_cmpint (g_date_get_julian (&date1), ==, g_date_get_julian (&date2));
2064 
2065  t = g_date_time_to_timespec (gdt2);
2066  date1 = timespec_to_gdate (t);
2067  gdt_local = gncdt.to_local (gdt2);
2068  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2069  g_date_time_unref (gdt_local);
2070  g_date_set_dmy (&date2, day, mon, yr);
2071  g_assert_cmpint (g_date_get_julian (&date1), ==, g_date_get_julian (&date2));
2072 
2073  t = g_date_time_to_timespec (gdt3);
2074  date1 = timespec_to_gdate (t);
2075  gdt_local = gncdt.to_local (gdt3);
2076  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2077  g_date_time_unref (gdt_local);
2078  g_date_set_dmy (&date2, day, mon, yr);
2079  g_assert_cmpint (g_date_get_julian (&date1), ==, g_date_get_julian (&date2));
2080  t = g_date_time_to_timespec (gdt4);
2081  date1 = timespec_to_gdate (t);
2082  gdt_local = gncdt.to_local (gdt4);
2083  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2084  g_date_time_unref (gdt_local);
2085  g_date_set_dmy (&date2, day, mon, yr);
2086  g_assert_cmpint (g_date_get_julian (&date1), ==, g_date_get_julian (&date2));
2087 
2088  t = g_date_time_to_timespec (gdt5);
2089  date1 = timespec_to_gdate (t);
2090  gdt_local = gncdt.to_local (gdt5);
2091  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2092  g_date_time_unref (gdt_local);
2093  g_date_set_dmy (&date2, day, mon, yr);
2094  g_assert_cmpint (g_date_get_julian (&date1),
2095  ==, g_date_get_julian (&date2));
2096 
2097  g_date_time_unref (gdt0);
2098  g_date_time_unref (gdt1);
2099  g_date_time_unref (gdt2);
2100  g_date_time_unref (gdt3);
2101  g_date_time_unref (gdt4);
2102  g_date_time_unref (gdt5);
2103  g_time_zone_unref (zulu);
2104  g_time_zone_unref (tz05);
2105  g_time_zone_unref (tz0840);
2106 }
2107 /* gdate_to_timespec
2108 Timespec gdate_to_timespec (GDate d)// C: 7 in 6 Local: 0:0:0
2109 */
2110 static void
2111 test_gdate_to_timespec (void)
2112 {
2113  GDateTime *gdt1 = gncdt.new_local (1999, 7, 21, 0, 0, 0);
2114  GDateTime *gdt2 = gncdt.new_local (1918, 3, 31, 0, 0, 0);
2115  GDateTime *gdt3 = gncdt.new_local (1918, 4, 1, 0, 0, 0);
2116  GDateTime *gdt4 = gncdt.new_local (2057, 11, 20, 0, 0, 0);
2117 
2118  gint day, mon, yr;
2119  Timespec t, r_t;
2120  GDate gd;
2121 
2122  g_date_clear (&gd, 1);
2123 
2124  t = g_date_time_to_timespec (gdt1);
2125  g_date_time_get_ymd (gdt1, &yr, &mon, &day);
2126  g_date_set_dmy (&gd, day, mon, yr);
2127  r_t = gdate_to_timespec (gd);
2128  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2129  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
2130 
2131  t = g_date_time_to_timespec (gdt2);
2132  g_date_time_get_ymd (gdt2, &yr, &mon, &day);
2133  g_date_set_dmy (&gd, day, mon, yr);
2134  r_t = gdate_to_timespec (gd);
2135  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2136  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
2137 
2138  t = g_date_time_to_timespec (gdt3);
2139  g_date_time_get_ymd (gdt3, &yr, &mon, &day);
2140  g_date_set_dmy (&gd, day, mon, yr);
2141  r_t = gdate_to_timespec (gd);
2142  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2143  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
2144 
2145  t = g_date_time_to_timespec (gdt4);
2146  g_date_time_get_ymd (gdt4, &yr, &mon, &day);
2147  g_date_set_dmy (&gd, day, mon, yr);
2148  r_t = gdate_to_timespec (gd);
2149  g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2150  g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
2151 
2152  g_date_time_unref (gdt1);
2153  g_date_time_unref (gdt2);
2154  g_date_time_unref (gdt3);
2155  g_date_time_unref (gdt4);
2156 }
2157 /* gnc_tm_get_day_start
2158 static void
2159 gnc_tm_get_day_start (struct tm *tm, time64 time_val)// Local: 3:0:0
2160 */
2161 /* static void
2162 test_gnc_tm_get_day_start (void)
2163 {
2164 }*/
2165 /* gnc_tm_get_day_end
2166 static void
2167 gnc_tm_get_day_end (struct tm *tm, time64 time_val)// Local: 3:0:0
2168 */
2169 /* static void
2170 test_gnc_tm_get_day_end (void)
2171 {
2172 }*/
2173 /* gnc_time64_get_day_start
2174 time64
2175 gnc_time64_get_day_start (time64 time_val)// C: 8 in 7 Local: 0:0:0
2176 */
2177 static void
2178 test_gnc_time64_get_day_start (void)
2179 {
2180  GTimeZone *zulu = g_time_zone_new ("Z");
2181  GTimeZone *tz05 = g_time_zone_new ("-05");
2182  GTimeZone *tz0840 = g_time_zone_new ("+08:40");
2183  GDateTime *gdt0 = g_date_time_new_from_unix_utc (0);
2184  GDateTime *gdt1 = g_date_time_new (zulu, 1989, 3, 27, 13, 43, 27.345678);
2185  GDateTime *gdt2 = g_date_time_new (tz05, 2020, 11, 7, 6, 21, 19.0);
2186  GDateTime *gdt3 = g_date_time_new (tz0840, 2012, 7, 4, 19, 27, 44.0);
2187  GDateTime *gdt4 = g_date_time_new (tz05, 1961, 9, 22, 17, 53, 19.0);
2188  GDateTime *gdt5 = g_date_time_new (tz05, 2061, 1, 25, 23, 21, 19.0);
2189  GDateTime *gdt_local, *gdt_day_begin;
2190 
2191  gint day, mon, yr;
2192  time64 time, t_time, r_time;
2193 
2194  gdt_local = gncdt.to_local (gdt0);
2195  time = g_date_time_to_unix (gdt0);
2196  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2197  gdt_day_begin = gncdt.new_local (yr, mon, day, 0, 0, 0);
2198  t_time = g_date_time_to_unix (gdt_day_begin);
2199  r_time = gnc_time64_get_day_start (time);
2200  /* This will work in the half of the world where localtime is later than UTC */
2201  g_assert_cmpint (t_time, ==, r_time);
2202 
2203  gdt_local = gncdt.to_local (gdt1);
2204  time = g_date_time_to_unix (gdt1);
2205  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2206  gdt_day_begin = gncdt.new_local (yr, mon, day, 0, 0, 0);
2207  t_time = g_date_time_to_unix (gdt_day_begin);
2208  r_time = gnc_time64_get_day_start (time);
2209  g_assert_cmpint (t_time, ==, r_time);
2210 
2211  gdt_local = gncdt.to_local (gdt2);
2212  time = g_date_time_to_unix (gdt2);
2213  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2214  gdt_day_begin = gncdt.new_local (yr, mon, day, 0, 0, 0);
2215  t_time = g_date_time_to_unix (gdt_day_begin);
2216  r_time = gnc_time64_get_day_start (time);
2217  g_assert_cmpint (t_time, ==, r_time);
2218 
2219  gdt_local = gncdt.to_local (gdt3);
2220  time = g_date_time_to_unix (gdt3);
2221  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2222  gdt_day_begin = gncdt.new_local (yr, mon, day, 0, 0, 0);
2223  t_time = g_date_time_to_unix (gdt_day_begin);
2224  r_time = gnc_time64_get_day_start (time);
2225  g_assert_cmpint (t_time, ==, r_time);
2226 
2227  gdt_local = gncdt.to_local (gdt4);
2228  time = g_date_time_to_unix (gdt4);
2229  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2230  gdt_day_begin = gncdt.new_local (yr, mon, day, 0, 0, 0);
2231  t_time = g_date_time_to_unix (gdt_day_begin);
2232  r_time = gnc_time64_get_day_start (time);
2233  g_assert_cmpint (t_time, ==, r_time);
2234 
2235  gdt_local = gncdt.to_local (gdt5);
2236  time = g_date_time_to_unix (gdt5);
2237  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2238  gdt_day_begin = gncdt.new_local (yr, mon, day, 0, 0, 0);
2239  t_time = g_date_time_to_unix (gdt_day_begin);
2240  r_time = gnc_time64_get_day_start (time);
2241  g_assert_cmpint (t_time, ==, r_time);
2242 
2243  g_date_time_unref (gdt0);
2244  g_date_time_unref (gdt1);
2245  g_date_time_unref (gdt2);
2246  g_date_time_unref (gdt3);
2247  g_date_time_unref (gdt4);
2248  g_date_time_unref (gdt5);
2249  g_time_zone_unref (zulu);
2250  g_time_zone_unref (tz05);
2251  g_time_zone_unref (tz0840);
2252 }
2253 /* gnc_time64_get_day_end
2254 time64
2255 gnc_time64_get_day_end (time64 time_val)// C: 12 in 8 Local: 0:0:0
2256 */
2257 static void
2258 test_gnc_time64_get_day_end (void)
2259 {
2260  GTimeZone *zulu = g_time_zone_new ("Z");
2261  GTimeZone *tz05 = g_time_zone_new ("-05");
2262  GTimeZone *tz0840 = g_time_zone_new ("+08:40");
2263  GDateTime *gdt0 = g_date_time_new_from_unix_utc (0);
2264  GDateTime *gdt1 = g_date_time_new (zulu, 1989, 3, 27, 13, 43, 27.345678);
2265  GDateTime *gdt2 = g_date_time_new (tz05, 2020, 11, 7, 6, 21, 19.0);
2266  GDateTime *gdt3 = g_date_time_new (tz0840, 2012, 7, 4, 19, 27, 44.0);
2267  GDateTime *gdt4 = g_date_time_new (tz05, 1961, 9, 22, 17, 53, 19.0);
2268  GDateTime *gdt5 = g_date_time_new (tz05, 2061, 1, 25, 23, 21, 19.0);
2269  GDateTime *gdt_local, *gdt_day_end;
2270 
2271  gint day, mon, yr;
2272  time64 time, t_time, r_time;
2273 
2274  gdt_local = gncdt.to_local (gdt0);
2275  time = g_date_time_to_unix (gdt0);
2276  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2277  gdt_day_end = gncdt.new_local (yr, mon, day, 23, 59, 59);
2278  t_time = g_date_time_to_unix (gdt_day_end);
2279  r_time = gnc_time64_get_day_end (time);
2280  g_assert_cmpint (t_time, ==, r_time);
2281 
2282  gdt_local = gncdt.to_local (gdt1);
2283  time = g_date_time_to_unix (gdt1);
2284  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2285  gdt_day_end = gncdt.new_local (yr, mon, day, 23, 59, 59);
2286  t_time = g_date_time_to_unix (gdt_day_end);
2287  r_time = gnc_time64_get_day_end (time);
2288  g_assert_cmpint (t_time, ==, r_time);
2289 
2290  gdt_local = gncdt.to_local (gdt2);
2291  time = g_date_time_to_unix (gdt2);
2292  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2293  gdt_day_end = gncdt.new_local (yr, mon, day, 23, 59, 59);
2294  t_time = g_date_time_to_unix (gdt_day_end);
2295  r_time = gnc_time64_get_day_end (time);
2296  g_assert_cmpint (t_time, ==, r_time);
2297 
2298  gdt_local = gncdt.to_local (gdt3);
2299  time = g_date_time_to_unix (gdt3);
2300  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2301  gdt_day_end = gncdt.new_local (yr, mon, day, 23, 59, 59);
2302  t_time = g_date_time_to_unix (gdt_day_end);
2303  r_time = gnc_time64_get_day_end (time);
2304  g_assert_cmpint (t_time, ==, r_time);
2305 
2306  gdt_local = gncdt.to_local (gdt4);
2307  time = g_date_time_to_unix (gdt4);
2308  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2309  gdt_day_end = gncdt.new_local (yr, mon, day, 23, 59, 59);
2310  t_time = g_date_time_to_unix (gdt_day_end);
2311  r_time = gnc_time64_get_day_end (time);
2312  g_assert_cmpint (t_time, ==, r_time);
2313 
2314  gdt_local = gncdt.to_local (gdt5);
2315  time = g_date_time_to_unix (gdt5);
2316  g_date_time_get_ymd (gdt_local, &yr, &mon, &day);
2317  gdt_day_end = gncdt.new_local (yr, mon, day, 23, 59, 59);
2318  t_time = g_date_time_to_unix (gdt_day_end);
2319  r_time = gnc_time64_get_day_end (time);
2320  g_assert_cmpint (t_time, ==, r_time);
2321 
2322  g_date_time_unref (gdt0);
2323  g_date_time_unref (gdt1);
2324  g_date_time_unref (gdt2);
2325  g_date_time_unref (gdt3);
2326  g_date_time_unref (gdt4);
2327  g_date_time_unref (gdt5);
2328  g_time_zone_unref (zulu);
2329  g_time_zone_unref (tz05);
2330  g_time_zone_unref (tz0840);
2331 }
2332 /* gnc_tm_get_today_start
2333 void
2334 gnc_tm_get_today_start (struct tm *tm)// C: 3 in 3 Local: 0:0:0
2335 */
2336 /* static void
2337 test_gnc_tm_get_today_start (void)
2338 {
2339 }*/
2340 // Not Used
2341 /* gnc_tm_get_today_end
2342 void
2343 gnc_tm_get_today_end (struct tm *tm)// Local: 0:0:0
2344 */
2345 /* gnc_time64_get_today_start
2346 time64
2347 gnc_time64_get_today_start (void)// C: 7 in 4 Local: 0:0:0
2348 */
2349 /* static void
2350 test_gnc_time64_get_today_start (void)
2351 {
2352 }*/
2353 /* gnc_time64_get_today_end
2354 time64
2355 gnc_time64_get_today_end (void)// C: 8 in 5 Local: 0:0:0
2356 */
2357 /* static void
2358 test_gnc_time64_get_today_end (void)
2359 {
2360 }*/
2361 /* gnc_dow_abbrev
2362 void
2363 gnc_dow_abbrev(gchar *buf, int buf_len, int dow)// C: 4 in 2 Local: 0:0:0
2364 */
2365 /* static void
2366 test_gnc_dow_abbrev (void)
2367 {
2368 }*/
2369 /* timespec_boxed_copy_func
2370 static gpointer
2371 timespec_boxed_copy_func( gpointer in_timespec )// Local: 0:1:0
2372 */
2373 /* static void
2374 test_timespec_boxed_copy_func (void)
2375 {
2376 }*/
2377 /* timespec_boxed_free_func
2378 static void
2379 timespec_boxed_free_func( gpointer in_timespec )// Local: 0:1:0
2380 */
2381 /* static void
2382 test_timespec_boxed_free_func (void)
2383 {
2384 }*/
2385 // Not Used
2386 /* timespec_get_type
2387 GType
2388 timespec_get_type( void )// Local: 0:0:0
2389 */
2390 
2391 
2392 void
2393 test_suite_gnc_date (void)
2394 {
2395  _gnc_date_time_init (&gncdt);
2396 
2397 
2398  GNC_TEST_ADD_FUNC (suitename, "gnc localtime", test_gnc_localtime);
2399  GNC_TEST_ADD_FUNC (suitename, "gnc gmtime", test_gnc_gmtime);
2400  GNC_TEST_ADD_FUNC (suitename, "gnc mktime", test_gnc_mktime);
2401  GNC_TEST_ADD_FUNC (suitename, "gnc mktime normalization", test_gnc_mktime_normalization);
2402  GNC_TEST_ADD_FUNC (suitename, "gnc ctime", test_gnc_ctime);
2403  GNC_TEST_ADD_FUNC (suitename, "gnc time", test_gnc_time);
2404 
2405  GNC_TEST_ADD_FUNC (suitename, "gnc date dateformat to string", test_gnc_date_dateformat_to_string);
2406  GNC_TEST_ADD_FUNC (suitename, "gnc date string to dateformat", test_gnc_date_string_to_dateformat);
2407  GNC_TEST_ADD_FUNC (suitename, "gnc date monthformat to string", test_gnc_date_monthformat_to_string);
2408  GNC_TEST_ADD_FUNC (suitename, "gnc date string to monthformat", test_gnc_date_string_to_monthformat);
2409  GNC_TEST_ADD_FUNC (suitename, "timespec normalize", test_timespec_normalize);
2410  GNC_TEST_ADD_FUNC (suitename, "timespec equal", test_timespec_equal);
2411  GNC_TEST_ADD_FUNC (suitename, "timespec cmp", test_timespec_cmp);
2412  GNC_TEST_ADD_FUNC (suitename, "timespec diff", test_timespec_diff);
2413  GNC_TEST_ADD_FUNC (suitename, "timespec abs", test_timespec_abs);
2414  GNC_TEST_ADD_FUNC (suitename, "timespecCanonicalDayTime", test_timespecCanonicalDayTime);
2415  GNC_TEST_ADD_FUNC (suitename, "date get last mday", test_gnc_date_get_last_mday);
2416  GNC_TEST_ADD_FUNC (suitename, "qof date format set", test_qof_date_format_set);
2417 // GNC_TEST_ADD_FUNC (suitename, "qof date completion set", test_qof_date_completion_set);
2418  GNC_TEST_ADD_FUNC (suitename, "qof print date dmy buff", test_qof_print_date_dmy_buff);
2419  GNC_TEST_ADD_FUNC (suitename, "qof print date buff", test_qof_print_date_buff);
2420  GNC_TEST_ADD_FUNC (suitename, "qof print gdate", test_qof_print_gdate);
2421  GNC_TEST_ADD_FUNC (suitename, "qof print date", test_qof_print_date);
2422  GNC_TEST_ADD_FUNC (suitename, "gnc print date", test_gnc_print_date);
2423 // GNC_TEST_ADD_FUNC (suitename, "floordiv", test_floordiv);
2424 // GNC_TEST_ADD_FUNC (suitename, "qof scan date internal", test_qof_scan_date_internal);
2425  GNC_TEST_ADD_FUNC (suitename, "qof scan date", test_qof_scan_date);
2426 // GNC_TEST_ADD_FUNC (suitename, "dateSeparator", test_dateSeparator);
2427 // GNC_TEST_ADD_FUNC (suitename, "qof time format from utf8", test_qof_time_format_from_utf8);
2428 // GNC_TEST_ADD_FUNC (suitename, "qof formatted time to utf8", test_qof_formatted_time_to_utf8);
2429 // GNC_TEST_ADD_FUNC (suitename, "qof format time", test_qof_format_time);
2430 // GNC_TEST_ADD_FUNC (suitename, "qof strftime", test_qof_strftime);
2431  GNC_TEST_ADD_FUNC (suitename, "gnc_date_timestamp", test_gnc_date_timestamp);
2432  GNC_TEST_ADD_FUNC (suitename, "gnc iso8601 to timespec gmt", test_gnc_iso8601_to_timespec_gmt);
2433  GNC_TEST_ADD_FUNC (suitename, "gnc timespec to iso8601 buff", test_gnc_timespec_to_iso8601_buff);
2434  GNC_TEST_ADD_FUNC (suitename, "gnc timespec2dmy", test_gnc_timespec2dmy);
2435 // GNC_TEST_ADD_FUNC (suitename, "gnc dmy2timespec internal", test_gnc_dmy2timespec_internal);
2436  GNC_TEST_ADD_FUNC (suitename, "gnc dmy2timespec", test_gnc_dmy2timespec);
2437  GNC_TEST_ADD_FUNC (suitename, "gnc dmy2timespec end", test_gnc_dmy2timespec_end);
2438 // GNC_TEST_ADD_FUNC (suitename, "gnc timezone", test_gnc_timezone);
2439 // GNC_TEST_ADD_FUNC (suitename, "timespecFromTime t", test_timespecFromtime64);
2440 // GNC_TEST_ADD_FUNC (suitename, "timespec now", test_timespec_now);
2441 // GNC_TEST_ADD_FUNC (suitename, "timespecToTime t", test_timespecTotime64);
2442  GNC_TEST_ADD_FUNC (suitename, "timespec to gdate", test_timespec_to_gdate);
2443  GNC_TEST_ADD_FUNC (suitename, "gdate to timespec", test_gdate_to_timespec);
2444 // GNC_TEST_ADD_FUNC (suitename, "gnc tm get day start", test_gnc_tm_get_day_start);
2445 // GNC_TEST_ADD_FUNC (suitename, "gnc tm get day end", test_gnc_tm_get_day_end);
2446  GNC_TEST_ADD_FUNC (suitename, "gnc time64 get day start", test_gnc_time64_get_day_start);
2447  GNC_TEST_ADD_FUNC (suitename, "gnc time64 get day end", test_gnc_time64_get_day_end);
2448 // GNC_TEST_ADD_FUNC (suitename, "gnc tm get today start", test_gnc_tm_get_today_start);
2449 // GNC_TEST_ADD_FUNC (suitename, "gnc timet get today start", test_gnc_time64_get_today_start);
2450 // GNC_TEST_ADD_FUNC (suitename, "gnc timet get today end", test_gnc_time64_get_today_end);
2451 // GNC_TEST_ADD_FUNC (suitename, "gnc dow abbrev", test_gnc_dow_abbrev);
2452 // GNC_TEST_ADD_FUNC (suitename, "timespec boxed copy func", test_timespec_boxed_copy_func);
2453 // GNC_TEST_ADD_FUNC (suitename, "timespec boxed free func", test_timespec_boxed_free_func);
2454 
2455 }
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
const char * gnc_print_date(Timespec ts)
gboolean gnc_date_string_to_monthformat(const gchar *format_string, GNCDateMonthFormat *format)
Converts the month format to a printable string.
const gchar * gnc_date_dateformat_to_string(QofDateFormat format)
The string->value versions return FALSE on success and TRUE on failure.
Timespec timespecCanonicalDayTime(Timespec t)
Timespec gnc_dmy2timespec_end(gint day, gint month, gint year)
gboolean timespec_equal(const Timespec *ta, const Timespec *tb)
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
Timespec gnc_dmy2timespec(gint day, gint month, gint year)
Timespec timespec_abs(const Timespec *t)
void gnc_tm_free(struct tm *time)
free a struct tm* created with gnc_localtime() or gnc_gmtime()
gint timespec_cmp(const Timespec *ta, const Timespec *tb)
GDate timespec_to_gdate(Timespec ts)
void qof_date_completion_set(QofDateCompletion dc, int backmonths)
time64 gnc_time64_get_day_end(time64 time_val)
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
int gnc_date_get_last_mday(int month, int year)
GNCDateMonthFormat
Definition: gnc-date.h:150
#define MAX_DATE_LENGTH
Definition: gnc-date.h:106
struct tm * gnc_localtime(const time64 *secs)
fill out a time struct from a 64-bit time value.
Timespec gnc_iso8601_to_timespec_gmt(const gchar *)
time64 gnc_time64_get_day_start(time64 time_val)
Timespec timespec_diff(const Timespec *ta, const Timespec *tb)
size_t qof_print_date_dmy_buff(gchar *buff, size_t buflen, int day, int month, int year)
gboolean qof_scan_date(const char *buff, int *day, int *month, int *year)
QofDateFormat qof_date_format_get(void)
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
void qof_date_format_set(QofDateFormat df)
time64 gnc_time(time64 *tbuf)
get the current local time
gint64 time64
Definition: gnc-date.h:83
Timespec gdate_to_timespec(GDate d)
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
gchar * gnc_ctime(const time64 *secs)
Return a string representation of a date from a 64-bit time value.
gboolean gnc_date_string_to_dateformat(const gchar *format_string, QofDateFormat *format)
Converts the date format to a printable string.
QofDateFormat
Definition: gnc-date.h:121
void gnc_timespec2dmy(Timespec ts, gint *day, gint *month, gint *year)
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd)
char * gnc_date_timestamp(void)
Make a timestamp in YYYYMMDDHHMMSS format.