32 #include <unittest-support.h>
39 #include "../gnc-date.h"
40 #include "../gnc-date-p.h"
42 #include <glib/gprintf.h>
44 # include "strptime.h"
53 static const gchar *suitename =
"/qof/gnc-date";
54 void test_suite_gnc_date (
void );
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 *);
82 test_gnc_localtime (
void)
84 time64 secs[6] = {-43238956734LL, -1123692LL, 432761LL,
85 723349832LL, 887326459367LL,
90 #if defined(__clang__)
91 #define _func "struct tm *gnc_localtime_r(const time64 *, struct tm *)"
93 #define _func "tm* gnc_localtime_r(const time64*, tm*)"
96 gchar *msg = _func
": assertion " _Q
"gdt != NULL' failed";
98 gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
99 gchar *logdomain =
"qof";
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);
104 for (ind = 0; ind < G_N_ELEMENTS (secs); ind++)
107 GDateTime *gdt = gncdt.new_from_unix_local (secs[ind]);
110 g_assert (time == NULL);
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));
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);
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);
130 g_date_time_unref (gdt);
133 g_assert_cmpint (check.hits, ==, 1);
134 g_log_set_default_handler (hdlr, NULL);
138 test_gnc_gmtime (
void)
140 time64 secs[6] = {-43238956734LL, -1123692LL, 432761LL,
141 723349832LL, 887326459367LL, 1175964426LL
143 struct tm answers[6] =
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 },
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 },
162 #if defined(__clang__)
163 #define _func "struct tm *gnc_gmtime(const time64 *)"
165 #define _func "tm* gnc_gmtime(const time64*)"
168 gchar *msg = _func
": assertion " _Q
"gdt != NULL' failed";
170 gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
171 gchar *logdomain =
"qof";
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);
176 for (ind = 0; ind < G_N_ELEMENTS (secs); ind++)
179 GDateTime *gdt = g_date_time_new_from_unix_utc (secs[ind]);
182 g_assert (time == NULL);
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);
197 g_date_time_unref (gdt);
200 g_assert_cmpint (check.hits, ==, 1);
201 g_log_set_default_handler (hdlr, NULL);
205 test_gnc_mktime (
void)
214 { -43238956734LL, 4, 297 },
215 { -1123692LL, 4, 352 },
217 { 723349832LL, 4, 338 },
218 { 1175964426LL, 6, 97 }
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 },
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 },
239 for (ind = 0; ind < G_N_ELEMENTS (time); ind++)
242 GDateTime *gdt = gncdt.new_local (time[ind].tm_year + 1900,
243 time[ind].tm_mon + 1,
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);
255 g_assert_cmpint (time[ind].tm_isdst, ==, 0);
257 #ifdef HAVE_STRUCT_TM_GMTOFF
258 g_assert_cmpint (time[ind].tm_gmtoff, ==, offset);
260 g_date_time_unref (gdt);
269 test_gnc_mktime_normalization (
void)
276 } ans = { 723349832LL, 4, 338 };
278 struct tm normal_time =
279 #ifdef HAVE_STRUCT_TM_GMTOFF
281 32, 30, 2, 3, 11, 92, 0, 0, -1, 0, NULL
285 32, 30, 2, 3, 11, 92, 0, 0, -1
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 },
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 },
304 for (ind = 0; ind < G_N_ELEMENTS (time); ind++)
307 GDateTime *gdt = gncdt.new_local (time[ind].tm_year + 1900,
308 time[ind].tm_mon + 1,
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);
326 g_assert_cmpint (time[ind].tm_isdst, ==, 0);
327 #ifdef HAVE_STRUCT_TM_GMTOFF
328 g_assert_cmpint (time[ind].tm_gmtoff, ==, offset);
330 g_date_time_unref (gdt);
335 test_gnc_ctime (
void)
337 time64 secs[5] = {-43238956734LL, -1123692LL, 432761LL,
338 723349832LL, 1175964426LL
341 for (ind = 0; ind < G_N_ELEMENTS (secs); ind++)
343 GDateTime *gdt = gncdt.new_from_unix_local (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);
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);
374 test_gnc_date_dateformat_to_string (
void)
390 test_gnc_date_string_to_dateformat (
void)
394 g_assert_cmpint (fmt, ==, 123);
411 g_assert_cmpint (fmt, ==, 123);
413 g_assert_cmpint (fmt, ==, 123);
421 test_gnc_date_monthformat_to_string (
void)
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);
433 test_gnc_date_string_to_monthformat (
void)
437 g_assert_cmpint (fmt, ==, 123);
439 g_assert_cmpint (fmt, ==, GNCDATE_MONTH_NUMBER);
441 g_assert_cmpint (fmt, ==, GNCDATE_MONTH_ABBREV);
443 g_assert_cmpint (fmt, ==, GNCDATE_MONTH_NAME);
446 g_assert_cmpint (fmt, ==, 123);
448 g_assert_cmpint (fmt, ==, 123);
452 test_gnc_setlocale (
int category, gchar *locale)
454 gchar *suffixes[] = {
"utf8",
"UTF-8"};
458 if (g_strcmp0 (locale,
"en_US") == 0
459 && setlocale (category,
"English_US"))
461 if (g_strcmp0 (locale,
"en_GB") == 0
462 && setlocale (category,
"English_UK"))
464 if (g_strcmp0 (locale,
"fr_FR") == 0
465 && setlocale (category,
"French_France"))
469 if (setlocale (category, locale) != NULL)
472 for (i = 0; i < G_N_ELEMENTS (suffixes); i++)
474 gchar * modlocale = g_strdup_printf (
"%s.%s", locale, suffixes[i]);
475 gchar *localeval = setlocale (category, modlocale);
477 if (localeval != NULL)
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 ();
492 test_timespec_normalize (
void)
494 const int offset = 4396432;
495 const int factor = 2;
497 Timespec t = { base, factor * NANOS_PER_SECOND + offset };
500 tf->timespec_normalize (&t);
501 g_assert_cmpint (t.tv_sec, ==, base + factor);
502 g_assert_cmpint (t.tv_nsec, ==, offset);
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);
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);
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);
531 test_timespec_equal (
void)
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;
559 test_timespec_cmp (
void)
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;
593 test_timespec_diff (
void)
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;
612 g_assert_cmpint (tt.tv_sec, ==, 0);
613 g_assert_cmpint (tt.tv_nsec, ==, 0);
616 g_assert_cmpint (tt.tv_sec, ==, secs1 - secs2 - 1);
617 g_assert_cmpint (tt.tv_nsec, ==, nsec1 - nsec2 + NANOS_PER_SECOND);
620 g_assert_cmpint (tt.tv_sec, ==, 0);
621 g_assert_cmpint (tt.tv_nsec, ==, nsec1 - nsec2);
624 g_assert_cmpint (tt.tv_sec, ==, 0);
625 g_assert_cmpint (tt.tv_nsec, ==, 0);
628 if (
sizeof (glong) > 4)
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);
636 g_assert_cmpint (tt.tv_sec, ==, secs2 - secs1 - 3);
637 g_assert_cmpint (tt.tv_nsec, <, 0);
640 g_assert_cmpint (tt.tv_sec, ==, -secs2 - secs3 + 1);
641 g_assert_cmpint (tt.tv_nsec, ==, nsec2 - nsec1 - NANOS_PER_SECOND);
649 test_timespec_abs (
void)
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;
663 g_assert_cmpint (tt.tv_sec, ==, secs1);
664 g_assert_cmpint (tt.tv_nsec, ==, nsec1);
667 g_assert_cmpint (tt.tv_sec, ==, secs2);
668 g_assert_cmpint (tt.tv_nsec, ==, nsec2);
671 g_assert_cmpint (tt.tv_sec, ==, secs2 - 1);
672 g_assert_cmpint (tt.tv_nsec, ==, NANOS_PER_SECOND - nsec2);
675 g_assert_cmpint (tt.tv_sec, ==, secs1 - 1);
676 g_assert_cmpint (tt.tv_nsec, ==, NANOS_PER_SECOND - nsec1);
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);
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);
700 test_timespecCanonicalDayTime (
void)
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;
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);
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);
734 test_gnc_date_get_last_mday (
void)
775 test_qof_date_format_set (
void)
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";
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);
785 g_assert_cmpint (check.hits, ==,1);
789 g_assert_cmpint (check.hits, ==,1);
790 g_log_set_default_handler (hdlr, NULL);
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))
823 # define GNC_D_FMT "%Y-%m-%d"
824 # define GNC_D_T_FMT "%Y-%m-%d %r"
825 # define GNC_T_FMT "%r"
828 static void tm_set_dmy (
struct tm *tm, gint year, gint month, gint mday)
830 tm->tm_year = year - 1900;
831 tm->tm_mon = month - 1;
836 test_qof_print_date_dmy_buff (
void)
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
847 memset ((gpointer)buff, 0,
sizeof (buff));
849 g_assert_cmpstr (buff, ==,
"23/11/1974");
850 memset ((gpointer)buff, 0,
sizeof (buff));
852 g_assert_cmpstr (buff, ==,
"02/02/1961");
853 memset ((gpointer)buff, 0,
sizeof (buff));
855 g_assert_cmpstr (buff, ==,
"16/06/2045");
858 memset ((gpointer)buff, 0,
sizeof (buff));
860 g_assert_cmpstr (buff, ==,
"23.11.1974");
861 memset ((gpointer)buff, 0,
sizeof (buff));
863 g_assert_cmpstr (buff, ==,
"02.02.1961");
864 memset ((gpointer)buff, 0,
sizeof (buff));
866 g_assert_cmpstr (buff, ==,
"16.06.2045");
869 memset ((gpointer)buff, 0,
sizeof (buff));
871 g_assert_cmpstr (buff, ==,
"11/23/1974");
872 memset ((gpointer)buff, 0,
sizeof (buff));
874 g_assert_cmpstr (buff, ==,
"02/02/1961");
875 memset ((gpointer)buff, 0,
sizeof (buff));
877 g_assert_cmpstr (buff, ==,
"06/16/2045");
880 memset ((gpointer)buff, 0,
sizeof (buff));
882 g_assert_cmpstr (buff, ==,
"1974-11-23");
883 memset ((gpointer)buff, 0,
sizeof (buff));
886 g_assert_cmpstr (buff, ==,
"1961-02-02");
887 memset ((gpointer)buff, 0,
sizeof (buff));
890 g_assert_cmpstr (buff, ==,
"2045-06-16");
893 test_gnc_setlocale (LC_TIME,
"en_US");
894 tm_set_dmy (&tm, 1974, 11, 23);
896 memset ((gpointer)buff, 0,
sizeof (buff));
898 tm.tm_mon + 1, tm.tm_year + 1900),
900 g_assert_cmpstr (buff, ==, t_buff);
903 tm_set_dmy (&tm, 1961, 2, 2);
905 memset ((gpointer)buff, 0,
sizeof (buff));
907 tm.tm_mon + 1, tm.tm_year + 1900),
909 g_assert_cmpstr (buff, ==, t_buff);
910 memset ((gpointer)buff, 0,
sizeof (buff));
911 tm_set_dmy (&tm, 2045, 6, 16);
913 memset ((gpointer)buff, 0,
sizeof (buff));
915 tm.tm_mon + 1, tm.tm_year + 1900),
917 g_assert_cmpstr (buff, ==, t_buff);
919 test_gnc_setlocale (LC_TIME,
"en_GB");
920 tm_set_dmy (&tm, 1974, 11, 23);
922 memset ((gpointer)buff, 0,
sizeof (buff));
924 tm.tm_mon + 1, tm.tm_year + 1900),
926 g_assert_cmpstr (buff, ==, t_buff);
927 tm_set_dmy (&tm, 1961, 2, 2);
929 memset ((gpointer)buff, 0,
sizeof (buff));
931 tm.tm_mon + 1, tm.tm_year + 1900),
933 g_assert_cmpstr (buff, ==, t_buff);
934 memset ((gpointer)buff, 0,
sizeof (buff));
935 tm_set_dmy (&tm, 2045, 6, 16);
937 memset ((gpointer)buff, 0,
sizeof (buff));
939 tm.tm_mon + 1, tm.tm_year + 1900),
941 g_assert_cmpstr (buff, ==, t_buff);
943 test_gnc_setlocale (LC_TIME,
"fr_FR");
944 tm_set_dmy (&tm, 1974, 11, 23);
946 memset ((gpointer)buff, 0,
sizeof (buff));
948 tm.tm_mon + 1, tm.tm_year + 1900),
950 g_assert_cmpstr (buff, ==, t_buff);
951 tm_set_dmy (&tm, 1961, 2, 2);
953 memset ((gpointer)buff, 0,
sizeof (buff));
955 tm.tm_mon + 1, tm.tm_year + 1900),
957 g_assert_cmpstr (buff, ==, t_buff);
958 memset ((gpointer)buff, 0,
sizeof (buff));
959 tm_set_dmy (&tm, 2045, 6, 16);
961 memset ((gpointer)buff, 0,
sizeof (buff));
963 tm.tm_mon + 1, tm.tm_year + 1900),
965 g_assert_cmpstr (buff, ==, t_buff);
967 setlocale (LC_TIME, locale);
981 #define test_assert_localized_timestring(time, datestr) \
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); \
996 test_qof_print_date_buff (
void)
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);
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);
1009 memset ((gpointer)buff, 0,
sizeof (buff));
1012 g_assert_cmpstr (buff, ==,
"23/11/1974");
1013 memset ((gpointer)buff, 0,
sizeof (buff));
1016 g_assert_cmpstr (buff, ==,
"02/02/1961");
1018 memset ((gpointer)buff, 0,
sizeof (buff));
1021 g_assert_cmpstr (buff, ==,
"16/06/2045");
1024 memset ((gpointer)buff, 0,
sizeof (buff));
1027 g_assert_cmpstr (buff, ==,
"23.11.1974");
1028 memset ((gpointer)buff, 0,
sizeof (buff));
1031 g_assert_cmpstr (buff, ==,
"02.02.1961");
1033 memset ((gpointer)buff, 0,
sizeof (buff));
1036 g_assert_cmpstr (buff, ==,
"16.06.2045");
1039 memset ((gpointer)buff, 0,
sizeof (buff));
1042 g_assert_cmpstr (buff, ==,
"11/23/1974");
1043 memset ((gpointer)buff, 0,
sizeof (buff));
1046 g_assert_cmpstr (buff, ==,
"02/02/1961");
1048 memset ((gpointer)buff, 0,
sizeof (buff));
1051 g_assert_cmpstr (buff, ==,
"06/16/2045");
1054 memset ((gpointer)buff, 0,
sizeof (buff));
1057 g_assert_cmpstr (buff, ==,
"1974-11-23");
1058 memset ((gpointer)buff, 0,
sizeof (buff));
1061 g_assert_cmpstr (buff, ==,
"1961-02-02");
1063 memset ((gpointer)buff, 0,
sizeof (buff));
1066 g_assert_cmpstr (buff, ==,
"2045-06-16");
1069 test_gnc_setlocale (LC_TIME,
"en_US");
1070 memset ((gpointer)buff, 0,
sizeof (buff));
1073 g_assert_cmpstr (buff, ==, g_date_time_format (gd1, GNC_D_FMT));
1074 memset ((gpointer)buff, 0,
sizeof (buff));
1077 g_assert_cmpstr (buff, ==, g_date_time_format (gd2, GNC_D_FMT));
1079 memset ((gpointer)buff, 0,
sizeof (buff));
1082 g_assert_cmpstr (buff, ==, g_date_time_format (gd3, GNC_D_FMT));
1084 test_gnc_setlocale (LC_TIME,
"en_GB");
1085 memset ((gpointer)buff, 0,
sizeof (buff));
1088 g_assert_cmpstr (buff, ==, g_date_time_format (gd1, GNC_D_FMT));
1089 memset ((gpointer)buff, 0,
sizeof (buff));
1092 g_assert_cmpstr (buff, ==, g_date_time_format (gd2, GNC_D_FMT));
1093 memset ((gpointer)buff, 0,
sizeof (buff));
1096 g_assert_cmpstr (buff, ==, g_date_time_format (gd3, GNC_D_FMT));
1098 test_gnc_setlocale (LC_TIME,
"fr_FR");
1099 memset ((gpointer)buff, 0,
sizeof (buff));
1102 g_assert_cmpstr (buff, ==, g_date_time_format (gd1, GNC_D_FMT));
1103 memset ((gpointer)buff, 0,
sizeof (buff));
1106 g_assert_cmpstr (buff, ==, g_date_time_format (gd2, GNC_D_FMT));
1107 memset ((gpointer)buff, 0,
sizeof (buff));
1110 g_assert_cmpstr (buff, ==, g_date_time_format (gd3, GNC_D_FMT));
1112 setlocale (LC_TIME, locale);
1114 g_date_time_unref (gd1);
1115 g_date_time_unref (gd2);
1116 g_date_time_unref (gd3);
1123 test_qof_print_gdate (
void)
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);
1132 memset ((gpointer)buff, 0,
sizeof (buff));
1135 g_assert_cmpstr (buff, ==,
"23/11/1974");
1136 memset ((gpointer)buff, 0,
sizeof (buff));
1139 g_assert_cmpstr (buff, ==,
"02/02/1961");
1140 memset ((gpointer)buff, 0,
sizeof (buff));
1143 g_assert_cmpstr (buff, ==,
"16/06/2045");
1146 memset ((gpointer)buff, 0,
sizeof (buff));
1149 g_assert_cmpstr (buff, ==,
"23.11.1974");
1150 memset ((gpointer)buff, 0,
sizeof (buff));
1153 g_assert_cmpstr (buff, ==,
"02.02.1961");
1154 memset ((gpointer)buff, 0,
sizeof (buff));
1157 g_assert_cmpstr (buff, ==,
"16.06.2045");
1161 memset ((gpointer)buff, 0,
sizeof (buff));
1164 g_assert_cmpstr (buff, ==,
"11/23/1974");
1165 memset ((gpointer)buff, 0,
sizeof (buff));
1168 g_assert_cmpstr (buff, ==,
"02/02/1961");
1169 memset ((gpointer)buff, 0,
sizeof (buff));
1172 g_assert_cmpstr (buff, ==,
"06/16/2045");
1176 memset ((gpointer)buff, 0,
sizeof (buff));
1179 g_assert_cmpstr (buff, ==,
"1974-11-23");
1180 memset ((gpointer)buff, 0,
sizeof (buff));
1183 g_assert_cmpstr (buff, ==,
"1961-02-02");
1184 memset ((gpointer)buff, 0,
sizeof (buff));
1187 g_assert_cmpstr (buff, ==,
"2045-06-16");
1191 test_gnc_setlocale (LC_TIME,
"en_US");
1192 memset ((gpointer)buff, 0,
sizeof (buff));
1196 g_assert_cmpstr (buff, ==, t_buff);
1197 memset ((gpointer)buff, 0,
sizeof (buff));
1201 g_assert_cmpstr (buff, ==, t_buff);
1202 memset ((gpointer)buff, 0,
sizeof (buff));
1206 g_assert_cmpstr (buff, ==, t_buff);
1208 test_gnc_setlocale (LC_TIME,
"en_GB");
1209 memset ((gpointer)buff, 0,
sizeof (buff));
1213 g_assert_cmpstr (buff, ==, t_buff);
1214 memset ((gpointer)buff, 0,
sizeof (buff));
1218 g_assert_cmpstr (buff, ==, t_buff);
1219 memset ((gpointer)buff, 0,
sizeof (buff));
1223 g_assert_cmpstr (buff, ==, t_buff);
1226 test_gnc_setlocale (LC_TIME,
"fr_FR");
1227 memset ((gpointer)buff, 0,
sizeof (buff));
1231 g_assert_cmpstr (buff, ==, t_buff);
1232 memset ((gpointer)buff, 0,
sizeof (buff));
1236 g_assert_cmpstr (buff, ==, t_buff);
1237 memset ((gpointer)buff, 0,
sizeof (buff));
1241 g_assert_cmpstr (buff, ==, t_buff);
1243 setlocale (LC_TIME, locale);
1250 #define test_assert_qof_print_date(time, datestr) \
1252 gchar *buf = qof_print_date (time); \
1253 g_assert_cmpstr (buf, ==, datestr); \
1257 #define test_assert_qof_print_date_outside_range(time, datestr) \
1259 gchar *buf = qof_print_date (time); \
1260 g_assert_cmpstr (buf, ==, datestr); \
1264 #define test_assert_localized_qof_print_date(time) \
1266 gchar *buf = qof_print_date (time); \
1267 test_assert_localized_timestring (time, buf); \
1276 test_qof_print_date (
void)
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);
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);
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");
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");
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");
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");
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));
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));
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));
1332 setlocale (LC_TIME, locale);
1334 g_date_time_unref (gd1);
1335 g_date_time_unref (gd2);
1336 g_date_time_unref (gd3);
1343 test_gnc_print_date (
void)
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);
1376 test_gnc_setlocale (LC_TIME,
"en_US");
1384 test_gnc_setlocale (LC_TIME,
"en_GB");
1392 test_gnc_setlocale (LC_TIME,
"fr_FR");
1400 setlocale (LC_TIME, locale);
1427 test_qof_scan_date (
void)
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
1440 g_date_time_unref (gdt);
1443 g_assert_cmpint (day, ==, 0);
1444 g_assert_cmpint (mo, ==, 0);
1445 g_assert_cmpint (yr, ==, 0);
1449 g_assert_cmpint (day, ==, 23);
1450 g_assert_cmpint (mo, ==, 11);
1451 g_assert_cmpint (yr, ==, 1974);
1454 g_assert_cmpint (day, ==, 2);
1455 g_assert_cmpint (mo, ==, 2);
1456 g_assert_cmpint (yr, ==, 1961);
1459 g_assert_cmpint (day, ==, 16);
1460 g_assert_cmpint (mo, ==, 6);
1461 g_assert_cmpint (yr, ==, 2045);
1465 g_assert_cmpint (day, ==, 23);
1466 g_assert_cmpint (mo, ==, 11);
1467 g_assert_cmpint (yr, ==, 1974);
1470 g_assert_cmpint (day, ==, 2);
1471 g_assert_cmpint (mo, ==, 2);
1472 g_assert_cmpint (yr, ==, 1961);
1475 g_assert_cmpint (day, ==, 16);
1476 g_assert_cmpint (mo, ==, 6);
1477 g_assert_cmpint (yr, ==, 2045);
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);
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);
1492 g_assert_cmpint (day, ==, 23);
1493 g_assert_cmpint (mo, ==, 11);
1494 g_assert_cmpint (yr, ==, year);
1497 g_assert_cmpint (day, ==, 23);
1498 g_assert_cmpint (mo, ==, 11);
1499 g_assert_cmpint (yr, ==, year);
1506 g_assert_cmpint (day, ==, 23);
1507 g_assert_cmpint (mo, ==, 12);
1508 g_assert_cmpint (yr, ==, year - 1);
1515 g_assert_cmpint (day, ==, 23);
1516 g_assert_cmpint (mo, ==, 11);
1517 g_assert_cmpint (yr, ==, 1974);
1520 g_assert_cmpint (day, ==, 2);
1521 g_assert_cmpint (mo, ==, 2);
1522 g_assert_cmpint (yr, ==, 1961);
1525 g_assert_cmpint (day, ==, 16);
1526 g_assert_cmpint (mo, ==, 6);
1527 g_assert_cmpint (yr, ==, 2045);
1530 test_gnc_setlocale (LC_TIME,
"en_GB");
1531 tm_set_dmy (&tm, 1974, 11, 23);
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);
1538 tm_set_dmy (&tm, 1961,2, 2);
1541 g_assert_cmpint (day, ==, tm.tm_mday);
1542 g_assert_cmpint (mo, ==, tm.tm_mon + 1);
1546 g_assert_cmpint (yr % 100, ==, tm.tm_year % 100);
1548 tm_set_dmy (&tm, 2045, 6, 16);
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);
1555 setlocale (LC_TIME, locale);
1604 test_gnc_date_timestamp (
void)
1606 GDateTime *gdt = gncdt.new_now_local ();
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);
1618 g_date_time_unref (gdt);
1626 get_nanoseconds (GDateTime *gdt)
1628 return g_date_time_get_microsecond (gdt) * 1000;
1632 test_gnc_iso8601_to_timespec_gmt (
void)
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);
1646 g_assert_cmpint (t.tv_sec, ==, 0);
1647 g_assert_cmpint (t.tv_nsec, ==, 0);
1650 g_assert_cmpint (t.tv_sec, ==, 0);
1651 g_assert_cmpint (t.tv_nsec, ==, 0);
1654 g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt1));
1657 g_assert_cmpint (t.tv_nsec - 2000, <=, get_nanoseconds (gdt1));
1658 g_assert_cmpint (t.tv_nsec + 2000, >=, get_nanoseconds (gdt1));
1660 g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt1));
1663 g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt2));
1664 g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt2));
1667 g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt3));
1668 g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt3));
1671 g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt4));
1672 g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt4));
1675 g_assert_cmpint (t.tv_sec, ==, g_date_time_to_unix (gdt5));
1676 g_assert_cmpint (t.tv_nsec, ==, get_nanoseconds (gdt5));
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);
1691 #define ISO8601_SIZE MAX_DATE_LENGTH + 4
1693 g_date_time_to_timespec (GDateTime *gdt)
1696 t.tv_sec = g_date_time_to_unix (gdt);
1697 t.tv_nsec = g_date_time_get_microsecond (gdt) * 1000;
1702 format_timestring (GDateTime *gdt)
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;
1710 gchar *tz = g_date_time_format (ngdt,
"%Z");
1712 gchar *tz = g_date_time_format (ngdt,
"%z");
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);
1726 test_gnc_timespec_to_iso8601_buff (
void)
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);
1738 gchar buff[ISO8601_SIZE];
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 *)"
1747 #define _func "char* gnc_timespec_to_iso8601_buff(Timespec, char*)"
1750 gchar *msg = _func
": assertion " _Q
"buff != NULL' failed";
1753 GLogFunc oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler,
1755 g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
1757 memset (buff, 0,
sizeof buff);
1760 g_assert (end == NULL);
1761 g_assert_cmpint (check.hits, ==, 1);
1763 g_log_set_default_handler (oldlogger, NULL);
1766 g_assert_cmpint (end - buff, ==, strlen (buff));
1767 time_str = format_timestring (gdt0);
1768 g_assert_cmpstr (buff, ==, time_str);
1771 t = g_date_time_to_timespec (gdt1);
1773 time_str = format_timestring (gdt1);
1774 g_assert_cmpstr (buff, ==, time_str);
1778 t = g_date_time_to_timespec (gdt2);
1780 time_str = format_timestring (gdt2);
1781 g_assert_cmpstr (buff, ==, time_str);
1784 t = g_date_time_to_timespec (gdt3);
1786 time_str = format_timestring (gdt3);
1787 g_assert_cmpstr (buff, ==, time_str);
1790 t = g_date_time_to_timespec (gdt4);
1792 time_str = format_timestring (gdt4);
1793 g_assert_cmpstr (buff, ==, time_str);
1796 t = g_date_time_to_timespec (gdt5);
1798 time_str = format_timestring (gdt5);
1799 g_assert_cmpstr (buff, ==, time_str);
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);
1817 test_gnc_timespec2dmy (
void)
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;
1830 int day, r_day, mo, r_mo, yr, r_yr;
1833 t = g_date_time_to_timespec (gdt0);
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);
1842 t = g_date_time_to_timespec (gdt1);
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);
1851 t = g_date_time_to_timespec (gdt2);
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);
1860 t = g_date_time_to_timespec (gdt3);
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);
1869 t = g_date_time_to_timespec (gdt4);
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);
1878 t = g_date_time_to_timespec (gdt5);
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);
1884 g_assert_cmpint (r_day, ==, day);
1885 g_assert_cmpint (r_mo, ==, mo);
1886 g_assert_cmpint (r_yr, ==, yr);
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);
1911 test_gnc_dmy2timespec (
void)
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);
1921 t = g_date_time_to_timespec (gdt1);
1922 g_date_time_get_ymd (gdt1, &yr, &mon, &day);
1924 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1925 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1927 t = g_date_time_to_timespec (gdt2);
1928 g_date_time_get_ymd (gdt2, &yr, &mon, &day);
1930 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1931 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1933 t = g_date_time_to_timespec (gdt3);
1934 g_date_time_get_ymd (gdt3, &yr, &mon, &day);
1936 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1937 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1939 t = g_date_time_to_timespec (gdt4);
1940 g_date_time_get_ymd (gdt4, &yr, &mon, &day);
1942 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1943 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1945 g_date_time_unref (gdt1);
1946 g_date_time_unref (gdt2);
1947 g_date_time_unref (gdt3);
1948 g_date_time_unref (gdt4);
1955 test_gnc_dmy2timespec_end (
void)
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);
1965 t = g_date_time_to_timespec (gdt1);
1966 g_date_time_get_ymd (gdt1, &yr, &mon, &day);
1968 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1969 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1971 t = g_date_time_to_timespec (gdt2);
1972 g_date_time_get_ymd (gdt2, &yr, &mon, &day);
1974 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1975 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1977 t = g_date_time_to_timespec (gdt3);
1978 g_date_time_get_ymd (gdt3, &yr, &mon, &day);
1980 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1981 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1983 t = g_date_time_to_timespec (gdt4);
1984 g_date_time_get_ymd (gdt4, &yr, &mon, &day);
1986 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
1987 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
1989 g_date_time_unref (gdt1);
1990 g_date_time_unref (gdt2);
1991 g_date_time_unref (gdt3);
1992 g_date_time_unref (gdt4);
2030 test_timespec_to_gdate (
void)
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;
2047 g_date_clear (&date2, 1);
2049 t = g_date_time_to_timespec (gdt0);
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));
2057 t = g_date_time_to_timespec (gdt1);
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));
2065 t = g_date_time_to_timespec (gdt2);
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));
2073 t = g_date_time_to_timespec (gdt3);
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);
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));
2088 t = g_date_time_to_timespec (gdt5);
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));
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);
2111 test_gdate_to_timespec (
void)
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);
2122 g_date_clear (&gd, 1);
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);
2128 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2129 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
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);
2135 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2136 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
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);
2142 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2143 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
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);
2149 g_assert_cmpint (r_t.tv_sec, ==, t.tv_sec);
2150 g_assert_cmpint (r_t.tv_nsec, ==, t.tv_nsec);
2152 g_date_time_unref (gdt1);
2153 g_date_time_unref (gdt2);
2154 g_date_time_unref (gdt3);
2155 g_date_time_unref (gdt4);
2178 test_gnc_time64_get_day_start (
void)
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;
2192 time64 time, t_time, r_time;
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);
2201 g_assert_cmpint (t_time, ==, r_time);
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);
2209 g_assert_cmpint (t_time, ==, r_time);
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);
2217 g_assert_cmpint (t_time, ==, r_time);
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);
2225 g_assert_cmpint (t_time, ==, r_time);
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);
2233 g_assert_cmpint (t_time, ==, r_time);
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);
2241 g_assert_cmpint (t_time, ==, r_time);
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);
2258 test_gnc_time64_get_day_end (
void)
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;
2272 time64 time, t_time, r_time;
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);
2280 g_assert_cmpint (t_time, ==, r_time);
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);
2288 g_assert_cmpint (t_time, ==, r_time);
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);
2296 g_assert_cmpint (t_time, ==, r_time);
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);
2304 g_assert_cmpint (t_time, ==, r_time);
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);
2312 g_assert_cmpint (t_time, ==, r_time);
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);
2320 g_assert_cmpint (t_time, ==, r_time);
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);
2393 test_suite_gnc_date (
void)
2395 _gnc_date_time_init (&gncdt);
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);
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);
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);
2425 GNC_TEST_ADD_FUNC (suitename,
"qof scan date", test_qof_scan_date);
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);
2436 GNC_TEST_ADD_FUNC (suitename,
"gnc dmy2timespec", test_gnc_dmy2timespec);
2437 GNC_TEST_ADD_FUNC (suitename,
"gnc dmy2timespec end", test_gnc_dmy2timespec_end);
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);
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);
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.
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)
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
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.
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.