3 * Copyright (C) 2009-2010 Christian Hergert <chris@dronelabs.com>
5 * This is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, see <http://www.gnu.org/licenses/>.
24 #include <glib/gstdio.h>
27 #define ASSERT_DATE(dt,y,m,d) G_STMT_START { \
28 g_assert_cmpint ((y), ==, g_date_time_get_year ((dt))); \
29 g_assert_cmpint ((m), ==, g_date_time_get_month ((dt))); \
30 g_assert_cmpint ((d), ==, g_date_time_get_day_of_month ((dt))); \
32 #define ASSERT_TIME(dt,H,M,S) G_STMT_START { \
33 g_assert_cmpint ((H), ==, g_date_time_get_hour ((dt))); \
34 g_assert_cmpint ((M), ==, g_date_time_get_minute ((dt))); \
35 g_assert_cmpint ((S), ==, g_date_time_get_second ((dt))); \
39 get_localtime_tm (time_t time_,
42 #ifdef HAVE_LOCALTIME_R
43 localtime_r (&time_, retval);
46 struct tm *ptm = localtime (&time_);
50 /* Happens at least in Microsoft's C library if you pass a
51 * negative time_t. Use 2000-01-01 as default date.
53 #ifndef G_DISABLE_CHECKS
54 g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, "ptm != NULL");
59 retval->tm_year = 100;
62 memcpy ((void *) retval, (void *) ptm, sizeof (struct tm));
64 #endif /* HAVE_LOCALTIME_R */
68 test_GDateTime_now (void)
75 /* before <= dt.to_unix() <= after, but the inequalities might not be
76 * equality if we're close to the boundary between seconds.
77 * We loop until before == after (and hence dt.to_unix() should equal both)
78 * to guard against that. */
81 before = g_get_real_time () / G_TIME_SPAN_SECOND;
83 memset (&tm, 0, sizeof (tm));
84 get_localtime_tm (before, &tm);
86 dt = g_date_time_new_now_local ();
88 after = g_get_real_time () / G_TIME_SPAN_SECOND;
90 while (before != after);
92 g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
93 g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
94 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
95 g_assert_cmpint (g_date_time_get_hour (dt), ==, tm.tm_hour);
96 g_assert_cmpint (g_date_time_get_minute (dt), ==, tm.tm_min);
97 g_assert_cmpint (g_date_time_get_second (dt), ==, tm.tm_sec);
99 g_date_time_unref (dt);
103 test_GDateTime_new_from_unix (void)
109 memset (&tm, 0, sizeof (tm));
111 get_localtime_tm (t, &tm);
113 dt = g_date_time_new_from_unix_local (t);
114 g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
115 g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
116 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
117 g_assert_cmpint (g_date_time_get_hour (dt), ==, tm.tm_hour);
118 g_assert_cmpint (g_date_time_get_minute (dt), ==, tm.tm_min);
119 g_assert_cmpint (g_date_time_get_second (dt), ==, tm.tm_sec);
120 g_date_time_unref (dt);
122 memset (&tm, 0, sizeof (tm));
132 dt = g_date_time_new_from_unix_local (t);
133 g_assert_cmpint (g_date_time_get_year (dt), ==, 1990);
134 g_assert_cmpint (g_date_time_get_month (dt), ==, 1);
135 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 1);
136 g_assert_cmpint (g_date_time_get_hour (dt), ==, 0);
137 g_assert_cmpint (g_date_time_get_minute (dt), ==, 0);
138 g_assert_cmpint (g_date_time_get_second (dt), ==, 0);
139 g_date_time_unref (dt);
142 /* Check that trying to create a #GDateTime too far in the future reliably
143 * fails. Previously, the checks for this overflowed and it silently returned
144 * an incorrect #GDateTime. */
146 test_GDateTime_new_from_unix_overflow (void)
150 g_test_bug ("782089");
152 dt = g_date_time_new_from_unix_utc (G_MAXINT64);
155 dt = g_date_time_new_from_unix_local (G_MAXINT64);
160 test_GDateTime_invalid (void)
164 g_test_bug ("702674");
166 dt = g_date_time_new_utc (2013, -2147483647, 31, 17, 15, 48);
167 g_assert (dt == NULL);
171 test_GDateTime_compare (void)
173 GDateTime *dt1, *dt2;
176 dt1 = g_date_time_new_utc (2000, 1, 1, 0, 0, 0);
178 for (i = 1; i < 2000; i++)
180 dt2 = g_date_time_new_utc (i, 12, 31, 0, 0, 0);
181 g_assert_cmpint (1, ==, g_date_time_compare (dt1, dt2));
182 g_date_time_unref (dt2);
185 dt2 = g_date_time_new_utc (1999, 12, 31, 23, 59, 59);
186 g_assert_cmpint (1, ==, g_date_time_compare (dt1, dt2));
187 g_date_time_unref (dt2);
189 dt2 = g_date_time_new_utc (2000, 1, 1, 0, 0, 1);
190 g_assert_cmpint (-1, ==, g_date_time_compare (dt1, dt2));
191 g_date_time_unref (dt2);
193 dt2 = g_date_time_new_utc (2000, 1, 1, 0, 0, 0);
194 g_assert_cmpint (0, ==, g_date_time_compare (dt1, dt2));
195 g_date_time_unref (dt2);
196 g_date_time_unref (dt1);
200 test_GDateTime_equal (void)
202 GDateTime *dt1, *dt2;
205 dt1 = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
206 dt2 = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
207 g_assert (g_date_time_equal (dt1, dt2));
208 g_date_time_unref (dt1);
209 g_date_time_unref (dt2);
211 dt1 = g_date_time_new_local (2009, 10, 18, 0, 0, 0);
212 dt2 = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
213 g_assert (!g_date_time_equal (dt1, dt2));
214 g_date_time_unref (dt1);
215 g_date_time_unref (dt2);
217 /* UTC-0300 and not in DST */
218 tz = g_time_zone_new ("-03:00");
219 dt1 = g_date_time_new (tz, 2010, 5, 24, 8, 0, 0);
220 g_time_zone_unref (tz);
221 g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, (-3 * 3600));
223 dt2 = g_date_time_new_utc (2010, 5, 24, 11, 0, 0);
224 g_assert_cmpint (g_date_time_get_utc_offset (dt2), ==, 0);
226 g_assert (g_date_time_equal (dt1, dt2));
227 g_date_time_unref (dt1);
229 /* America/Recife is in UTC-0300 */
231 tz = g_time_zone_new ("America/Recife");
232 #elif defined G_OS_WIN32
233 tz = g_time_zone_new ("E. South America Standard Time");
235 dt1 = g_date_time_new (tz, 2010, 5, 24, 8, 0, 0);
236 g_time_zone_unref (tz);
237 g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, (-3 * 3600));
238 g_assert (g_date_time_equal (dt1, dt2));
239 g_date_time_unref (dt1);
240 g_date_time_unref (dt2);
244 test_GDateTime_get_day_of_week (void)
248 dt = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
249 g_assert_cmpint (1, ==, g_date_time_get_day_of_week (dt));
250 g_date_time_unref (dt);
252 dt = g_date_time_new_local (2000, 10, 1, 0, 0, 0);
253 g_assert_cmpint (7, ==, g_date_time_get_day_of_week (dt));
254 g_date_time_unref (dt);
258 test_GDateTime_get_day_of_month (void)
262 dt = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
263 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 19);
264 g_date_time_unref (dt);
266 dt = g_date_time_new_local (1400, 3, 12, 0, 0, 0);
267 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 12);
268 g_date_time_unref (dt);
270 dt = g_date_time_new_local (1800, 12, 31, 0, 0, 0);
271 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 31);
272 g_date_time_unref (dt);
274 dt = g_date_time_new_local (1000, 1, 1, 0, 0, 0);
275 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 1);
276 g_date_time_unref (dt);
280 test_GDateTime_get_hour (void)
284 dt = g_date_time_new_utc (2009, 10, 19, 15, 13, 11);
285 g_assert_cmpint (15, ==, g_date_time_get_hour (dt));
286 g_date_time_unref (dt);
288 dt = g_date_time_new_utc (100, 10, 19, 1, 0, 0);
289 g_assert_cmpint (1, ==, g_date_time_get_hour (dt));
290 g_date_time_unref (dt);
292 dt = g_date_time_new_utc (100, 10, 19, 0, 0, 0);
293 g_assert_cmpint (0, ==, g_date_time_get_hour (dt));
294 g_date_time_unref (dt);
296 dt = g_date_time_new_utc (100, 10, 1, 23, 59, 59);
297 g_assert_cmpint (23, ==, g_date_time_get_hour (dt));
298 g_date_time_unref (dt);
302 test_GDateTime_get_microsecond (void)
307 g_get_current_time (&tv);
308 dt = g_date_time_new_from_timeval_local (&tv);
309 g_assert_cmpint (tv.tv_usec, ==, g_date_time_get_microsecond (dt));
310 g_date_time_unref (dt);
314 test_GDateTime_get_year (void)
318 dt = g_date_time_new_local (2009, 1, 1, 0, 0, 0);
319 g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
320 g_date_time_unref (dt);
322 dt = g_date_time_new_local (1, 1, 1, 0, 0, 0);
323 g_assert_cmpint (1, ==, g_date_time_get_year (dt));
324 g_date_time_unref (dt);
326 dt = g_date_time_new_local (13, 1, 1, 0, 0, 0);
327 g_assert_cmpint (13, ==, g_date_time_get_year (dt));
328 g_date_time_unref (dt);
330 dt = g_date_time_new_local (3000, 1, 1, 0, 0, 0);
331 g_assert_cmpint (3000, ==, g_date_time_get_year (dt));
332 g_date_time_unref (dt);
336 test_GDateTime_hash (void)
340 h = g_hash_table_new_full (g_date_time_hash, g_date_time_equal,
341 (GDestroyNotify)g_date_time_unref,
343 g_hash_table_insert (h, g_date_time_new_now_local (), NULL);
344 g_hash_table_remove_all (h);
345 g_hash_table_destroy (h);
349 test_GDateTime_new_from_timeval (void)
354 g_get_current_time (&tv);
355 dt = g_date_time_new_from_timeval_local (&tv);
357 if (g_test_verbose ())
358 g_printerr ("\nDT%04d-%02d-%02dT%02d:%02d:%02d%s\n",
359 g_date_time_get_year (dt),
360 g_date_time_get_month (dt),
361 g_date_time_get_day_of_month (dt),
362 g_date_time_get_hour (dt),
363 g_date_time_get_minute (dt),
364 g_date_time_get_second (dt),
365 g_date_time_get_timezone_abbreviation (dt));
367 g_date_time_to_timeval (dt, &tv2);
368 g_assert_cmpint (tv.tv_sec, ==, tv2.tv_sec);
369 g_assert_cmpint (tv.tv_usec, ==, tv2.tv_usec);
370 g_date_time_unref (dt);
374 find_maximum_supported_tv_sec (void)
376 glong highest_success = 0, lowest_failure = G_MAXLONG;
378 GDateTime *dt = NULL;
382 /* Corner case of all glong values being valid. */
383 tv.tv_sec = G_MAXLONG;
384 dt = g_date_time_new_from_timeval_utc (&tv);
387 highest_success = tv.tv_sec;
388 g_date_time_unref (dt);
391 while (highest_success < lowest_failure - 1)
393 tv.tv_sec = highest_success + (lowest_failure - highest_success) / 2;
394 dt = g_date_time_new_from_timeval_utc (&tv);
398 highest_success = tv.tv_sec;
399 g_date_time_unref (dt);
403 lowest_failure = tv.tv_sec;
407 return highest_success;
410 /* Check that trying to create a #GDateTime too far in the future reliably
411 * fails. With a #GTimeVal, this is subtle, as the tv_usec are added into the
412 * calculation part-way through.
414 * This varies a bit between 32- and 64-bit architectures, due to the
415 * differences in the size of glong (tv.tv_sec). */
417 test_GDateTime_new_from_timeval_overflow (void)
422 g_test_bug ("782089");
424 tv.tv_sec = find_maximum_supported_tv_sec ();
425 tv.tv_usec = G_USEC_PER_SEC - 1;
427 g_test_message ("Maximum supported GTimeVal.tv_sec = %lu", tv.tv_sec);
429 /* Sanity check: do we support the year 2000? */
430 g_assert_cmpint (tv.tv_sec, >=, 946684800);
432 dt = g_date_time_new_from_timeval_utc (&tv);
433 g_assert_nonnull (dt);
434 g_date_time_unref (dt);
436 if (tv.tv_sec < G_MAXLONG)
441 dt = g_date_time_new_from_timeval_utc (&tv);
447 test_GDateTime_new_from_timeval_utc (void)
452 g_get_current_time (&tv);
453 dt = g_date_time_new_from_timeval_utc (&tv);
455 if (g_test_verbose ())
456 g_printerr ("\nDT%04d-%02d-%02dT%02d:%02d:%02d%s\n",
457 g_date_time_get_year (dt),
458 g_date_time_get_month (dt),
459 g_date_time_get_day_of_month (dt),
460 g_date_time_get_hour (dt),
461 g_date_time_get_minute (dt),
462 g_date_time_get_second (dt),
463 g_date_time_get_timezone_abbreviation (dt));
465 g_date_time_to_timeval (dt, &tv2);
466 g_assert_cmpint (tv.tv_sec, ==, tv2.tv_sec);
467 g_assert_cmpint (tv.tv_usec, ==, tv2.tv_usec);
468 g_date_time_unref (dt);
472 test_GDateTime_to_unix (void)
478 dt = g_date_time_new_from_unix_local (t);
479 g_assert_cmpint (g_date_time_to_unix (dt), ==, t);
480 g_date_time_unref (dt);
484 test_GDateTime_add_years (void)
488 dt = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
489 dt2 = g_date_time_add_years (dt, 1);
490 g_assert_cmpint (2010, ==, g_date_time_get_year (dt2));
491 g_date_time_unref (dt);
492 g_date_time_unref (dt2);
496 test_GDateTime_add_months (void)
498 #define TEST_ADD_MONTHS(y,m,d,a,ny,nm,nd) G_STMT_START { \
499 GDateTime *dt, *dt2; \
500 dt = g_date_time_new_utc (y, m, d, 0, 0, 0); \
501 dt2 = g_date_time_add_months (dt, a); \
502 ASSERT_DATE (dt2, ny, nm, nd); \
503 g_date_time_unref (dt); \
504 g_date_time_unref (dt2); \
507 TEST_ADD_MONTHS (2009, 12, 31, 1, 2010, 1, 31);
508 TEST_ADD_MONTHS (2009, 12, 31, 1, 2010, 1, 31);
509 TEST_ADD_MONTHS (2009, 6, 15, 1, 2009, 7, 15);
510 TEST_ADD_MONTHS (1400, 3, 1, 1, 1400, 4, 1);
511 TEST_ADD_MONTHS (1400, 1, 31, 1, 1400, 2, 28);
512 TEST_ADD_MONTHS (1400, 1, 31, 7200, 2000, 1, 31);
513 TEST_ADD_MONTHS (2008, 2, 29, 12, 2009, 2, 28);
514 TEST_ADD_MONTHS (2000, 8, 16, -5, 2000, 3, 16);
515 TEST_ADD_MONTHS (2000, 8, 16, -12, 1999, 8, 16);
516 TEST_ADD_MONTHS (2011, 2, 1, -13, 2010, 1, 1);
517 TEST_ADD_MONTHS (1776, 7, 4, 1200, 1876, 7, 4);
521 test_GDateTime_add_days (void)
523 #define TEST_ADD_DAYS(y,m,d,a,ny,nm,nd) G_STMT_START { \
524 GDateTime *dt, *dt2; \
525 dt = g_date_time_new_local (y, m, d, 0, 0, 0); \
526 dt2 = g_date_time_add_days (dt, a); \
527 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
528 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
529 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
530 g_date_time_unref (dt); \
531 g_date_time_unref (dt2); \
534 TEST_ADD_DAYS (2009, 1, 31, 1, 2009, 2, 1);
535 TEST_ADD_DAYS (2009, 2, 1, -1, 2009, 1, 31);
536 TEST_ADD_DAYS (2008, 2, 28, 1, 2008, 2, 29);
537 TEST_ADD_DAYS (2008, 12, 31, 1, 2009, 1, 1);
538 TEST_ADD_DAYS (1, 1, 1, 1, 1, 1, 2);
539 TEST_ADD_DAYS (1955, 5, 24, 10, 1955, 6, 3);
540 TEST_ADD_DAYS (1955, 5, 24, -10, 1955, 5, 14);
544 test_GDateTime_add_weeks (void)
546 #define TEST_ADD_WEEKS(y,m,d,a,ny,nm,nd) G_STMT_START { \
547 GDateTime *dt, *dt2; \
548 dt = g_date_time_new_local (y, m, d, 0, 0, 0); \
549 dt2 = g_date_time_add_weeks (dt, a); \
550 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
551 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
552 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
553 g_date_time_unref (dt); \
554 g_date_time_unref (dt2); \
557 TEST_ADD_WEEKS (2009, 1, 1, 1, 2009, 1, 8);
558 TEST_ADD_WEEKS (2009, 8, 30, 1, 2009, 9, 6);
559 TEST_ADD_WEEKS (2009, 12, 31, 1, 2010, 1, 7);
560 TEST_ADD_WEEKS (2009, 1, 1, -1, 2008, 12, 25);
564 test_GDateTime_add_hours (void)
566 #define TEST_ADD_HOURS(y,m,d,h,mi,s,a,ny,nm,nd,nh,nmi,ns) G_STMT_START { \
567 GDateTime *dt, *dt2; \
568 dt = g_date_time_new_utc (y, m, d, h, mi, s); \
569 dt2 = g_date_time_add_hours (dt, a); \
570 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
571 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
572 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
573 g_assert_cmpint (nh, ==, g_date_time_get_hour (dt2)); \
574 g_assert_cmpint (nmi, ==, g_date_time_get_minute (dt2)); \
575 g_assert_cmpint (ns, ==, g_date_time_get_second (dt2)); \
576 g_date_time_unref (dt); \
577 g_date_time_unref (dt2); \
580 TEST_ADD_HOURS (2009, 1, 1, 0, 0, 0, 1, 2009, 1, 1, 1, 0, 0);
581 TEST_ADD_HOURS (2008, 12, 31, 23, 0, 0, 1, 2009, 1, 1, 0, 0, 0);
585 test_GDateTime_add_full (void)
587 #define TEST_ADD_FULL(y,m,d,h,mi,s,ay,am,ad,ah,ami,as,ny,nm,nd,nh,nmi,ns) G_STMT_START { \
588 GDateTime *dt, *dt2; \
589 dt = g_date_time_new_utc (y, m, d, h, mi, s); \
590 dt2 = g_date_time_add_full (dt, ay, am, ad, ah, ami, as); \
591 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
592 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
593 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
594 g_assert_cmpint (nh, ==, g_date_time_get_hour (dt2)); \
595 g_assert_cmpint (nmi, ==, g_date_time_get_minute (dt2)); \
596 g_assert_cmpint (ns, ==, g_date_time_get_second (dt2)); \
597 g_date_time_unref (dt); \
598 g_date_time_unref (dt2); \
601 TEST_ADD_FULL (2009, 10, 21, 0, 0, 0,
603 2010, 11, 22, 1, 1, 1);
604 TEST_ADD_FULL (2000, 1, 1, 1, 1, 1,
606 2000, 2, 1, 1, 1, 1);
607 TEST_ADD_FULL (2000, 1, 1, 0, 0, 0,
609 1999, 2, 1, 0, 0, 0);
610 TEST_ADD_FULL (2010, 10, 31, 0, 0, 0,
612 2011, 2, 28, 0, 0, 0);
613 TEST_ADD_FULL (2010, 8, 25, 22, 45, 0,
615 2010, 10, 2, 0, 10, 0);
619 test_GDateTime_add_minutes (void)
621 #define TEST_ADD_MINUTES(i,o) G_STMT_START { \
622 GDateTime *dt, *dt2; \
623 dt = g_date_time_new_local (2000, 1, 1, 0, 0, 0); \
624 dt2 = g_date_time_add_minutes (dt, i); \
625 g_assert_cmpint (o, ==, g_date_time_get_minute (dt2)); \
626 g_date_time_unref (dt); \
627 g_date_time_unref (dt2); \
630 TEST_ADD_MINUTES (60, 0);
631 TEST_ADD_MINUTES (100, 40);
632 TEST_ADD_MINUTES (5, 5);
633 TEST_ADD_MINUTES (1441, 1);
634 TEST_ADD_MINUTES (-1441, 59);
638 test_GDateTime_add_seconds (void)
640 #define TEST_ADD_SECONDS(i,o) G_STMT_START { \
641 GDateTime *dt, *dt2; \
642 dt = g_date_time_new_local (2000, 1, 1, 0, 0, 0); \
643 dt2 = g_date_time_add_seconds (dt, i); \
644 g_assert_cmpint (o, ==, g_date_time_get_second (dt2)); \
645 g_date_time_unref (dt); \
646 g_date_time_unref (dt2); \
649 TEST_ADD_SECONDS (1, 1);
650 TEST_ADD_SECONDS (60, 0);
651 TEST_ADD_SECONDS (61, 1);
652 TEST_ADD_SECONDS (120, 0);
653 TEST_ADD_SECONDS (-61, 59);
654 TEST_ADD_SECONDS (86401, 1);
655 TEST_ADD_SECONDS (-86401, 59);
656 TEST_ADD_SECONDS (-31, 29);
657 TEST_ADD_SECONDS (13, 13);
661 test_GDateTime_diff (void)
663 #define TEST_DIFF(y,m,d,y2,m2,d2,u) G_STMT_START { \
664 GDateTime *dt1, *dt2; \
666 dt1 = g_date_time_new_utc (y, m, d, 0, 0, 0); \
667 dt2 = g_date_time_new_utc (y2, m2, d2, 0, 0, 0); \
668 ts = g_date_time_difference (dt2, dt1); \
669 g_assert_cmpint (ts, ==, u); \
670 g_date_time_unref (dt1); \
671 g_date_time_unref (dt2); \
674 TEST_DIFF (2009, 1, 1, 2009, 2, 1, G_TIME_SPAN_DAY * 31);
675 TEST_DIFF (2009, 1, 1, 2010, 1, 1, G_TIME_SPAN_DAY * 365);
676 TEST_DIFF (2008, 2, 28, 2008, 2, 29, G_TIME_SPAN_DAY);
677 TEST_DIFF (2008, 2, 29, 2008, 2, 28, -G_TIME_SPAN_DAY);
679 /* TODO: Add usec tests */
683 test_GDateTime_get_minute (void)
687 dt = g_date_time_new_utc (2009, 12, 1, 1, 31, 0);
688 g_assert_cmpint (31, ==, g_date_time_get_minute (dt));
689 g_date_time_unref (dt);
693 test_GDateTime_get_month (void)
697 dt = g_date_time_new_utc (2009, 12, 1, 1, 31, 0);
698 g_assert_cmpint (12, ==, g_date_time_get_month (dt));
699 g_date_time_unref (dt);
703 test_GDateTime_get_second (void)
707 dt = g_date_time_new_utc (2009, 12, 1, 1, 31, 44);
708 g_assert_cmpint (44, ==, g_date_time_get_second (dt));
709 g_date_time_unref (dt);
713 test_GDateTime_new_full (void)
718 dt = g_date_time_new_utc (2009, 12, 11, 12, 11, 10);
719 g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
720 g_assert_cmpint (12, ==, g_date_time_get_month (dt));
721 g_assert_cmpint (11, ==, g_date_time_get_day_of_month (dt));
722 g_assert_cmpint (12, ==, g_date_time_get_hour (dt));
723 g_assert_cmpint (11, ==, g_date_time_get_minute (dt));
724 g_assert_cmpint (10, ==, g_date_time_get_second (dt));
725 g_date_time_unref (dt);
728 tz = g_time_zone_new ("America/Tijuana");
729 #elif defined G_OS_WIN32
730 tz = g_time_zone_new ("Pacific Standard Time");
732 dt = g_date_time_new (tz, 2010, 11, 24, 8, 4, 0);
733 g_time_zone_unref (tz);
734 g_assert_cmpint (2010, ==, g_date_time_get_year (dt));
735 g_assert_cmpint (11, ==, g_date_time_get_month (dt));
736 g_assert_cmpint (24, ==, g_date_time_get_day_of_month (dt));
737 g_assert_cmpint (8, ==, g_date_time_get_hour (dt));
738 g_assert_cmpint (4, ==, g_date_time_get_minute (dt));
739 g_assert_cmpint (0, ==, g_date_time_get_second (dt));
741 g_assert_cmpstr ("PST", ==, g_date_time_get_timezone_abbreviation (dt));
742 #elif defined G_OS_WIN32
743 g_assert_cmpstr ("Pacific Standard Time", ==,
744 g_date_time_get_timezone_abbreviation (dt));
746 g_assert (!g_date_time_is_daylight_savings (dt));
747 g_date_time_unref (dt);
751 test_GDateTime_now_utc (void)
758 /* t <= dt.to_unix() <= after, but the inequalities might not be
759 * equality if we're close to the boundary between seconds.
760 * We loop until t == after (and hence dt.to_unix() should equal both)
761 * to guard against that. */
764 t = g_get_real_time () / G_TIME_SPAN_SECOND;
769 struct tm *tmp = gmtime (&t);
770 /* Assume gmtime() can't fail as we got t from time(NULL). (Note
771 * that on Windows, gmtime() *is* MT-safe, it uses a thread-local
774 memcpy (&tm, tmp, sizeof (struct tm));
777 dt = g_date_time_new_now_utc ();
779 after = g_get_real_time () / G_TIME_SPAN_SECOND;
783 g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
784 g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
785 g_assert_cmpint (tm.tm_mday, ==, g_date_time_get_day_of_month (dt));
786 g_assert_cmpint (tm.tm_hour, ==, g_date_time_get_hour (dt));
787 g_assert_cmpint (tm.tm_min, ==, g_date_time_get_minute (dt));
788 g_assert_cmpint (tm.tm_sec, ==, g_date_time_get_second (dt));
789 g_date_time_unref (dt);
793 test_GDateTime_new_from_unix_utc (void)
798 t = g_get_real_time ();
801 dt = g_date_time_new_from_unix_utc (t);
802 g_assert (dt == NULL);
805 t = t / 1e6; /* oops, this was microseconds */
807 dt = g_date_time_new_from_unix_utc (t);
808 g_assert (dt != NULL);
810 g_assert (dt == g_date_time_ref (dt));
811 g_date_time_unref (dt);
812 g_assert_cmpint (g_date_time_to_unix (dt), ==, t);
813 g_date_time_unref (dt);
817 test_GDateTime_get_utc_offset (void)
819 #if defined (HAVE_STRUCT_TM_TM_GMTOFF) || defined (HAVE_STRUCT_TM___TM_GMTOFF)
824 memset (&tm, 0, sizeof (tm));
825 get_localtime_tm (g_get_real_time () / G_TIME_SPAN_SECOND, &tm);
827 dt = g_date_time_new_now_local ();
828 ts = g_date_time_get_utc_offset (dt);
829 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
830 g_assert_cmpint (ts, ==, (tm.tm_gmtoff * G_TIME_SPAN_SECOND));
832 #ifdef HAVE_STRUCT_TM___TM_GMTOFF
833 g_assert_cmpint (ts, ==, (tm.__tm_gmtoff * G_TIME_SPAN_SECOND));
835 g_date_time_unref (dt);
840 test_GDateTime_to_timeval (void)
845 memset (&tv1, 0, sizeof (tv1));
846 memset (&tv2, 0, sizeof (tv2));
848 g_get_current_time (&tv1);
849 dt = g_date_time_new_from_timeval_local (&tv1);
850 g_date_time_to_timeval (dt, &tv2);
851 g_assert_cmpint (tv1.tv_sec, ==, tv2.tv_sec);
852 g_assert_cmpint (tv1.tv_usec, ==, tv2.tv_usec);
853 g_date_time_unref (dt);
857 test_GDateTime_to_local (void)
859 GDateTime *utc = NULL, *now = NULL, *dt;
860 time_t before, after;
862 /* before <= utc.to_unix() <= now.to_unix() <= after, but the inequalities
863 * might not be equality if we're close to the boundary between seconds.
864 * We loop until before == after (and hence the GDateTimes should match)
865 * to guard against that. */
868 before = g_get_real_time () / G_TIME_SPAN_SECOND;
869 g_clear_pointer (&utc, g_date_time_unref);
870 g_clear_pointer (&now, g_date_time_unref);
871 utc = g_date_time_new_now_utc ();
872 now = g_date_time_new_now_local ();
873 after = g_get_real_time () / G_TIME_SPAN_SECOND;
875 while (before != after);
877 dt = g_date_time_to_local (utc);
879 g_assert_cmpint (g_date_time_get_year (now), ==, g_date_time_get_year (dt));
880 g_assert_cmpint (g_date_time_get_month (now), ==, g_date_time_get_month (dt));
881 g_assert_cmpint (g_date_time_get_day_of_month (now), ==, g_date_time_get_day_of_month (dt));
882 g_assert_cmpint (g_date_time_get_hour (now), ==, g_date_time_get_hour (dt));
883 g_assert_cmpint (g_date_time_get_minute (now), ==, g_date_time_get_minute (dt));
884 g_assert_cmpint (g_date_time_get_second (now), ==, g_date_time_get_second (dt));
886 g_date_time_unref (now);
887 g_date_time_unref (utc);
888 g_date_time_unref (dt);
892 test_GDateTime_to_utc (void)
903 struct tm *tmp = gmtime (&t);
904 memcpy (&tm, tmp, sizeof (struct tm));
907 dt2 = g_date_time_new_from_unix_local (t);
908 dt = g_date_time_to_utc (dt2);
909 g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
910 g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
911 g_assert_cmpint (tm.tm_mday, ==, g_date_time_get_day_of_month (dt));
912 g_assert_cmpint (tm.tm_hour, ==, g_date_time_get_hour (dt));
913 g_assert_cmpint (tm.tm_min, ==, g_date_time_get_minute (dt));
914 g_assert_cmpint (tm.tm_sec, ==, g_date_time_get_second (dt));
915 g_date_time_unref (dt);
916 g_date_time_unref (dt2);
920 test_GDateTime_get_day_of_year (void)
922 #define TEST_DAY_OF_YEAR(y,m,d,o) G_STMT_START { \
923 GDateTime *__dt = g_date_time_new_local ((y), (m), (d), 0, 0, 0); \
924 g_assert_cmpint ((o), ==, g_date_time_get_day_of_year (__dt)); \
925 g_date_time_unref (__dt); } G_STMT_END
927 TEST_DAY_OF_YEAR (2009, 1, 1, 1);
928 TEST_DAY_OF_YEAR (2009, 2, 1, 32);
929 TEST_DAY_OF_YEAR (2009, 8, 16, 228);
930 TEST_DAY_OF_YEAR (2008, 8, 16, 229);
934 test_GDateTime_printf (void)
936 /* 64 seems big, but one zoneinfo file, Factory, has an abbreviation
937 * that long, and it will cause the test to fail if dst isn't big
944 #define TEST_PRINTF(f,o) G_STMT_START { \
945 GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
946 gchar *__p = g_date_time_format (__dt, (f)); \
947 g_assert_cmpstr (__p, ==, (o)); \
948 g_date_time_unref (__dt); \
949 g_free (__p); } G_STMT_END
951 #define TEST_PRINTF_DATE(y,m,d,f,o) G_STMT_START { \
952 GDateTime *dt = g_date_time_new_local (y, m, d, 0, 0, 0); \
953 gchar *p = g_date_time_format (dt, (f)); \
954 g_assert_cmpstr (p, ==, (o)); \
955 g_date_time_unref (dt); \
956 g_free (p); } G_STMT_END
958 #define TEST_PRINTF_TIME(h,m,s,f,o) G_STMT_START { \
959 GDateTime *dt = g_date_time_new_local (2009, 10, 24, (h), (m), (s)); \
960 gchar *p = g_date_time_format (dt, (f)); \
961 g_assert_cmpstr (p, ==, (o)); \
962 g_date_time_unref (dt); \
963 g_free (p); } G_STMT_END
966 * This is a little helper to make sure we can compare timezones to
967 * that of the generated timezone.
970 memset (&tt, 0, sizeof(tt));
971 get_localtime_tm (t, &tt);
972 tt.tm_year = 2009 - 1900;
973 tt.tm_mon = 9; /* 0 indexed */
976 memset (&tt, 0, sizeof(tt));
977 get_localtime_tm (t, &tt);
978 strftime (dst, sizeof(dst), "%Z", &tt);
980 /* get current time_t for 20090924 in the local timezone */
986 TEST_PRINTF ("%a", "Sat");
987 TEST_PRINTF ("%A", "Saturday");
988 TEST_PRINTF ("%b", "Oct");
989 TEST_PRINTF ("%B", "October");
990 TEST_PRINTF ("%d", "24");
991 TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
992 TEST_PRINTF ("%e", "24"); // fixme
993 TEST_PRINTF ("%h", "Oct");
994 TEST_PRINTF ("%H", "00");
995 TEST_PRINTF_TIME (15, 0, 0, "%H", "15");
996 TEST_PRINTF ("%I", "12");
997 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
998 TEST_PRINTF_TIME (15, 0, 0, "%I", "03");
999 TEST_PRINTF ("%j", "297");
1000 TEST_PRINTF ("%k", " 0");
1001 TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
1002 TEST_PRINTF ("%l", "12");
1003 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1004 TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
1005 TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
1006 TEST_PRINTF ("%m", "10");
1007 TEST_PRINTF ("%M", "00");
1008 TEST_PRINTF ("%p", "AM");
1009 TEST_PRINTF_TIME (13, 13, 13, "%p", "PM");
1010 TEST_PRINTF ("%P", "am");
1011 TEST_PRINTF_TIME (13, 13, 13, "%P", "pm");
1012 TEST_PRINTF ("%r", "12:00:00 AM");
1013 TEST_PRINTF_TIME (13, 13, 13, "%r", "01:13:13 PM");
1014 TEST_PRINTF ("%R", "00:00");
1015 TEST_PRINTF_TIME (13, 13, 31, "%R", "13:13");
1016 TEST_PRINTF ("%S", "00");
1017 TEST_PRINTF ("%t", " ");
1018 TEST_PRINTF ("%u", "6");
1019 TEST_PRINTF ("%x", "10/24/09");
1020 TEST_PRINTF ("%X", "00:00:00");
1021 TEST_PRINTF_TIME (13, 14, 15, "%X", "13:14:15");
1022 TEST_PRINTF ("%y", "09");
1023 TEST_PRINTF ("%Y", "2009");
1024 TEST_PRINTF ("%%", "%");
1025 TEST_PRINTF ("%", "");
1026 TEST_PRINTF ("%9", NULL);
1028 TEST_PRINTF ("%Z", dst);
1029 #elif defined G_OS_WIN32
1030 TEST_PRINTF ("%Z", "Pacific Standard Time");
1035 test_non_utf8_printf (void)
1039 oldlocale = g_strdup (setlocale (LC_ALL, NULL));
1040 setlocale (LC_ALL, "ja_JP.eucjp");
1041 if (strstr (setlocale (LC_ALL, NULL), "ja_JP") == NULL)
1043 g_test_message ("locale ja_JP.eucjp not available, skipping non-UTF8 tests");
1047 if (g_get_charset (NULL))
1049 g_test_message ("locale ja_JP.eucjp may be available, but glib seems to think that it's equivalent to UTF-8, skipping non-UTF-8 tests.");
1050 g_test_message ("This is a known issue on Darwin");
1051 setlocale (LC_ALL, oldlocale);
1056 /* These are the outputs that ja_JP.UTF-8 generates; if everything
1057 * is working then ja_JP.eucjp should generate the same.
1059 TEST_PRINTF ("%a", "\345\234\237");
1060 TEST_PRINTF ("%A", "\345\234\237\346\233\234\346\227\245");
1061 #ifndef HAVE_CARBON /* OSX just returns the number */
1062 TEST_PRINTF ("%b", "10\346\234\210");
1064 TEST_PRINTF ("%B", "10\346\234\210");
1065 TEST_PRINTF ("%d", "24");
1066 TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
1067 TEST_PRINTF ("%e", "24"); // fixme
1068 #ifndef HAVE_CARBON /* OSX just returns the number */
1069 TEST_PRINTF ("%h", "10\346\234\210");
1071 TEST_PRINTF ("%H", "00");
1072 TEST_PRINTF_TIME (15, 0, 0, "%H", "15");
1073 TEST_PRINTF ("%I", "12");
1074 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1075 TEST_PRINTF_TIME (15, 0, 0, "%I", "03");
1076 TEST_PRINTF ("%j", "297");
1077 TEST_PRINTF ("%k", " 0");
1078 TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
1079 TEST_PRINTF ("%l", "12");
1080 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1081 TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
1082 TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
1083 TEST_PRINTF ("%m", "10");
1084 TEST_PRINTF ("%M", "00");
1085 #ifndef HAVE_CARBON /* OSX returns latin "AM", not japanese */
1086 TEST_PRINTF ("%p", "\345\215\210\345\211\215");
1087 TEST_PRINTF_TIME (13, 13, 13, "%p", "\345\215\210\345\276\214");
1088 TEST_PRINTF ("%P", "\345\215\210\345\211\215");
1089 TEST_PRINTF_TIME (13, 13, 13, "%P", "\345\215\210\345\276\214");
1090 TEST_PRINTF ("%r", "\345\215\210\345\211\21512\346\231\20200\345\210\20600\347\247\222");
1091 TEST_PRINTF_TIME (13, 13, 13, "%r", "\345\215\210\345\276\21401\346\231\20213\345\210\20613\347\247\222");
1093 TEST_PRINTF ("%R", "00:00");
1094 TEST_PRINTF_TIME (13, 13, 31, "%R", "13:13");
1095 TEST_PRINTF ("%S", "00");
1096 TEST_PRINTF ("%t", " ");
1097 TEST_PRINTF ("%u", "6");
1098 #ifndef HAVE_CARBON /* OSX returns YYYY/MM/DD in ASCII */
1099 TEST_PRINTF ("%x", "2009\345\271\26410\346\234\21024\346\227\245");
1101 TEST_PRINTF ("%X", "00\346\231\20200\345\210\20600\347\247\222");
1102 TEST_PRINTF_TIME (13, 14, 15, "%X", "13\346\231\20214\345\210\20615\347\247\222");
1103 TEST_PRINTF ("%y", "09");
1104 TEST_PRINTF ("%Y", "2009");
1105 TEST_PRINTF ("%%", "%");
1106 TEST_PRINTF ("%", "");
1107 TEST_PRINTF ("%9", NULL);
1109 setlocale (LC_ALL, oldlocale);
1114 test_modifiers (void)
1118 TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
1119 TEST_PRINTF_DATE (2009, 1, 1, "%_d", " 1");
1120 TEST_PRINTF_DATE (2009, 1, 1, "%-d", "1");
1121 TEST_PRINTF_DATE (2009, 1, 1, "%0d", "01");
1122 TEST_PRINTF_DATE (2009, 1, 21, "%d", "21");
1123 TEST_PRINTF_DATE (2009, 1, 21, "%_d", "21");
1124 TEST_PRINTF_DATE (2009, 1, 21, "%-d", "21");
1125 TEST_PRINTF_DATE (2009, 1, 21, "%0d", "21");
1127 TEST_PRINTF_DATE (2009, 1, 1, "%e", " 1");
1128 TEST_PRINTF_DATE (2009, 1, 1, "%_e", " 1");
1129 TEST_PRINTF_DATE (2009, 1, 1, "%-e", "1");
1130 TEST_PRINTF_DATE (2009, 1, 1, "%0e", "01");
1131 TEST_PRINTF_DATE (2009, 1, 21, "%e", "21");
1132 TEST_PRINTF_DATE (2009, 1, 21, "%_e", "21");
1133 TEST_PRINTF_DATE (2009, 1, 21, "%-e", "21");
1134 TEST_PRINTF_DATE (2009, 1, 21, "%0e", "21");
1136 TEST_PRINTF_TIME ( 1, 0, 0, "%H", "01");
1137 TEST_PRINTF_TIME ( 1, 0, 0, "%_H", " 1");
1138 TEST_PRINTF_TIME ( 1, 0, 0, "%-H", "1");
1139 TEST_PRINTF_TIME ( 1, 0, 0, "%0H", "01");
1140 TEST_PRINTF_TIME (21, 0, 0, "%H", "21");
1141 TEST_PRINTF_TIME (21, 0, 0, "%_H", "21");
1142 TEST_PRINTF_TIME (21, 0, 0, "%-H", "21");
1143 TEST_PRINTF_TIME (21, 0, 0, "%0H", "21");
1145 TEST_PRINTF_TIME ( 1, 0, 0, "%I", "01");
1146 TEST_PRINTF_TIME ( 1, 0, 0, "%_I", " 1");
1147 TEST_PRINTF_TIME ( 1, 0, 0, "%-I", "1");
1148 TEST_PRINTF_TIME ( 1, 0, 0, "%0I", "01");
1149 TEST_PRINTF_TIME (23, 0, 0, "%I", "11");
1150 TEST_PRINTF_TIME (23, 0, 0, "%_I", "11");
1151 TEST_PRINTF_TIME (23, 0, 0, "%-I", "11");
1152 TEST_PRINTF_TIME (23, 0, 0, "%0I", "11");
1154 TEST_PRINTF_TIME ( 1, 0, 0, "%k", " 1");
1155 TEST_PRINTF_TIME ( 1, 0, 0, "%_k", " 1");
1156 TEST_PRINTF_TIME ( 1, 0, 0, "%-k", "1");
1157 TEST_PRINTF_TIME ( 1, 0, 0, "%0k", "01");
1159 oldlocale = g_strdup (setlocale (LC_ALL, NULL));
1160 setlocale (LC_ALL, "fa_IR.utf-8");
1161 if (strstr (setlocale (LC_ALL, NULL), "fa_IR") != NULL)
1163 TEST_PRINTF_TIME (23, 0, 0, "%OH", "\333\262\333\263"); /* '23' */
1164 TEST_PRINTF_TIME (23, 0, 0, "%OI", "\333\261\333\261"); /* '11' */
1165 TEST_PRINTF_TIME (23, 0, 0, "%OM", "\333\260\333\260"); /* '00' */
1167 TEST_PRINTF_DATE (2011, 7, 1, "%Om", "\333\260\333\267"); /* '07' */
1168 TEST_PRINTF_DATE (2011, 7, 1, "%0Om", "\333\260\333\267"); /* '07' */
1169 TEST_PRINTF_DATE (2011, 7, 1, "%-Om", "\333\267"); /* '7' */
1170 TEST_PRINTF_DATE (2011, 7, 1, "%_Om", " \333\267"); /* ' 7' */
1173 g_test_message ("locale fa_IR not available, skipping O modifier tests");
1174 setlocale (LC_ALL, oldlocale);
1179 test_GDateTime_dst (void)
1181 GDateTime *dt1, *dt2;
1184 /* this date has the DST state set for Europe/London */
1186 tz = g_time_zone_new ("Europe/London");
1187 #elif defined G_OS_WIN32
1188 tz = g_time_zone_new ("GMT Standard Time");
1190 dt1 = g_date_time_new (tz, 2009, 8, 15, 3, 0, 1);
1191 g_assert (g_date_time_is_daylight_savings (dt1));
1192 g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, 3600);
1193 g_assert_cmpint (g_date_time_get_hour (dt1), ==, 3);
1195 /* add 6 months to clear the DST flag but keep the same time */
1196 dt2 = g_date_time_add_months (dt1, 6);
1197 g_assert (!g_date_time_is_daylight_savings (dt2));
1198 g_assert_cmpint (g_date_time_get_utc_offset (dt2) / G_USEC_PER_SEC, ==, 0);
1199 g_assert_cmpint (g_date_time_get_hour (dt2), ==, 3);
1201 g_date_time_unref (dt2);
1202 g_date_time_unref (dt1);
1204 /* now do the reverse: start with a non-DST state and move to DST */
1205 dt1 = g_date_time_new (tz, 2009, 2, 15, 2, 0, 1);
1206 g_assert (!g_date_time_is_daylight_savings (dt1));
1207 g_assert_cmpint (g_date_time_get_hour (dt1), ==, 2);
1209 dt2 = g_date_time_add_months (dt1, 6);
1210 g_assert (g_date_time_is_daylight_savings (dt2));
1211 g_assert_cmpint (g_date_time_get_hour (dt2), ==, 2);
1213 g_date_time_unref (dt2);
1214 g_date_time_unref (dt1);
1215 g_time_zone_unref (tz);
1218 static inline gboolean
1219 is_leap_year (gint year)
1221 g_assert (1 <= year && year <= 9999);
1223 return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
1227 days_in_month (gint year, gint month)
1229 const gint table[2][13] = {
1230 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
1231 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
1234 g_assert (1 <= month && month <= 12);
1236 return table[is_leap_year (year)][month];
1240 test_all_dates (void)
1242 gint year, month, day;
1243 GTimeZone *timezone;
1250 /* save some time by hanging on to this. */
1251 timezone = g_time_zone_new_utc ();
1253 unix_time = G_GINT64_CONSTANT(-62135596800);
1255 /* 0001-01-01 is 0001-W01-1 */
1261 /* The calendar makes a full cycle every 400 years, so we could
1262 * theoretically just test years 1 through 400. That assumes that our
1263 * software has no bugs, so probably we should just test them all. :)
1265 for (year = 1; year <= 9999; year++)
1269 for (month = 1; month <= 12; month++)
1270 for (day = 1; day <= days_in_month (year, month); day++)
1274 dt = g_date_time_new (timezone, year, month, day, 0, 0, 0);
1277 g_printerr ("%04d-%02d-%02d = %04d-W%02d-%d = %04d-%03d\n",
1279 week_year, week_num, weekday,
1284 if G_UNLIKELY (g_date_time_get_year (dt) != year ||
1285 g_date_time_get_month (dt) != month ||
1286 g_date_time_get_day_of_month (dt) != day)
1287 g_error ("%04d-%02d-%02d comes out as %04d-%02d-%02d",
1289 g_date_time_get_year (dt),
1290 g_date_time_get_month (dt),
1291 g_date_time_get_day_of_month (dt));
1293 if G_UNLIKELY (g_date_time_get_week_numbering_year (dt) != week_year ||
1294 g_date_time_get_week_of_year (dt) != week_num ||
1295 g_date_time_get_day_of_week (dt) != weekday)
1296 g_error ("%04d-%02d-%02d should be %04d-W%02d-%d but "
1297 "comes out as %04d-W%02d-%d", year, month, day,
1298 week_year, week_num, weekday,
1299 g_date_time_get_week_numbering_year (dt),
1300 g_date_time_get_week_of_year (dt),
1301 g_date_time_get_day_of_week (dt));
1303 if G_UNLIKELY (g_date_time_to_unix (dt) != unix_time)
1304 g_error ("%04d-%02d-%02d 00:00:00 UTC should have unix time %"
1305 G_GINT64_FORMAT " but comes out as %"G_GINT64_FORMAT,
1306 year, month, day, unix_time, g_date_time_to_unix (dt));
1308 if G_UNLIKELY (g_date_time_get_day_of_year (dt) != day_of_year)
1309 g_error ("%04d-%02d-%02d should be day of year %d"
1310 " but comes out as %d", year, month, day,
1311 day_of_year, g_date_time_get_day_of_year (dt));
1313 if G_UNLIKELY (g_date_time_get_hour (dt) != 0 ||
1314 g_date_time_get_minute (dt) != 0 ||
1315 g_date_time_get_seconds (dt) != 0)
1316 g_error ("%04d-%02d-%02d 00:00:00 UTC comes out "
1317 "as %02d:%02d:%02.6f", year, month, day,
1318 g_date_time_get_hour (dt),
1319 g_date_time_get_minute (dt),
1320 g_date_time_get_seconds (dt));
1323 /* add 24 hours to unix time */
1324 unix_time += 24 * 60 * 60;
1326 /* move day of year forward */
1329 /* move the week date forward */
1332 weekday = 1; /* Sunday -> Monday */
1334 /* NOTE: year/month/day is the final day of the week we
1337 * If we just finished the last week of last year then
1338 * we are definitely starting the first week of this
1341 * Otherwise, if we're still in this year, but Sunday
1342 * fell on or after December 28 then December 29, 30, 31
1343 * could be days within the next year's first year.
1345 if (year != week_year || (month == 12 && day >= 28))
1347 /* first week of the new year */
1355 g_date_time_unref (dt);
1359 g_time_zone_unref (timezone);
1369 g_test_bug ("642935");
1371 tz = g_time_zone_new ("-08:00");
1372 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
1374 p = g_date_time_format (dt, "%z");
1375 g_assert_cmpstr (p, ==, "-0800");
1378 p = g_date_time_format (dt, "%:z");
1379 g_assert_cmpstr (p, ==, "-08:00");
1382 p = g_date_time_format (dt, "%::z");
1383 g_assert_cmpstr (p, ==, "-08:00:00");
1386 p = g_date_time_format (dt, "%:::z");
1387 g_assert_cmpstr (p, ==, "-08");
1390 g_date_time_unref (dt);
1391 g_time_zone_unref (tz);
1393 tz = g_time_zone_new ("+00:00");
1394 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
1395 p = g_date_time_format (dt, "%:::z");
1396 g_assert_cmpstr (p, ==, "+00");
1398 g_date_time_unref (dt);
1399 g_time_zone_unref (tz);
1401 tz = g_time_zone_new ("+08:23");
1402 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
1403 p = g_date_time_format (dt, "%:::z");
1404 g_assert_cmpstr (p, ==, "+08:23");
1406 g_date_time_unref (dt);
1407 g_time_zone_unref (tz);
1409 tz = g_time_zone_new ("+08:23:45");
1410 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
1411 p = g_date_time_format (dt, "%:::z");
1412 g_assert_cmpstr (p, ==, "+08:23:45");
1414 g_date_time_unref (dt);
1415 g_time_zone_unref (tz);
1418 #pragma GCC diagnostic push
1419 #pragma GCC diagnostic ignored "-Wformat-y2k"
1421 test_strftime (void)
1424 #define TEST_FORMAT \
1425 "a%a A%A b%b B%B c%c C%C d%d e%e F%F g%g G%G h%h H%H I%I j%j m%m M%M " \
1426 "n%n p%p r%r R%R S%S t%t T%T u%u V%V w%w x%x X%X y%y Y%Y z%z Z%Z %%"
1429 /* 127997 is prime, 1315005118 is now */
1430 for (t = 0; t < 1315005118; t += 127997)
1432 GDateTime *date_time;
1436 date_time = g_date_time_new_from_unix_local (t);
1437 dt_str = g_date_time_format (date_time, TEST_FORMAT);
1438 strftime (c_str, sizeof c_str, TEST_FORMAT, localtime (&t));
1439 g_assert_cmpstr (c_str, ==, dt_str);
1440 g_date_time_unref (date_time);
1445 #pragma GCC diagnostic pop
1448 test_find_interval (void)
1456 tz = g_time_zone_new ("America/Toronto");
1457 #elif defined G_OS_WIN32
1458 tz = g_time_zone_new ("Eastern Standard Time");
1460 dt = g_date_time_new_utc (2010, 11, 7, 1, 30, 0);
1461 u = g_date_time_to_unix (dt);
1463 i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, u);
1464 i2 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, u);
1466 g_assert_cmpint (i1, !=, i2);
1468 g_date_time_unref (dt);
1470 dt = g_date_time_new_utc (2010, 3, 14, 2, 0, 0);
1471 u = g_date_time_to_unix (dt);
1473 i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, u);
1474 g_assert_cmpint (i1, ==, -1);
1476 g_date_time_unref (dt);
1477 g_time_zone_unref (tz);
1481 test_adjust_time (void)
1489 tz = g_time_zone_new ("America/Toronto");
1490 #elif defined G_OS_WIN32
1491 tz = g_time_zone_new ("Eastern Standard Time");
1493 dt = g_date_time_new_utc (2010, 11, 7, 1, 30, 0);
1494 u = g_date_time_to_unix (dt);
1497 i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, u);
1498 i2 = g_time_zone_adjust_time (tz, G_TIME_TYPE_DAYLIGHT, &u2);
1500 g_assert_cmpint (i1, ==, i2);
1503 g_date_time_unref (dt);
1505 dt = g_date_time_new_utc (2010, 3, 14, 2, 30, 0);
1506 u2 = g_date_time_to_unix (dt);
1507 g_date_time_unref (dt);
1509 dt = g_date_time_new_utc (2010, 3, 14, 3, 0, 0);
1510 u = g_date_time_to_unix (dt);
1511 g_date_time_unref (dt);
1513 i1 = g_time_zone_adjust_time (tz, G_TIME_TYPE_DAYLIGHT, &u2);
1516 g_time_zone_unref (tz);
1520 test_no_header (void)
1524 tz = g_time_zone_new ("blabla");
1526 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
1527 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 0);
1528 g_assert (!g_time_zone_is_dst (tz, 0));
1530 g_time_zone_unref (tz);
1534 test_posix_parse (void)
1537 GDateTime *gdt1, *gdt2;
1539 tz = g_time_zone_new ("PST");
1540 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
1541 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 0);
1542 g_assert (!g_time_zone_is_dst (tz, 0));
1543 g_time_zone_unref (tz);
1545 tz = g_time_zone_new ("PST8");
1546 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
1547 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
1548 g_assert (!g_time_zone_is_dst (tz, 0));
1549 g_time_zone_unref (tz);
1551 /* This fails rules_from_identifier on Unix (though not on Windows)
1552 * but passes anyway because PST8PDT is a zone name.
1554 tz = g_time_zone_new ("PST8PDT");
1555 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
1556 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
1557 g_assert (!g_time_zone_is_dst (tz, 0));
1558 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "PDT");
1559 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==,- 7 * 3600);
1560 g_assert (g_time_zone_is_dst (tz, 1));
1561 g_time_zone_unref (tz);
1563 tz = g_time_zone_new ("PST8PDT6:32:15");
1565 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
1566 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
1567 g_assert (!g_time_zone_is_dst (tz, 0));
1568 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "PDT");
1569 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, - 6 * 3600 - 32 *60 - 15);
1570 g_assert (g_time_zone_is_dst (tz, 1));
1571 gdt1 = g_date_time_new (tz, 2012, 12, 6, 11, 15, 23.0);
1572 gdt2 = g_date_time_new (tz, 2012, 6, 6, 11, 15, 23.0);
1573 g_assert (!g_date_time_is_daylight_savings (gdt1));
1574 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, -28800);
1575 g_assert (g_date_time_is_daylight_savings (gdt2));
1576 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, -23535);
1577 g_date_time_unref (gdt1);
1578 g_date_time_unref (gdt2);
1580 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
1581 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 0);
1582 g_assert (!g_time_zone_is_dst (tz, 0));
1584 g_time_zone_unref (tz);
1586 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0");
1587 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
1588 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
1589 g_assert (!g_time_zone_is_dst (tz, 0));
1590 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
1591 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
1592 g_assert (g_time_zone_is_dst (tz, 1));
1593 gdt1 = g_date_time_new (tz, 2012, 3, 18, 0, 15, 23.0);
1594 gdt2 = g_date_time_new (tz, 2012, 3, 18, 3, 15, 23.0);
1595 g_assert (g_date_time_is_daylight_savings (gdt1));
1596 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1597 g_assert (!g_date_time_is_daylight_savings (gdt2));
1598 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1599 g_date_time_unref (gdt1);
1600 g_date_time_unref (gdt2);
1601 gdt1 = g_date_time_new (tz, 2012, 10, 7, 3, 15, 23.0);
1602 gdt2 = g_date_time_new (tz, 2012, 10, 7, 1, 15, 23.0);
1603 g_assert (g_date_time_is_daylight_savings (gdt1));
1604 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1605 g_assert (!g_date_time_is_daylight_savings (gdt2));
1606 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1607 g_date_time_unref (gdt1);
1608 g_date_time_unref (gdt2);
1609 g_time_zone_unref (tz);
1611 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,280,77");
1612 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
1613 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
1614 g_assert (!g_time_zone_is_dst (tz, 0));
1615 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
1616 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
1617 g_assert (g_time_zone_is_dst (tz, 1));
1618 gdt1 = g_date_time_new (tz, 2012, 3, 18, 0, 15, 23.0);
1619 gdt2 = g_date_time_new (tz, 2012, 3, 18, 3, 15, 23.0);
1620 g_assert (g_date_time_is_daylight_savings (gdt1));
1621 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1622 g_assert (!g_date_time_is_daylight_savings (gdt2));
1623 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1624 g_date_time_unref (gdt1);
1625 g_date_time_unref (gdt2);
1626 gdt1 = g_date_time_new (tz, 2012, 10, 7, 3, 15, 23.0);
1627 gdt2 = g_date_time_new (tz, 2012, 10, 7, 1, 15, 23.0);
1628 g_assert (g_date_time_is_daylight_savings (gdt1));
1629 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1630 g_assert (!g_date_time_is_daylight_savings (gdt2));
1631 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1632 g_date_time_unref (gdt1);
1633 g_date_time_unref (gdt2);
1634 g_time_zone_unref (tz);
1636 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,J279,J76");
1637 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
1638 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
1639 g_assert (!g_time_zone_is_dst (tz, 0));
1640 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
1641 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
1642 g_assert (g_time_zone_is_dst (tz, 1));
1643 gdt1 = g_date_time_new (tz, 2012, 3, 18, 0, 15, 23.0);
1644 gdt2 = g_date_time_new (tz, 2012, 3, 18, 3, 15, 23.0);
1645 g_assert (g_date_time_is_daylight_savings (gdt1));
1646 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1647 g_assert (!g_date_time_is_daylight_savings (gdt2));
1648 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1649 g_date_time_unref (gdt1);
1650 g_date_time_unref (gdt2);
1651 gdt1 = g_date_time_new (tz, 2012, 10, 7, 3, 15, 23.0);
1652 gdt2 = g_date_time_new (tz, 2012, 10, 7, 1, 15, 23.0);
1653 g_assert (g_date_time_is_daylight_savings (gdt1));
1654 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1655 g_assert (!g_date_time_is_daylight_savings (gdt2));
1656 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1657 g_date_time_unref (gdt1);
1658 g_date_time_unref (gdt2);
1659 g_time_zone_unref (tz);
1661 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,M10.1.0/07:00,M3.3.0/07:00");
1662 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
1663 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
1664 g_assert (!g_time_zone_is_dst (tz, 0));
1665 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
1666 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
1667 g_assert (g_time_zone_is_dst (tz, 1));
1668 gdt1 = g_date_time_new (tz, 2012, 3, 18, 5, 15, 23.0);
1669 gdt2 = g_date_time_new (tz, 2012, 3, 18, 8, 15, 23.0);
1670 g_assert (g_date_time_is_daylight_savings (gdt1));
1671 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1672 g_assert (!g_date_time_is_daylight_savings (gdt2));
1673 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1674 g_date_time_unref (gdt1);
1675 g_date_time_unref (gdt2);
1676 gdt1 = g_date_time_new (tz, 2012, 10, 7, 8, 15, 23.0);
1677 gdt2 = g_date_time_new (tz, 2012, 10, 7, 6, 15, 23.0);
1678 g_assert (g_date_time_is_daylight_savings (gdt1));
1679 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1680 g_assert (!g_date_time_is_daylight_savings (gdt2));
1681 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1682 g_date_time_unref (gdt1);
1683 g_date_time_unref (gdt2);
1684 gdt1 = g_date_time_new (tz, 1902, 10, 7, 8, 15, 23.0);
1685 gdt2 = g_date_time_new (tz, 1902, 10, 7, 6, 15, 23.0);
1686 g_assert (!g_date_time_is_daylight_savings (gdt1));
1687 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 43200);
1688 g_assert (!g_date_time_is_daylight_savings (gdt2));
1689 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1690 g_date_time_unref (gdt1);
1691 g_date_time_unref (gdt2);
1692 gdt1 = g_date_time_new (tz, 2142, 10, 7, 8, 15, 23.0);
1693 gdt2 = g_date_time_new (tz, 2142, 10, 7, 6, 15, 23.0);
1694 g_assert (g_date_time_is_daylight_savings (gdt1));
1695 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
1696 g_assert (!g_date_time_is_daylight_savings (gdt2));
1697 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1698 g_date_time_unref (gdt1);
1699 g_date_time_unref (gdt2);
1700 gdt1 = g_date_time_new (tz, 3212, 10, 7, 8, 15, 23.0);
1701 gdt2 = g_date_time_new (tz, 3212, 10, 7, 6, 15, 23.0);
1702 g_assert (!g_date_time_is_daylight_savings (gdt1));
1703 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 43200);
1704 g_assert (!g_date_time_is_daylight_savings (gdt2));
1705 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
1706 g_date_time_unref (gdt1);
1707 g_date_time_unref (gdt2);
1708 g_time_zone_unref (tz);
1715 g_test_init (&argc, &argv, NULL);
1716 g_test_bug_base ("http://bugzilla.gnome.org/");
1718 /* GDateTime Tests */
1720 g_test_add_func ("/GDateTime/invalid", test_GDateTime_invalid);
1721 g_test_add_func ("/GDateTime/add_days", test_GDateTime_add_days);
1722 g_test_add_func ("/GDateTime/add_full", test_GDateTime_add_full);
1723 g_test_add_func ("/GDateTime/add_hours", test_GDateTime_add_hours);
1724 g_test_add_func ("/GDateTime/add_minutes", test_GDateTime_add_minutes);
1725 g_test_add_func ("/GDateTime/add_months", test_GDateTime_add_months);
1726 g_test_add_func ("/GDateTime/add_seconds", test_GDateTime_add_seconds);
1727 g_test_add_func ("/GDateTime/add_weeks", test_GDateTime_add_weeks);
1728 g_test_add_func ("/GDateTime/add_years", test_GDateTime_add_years);
1729 g_test_add_func ("/GDateTime/compare", test_GDateTime_compare);
1730 g_test_add_func ("/GDateTime/diff", test_GDateTime_diff);
1731 g_test_add_func ("/GDateTime/equal", test_GDateTime_equal);
1732 g_test_add_func ("/GDateTime/get_day_of_week", test_GDateTime_get_day_of_week);
1733 g_test_add_func ("/GDateTime/get_day_of_month", test_GDateTime_get_day_of_month);
1734 g_test_add_func ("/GDateTime/get_day_of_year", test_GDateTime_get_day_of_year);
1735 g_test_add_func ("/GDateTime/get_hour", test_GDateTime_get_hour);
1736 g_test_add_func ("/GDateTime/get_microsecond", test_GDateTime_get_microsecond);
1737 g_test_add_func ("/GDateTime/get_minute", test_GDateTime_get_minute);
1738 g_test_add_func ("/GDateTime/get_month", test_GDateTime_get_month);
1739 g_test_add_func ("/GDateTime/get_second", test_GDateTime_get_second);
1740 g_test_add_func ("/GDateTime/get_utc_offset", test_GDateTime_get_utc_offset);
1741 g_test_add_func ("/GDateTime/get_year", test_GDateTime_get_year);
1742 g_test_add_func ("/GDateTime/hash", test_GDateTime_hash);
1743 g_test_add_func ("/GDateTime/new_from_unix", test_GDateTime_new_from_unix);
1744 g_test_add_func ("/GDateTime/new_from_unix_utc", test_GDateTime_new_from_unix_utc);
1745 g_test_add_func ("/GDateTime/new_from_unix/overflow", test_GDateTime_new_from_unix_overflow);
1746 g_test_add_func ("/GDateTime/new_from_timeval", test_GDateTime_new_from_timeval);
1747 g_test_add_func ("/GDateTime/new_from_timeval_utc", test_GDateTime_new_from_timeval_utc);
1748 g_test_add_func ("/GDateTime/new_from_timeval/overflow", test_GDateTime_new_from_timeval_overflow);
1749 g_test_add_func ("/GDateTime/new_full", test_GDateTime_new_full);
1750 g_test_add_func ("/GDateTime/now", test_GDateTime_now);
1751 g_test_add_func ("/GDateTime/printf", test_GDateTime_printf);
1752 g_test_add_func ("/GDateTime/non_utf8_printf", test_non_utf8_printf);
1753 g_test_add_func ("/GDateTime/strftime", test_strftime);
1754 g_test_add_func ("/GDateTime/modifiers", test_modifiers);
1755 g_test_add_func ("/GDateTime/to_local", test_GDateTime_to_local);
1756 g_test_add_func ("/GDateTime/to_unix", test_GDateTime_to_unix);
1757 g_test_add_func ("/GDateTime/to_timeval", test_GDateTime_to_timeval);
1758 g_test_add_func ("/GDateTime/to_utc", test_GDateTime_to_utc);
1759 g_test_add_func ("/GDateTime/now_utc", test_GDateTime_now_utc);
1760 g_test_add_func ("/GDateTime/dst", test_GDateTime_dst);
1761 g_test_add_func ("/GDateTime/test_z", test_z);
1762 g_test_add_func ("/GDateTime/test-all-dates", test_all_dates);
1763 g_test_add_func ("/GTimeZone/find-interval", test_find_interval);
1764 g_test_add_func ("/GTimeZone/adjust-time", test_adjust_time);
1765 g_test_add_func ("/GTimeZone/no-header", test_no_header);
1766 g_test_add_func ("/GTimeZone/posix-parse", test_posix_parse);
1768 return g_test_run ();