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/>.
25 #include <glib/gstdio.h>
29 #define WIN32_LEAN_AND_MEAN
33 #define ASSERT_DATE(dt,y,m,d) G_STMT_START { \
34 g_assert_nonnull ((dt)); \
35 g_assert_cmpint ((y), ==, g_date_time_get_year ((dt))); \
36 g_assert_cmpint ((m), ==, g_date_time_get_month ((dt))); \
37 g_assert_cmpint ((d), ==, g_date_time_get_day_of_month ((dt))); \
39 #define ASSERT_TIME(dt,H,M,S,U) G_STMT_START { \
40 g_assert_nonnull ((dt)); \
41 g_assert_cmpint ((H), ==, g_date_time_get_hour ((dt))); \
42 g_assert_cmpint ((M), ==, g_date_time_get_minute ((dt))); \
43 g_assert_cmpint ((S), ==, g_date_time_get_second ((dt))); \
44 g_assert_cmpint ((U), ==, g_date_time_get_microsecond ((dt))); \
48 get_localtime_tm (time_t time_,
51 #ifdef HAVE_LOCALTIME_R
52 localtime_r (&time_, retval);
55 struct tm *ptm = localtime (&time_);
59 /* Happens at least in Microsoft's C library if you pass a
60 * negative time_t. Use 2000-01-01 as default date.
62 #ifndef G_DISABLE_CHECKS
63 g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, "ptm != NULL");
68 retval->tm_year = 100;
71 memcpy ((void *) retval, (void *) ptm, sizeof (struct tm));
73 #endif /* HAVE_LOCALTIME_R */
77 test_GDateTime_now (void)
84 /* before <= dt.to_unix() <= after, but the inequalities might not be
85 * equality if we're close to the boundary between seconds.
86 * We loop until before == after (and hence dt.to_unix() should equal both)
87 * to guard against that. */
90 before = g_get_real_time () / G_TIME_SPAN_SECOND;
92 memset (&tm, 0, sizeof (tm));
93 get_localtime_tm (before, &tm);
95 dt = g_date_time_new_now_local ();
97 after = g_get_real_time () / G_TIME_SPAN_SECOND;
99 while (before != after);
101 g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
102 g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
103 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
104 g_assert_cmpint (g_date_time_get_hour (dt), ==, tm.tm_hour);
105 g_assert_cmpint (g_date_time_get_minute (dt), ==, tm.tm_min);
106 g_assert_cmpint (g_date_time_get_second (dt), ==, tm.tm_sec);
108 g_date_time_unref (dt);
112 test_GDateTime_new_from_unix (void)
118 memset (&tm, 0, sizeof (tm));
120 g_assert_cmpint (t, !=, (time_t) -1);
121 get_localtime_tm (t, &tm);
123 dt = g_date_time_new_from_unix_local (t);
124 g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
125 g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
126 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
127 g_assert_cmpint (g_date_time_get_hour (dt), ==, tm.tm_hour);
128 g_assert_cmpint (g_date_time_get_minute (dt), ==, tm.tm_min);
129 g_assert_cmpint (g_date_time_get_second (dt), ==, tm.tm_sec);
130 g_date_time_unref (dt);
132 /* Choose 1990-01-01 04:00:00 because no DST leaps happened then. The more
133 * obvious 1990-01-01 00:00:00 was a DST leap in America/Lima (which has,
134 * confusingly, since stopped using DST). */
135 memset (&tm, 0, sizeof (tm));
145 dt = g_date_time_new_from_unix_local (t);
146 g_assert_cmpint (g_date_time_get_year (dt), ==, 1990);
147 g_assert_cmpint (g_date_time_get_month (dt), ==, 1);
148 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 1);
149 g_assert_cmpint (g_date_time_get_hour (dt), ==, 4);
150 g_assert_cmpint (g_date_time_get_minute (dt), ==, 0);
151 g_assert_cmpint (g_date_time_get_second (dt), ==, 0);
152 g_date_time_unref (dt);
155 /* Check that trying to create a #GDateTime too far in the future reliably
156 * fails. Previously, the checks for this overflowed and it silently returned
157 * an incorrect #GDateTime. */
159 test_GDateTime_new_from_unix_overflow (void)
163 g_test_bug ("782089");
165 dt = g_date_time_new_from_unix_utc (G_MAXINT64);
168 dt = g_date_time_new_from_unix_local (G_MAXINT64);
173 test_GDateTime_invalid (void)
177 g_test_bug ("702674");
179 dt = g_date_time_new_utc (2013, -2147483647, 31, 17, 15, 48);
180 g_assert (dt == NULL);
184 test_GDateTime_compare (void)
186 GDateTime *dt1, *dt2;
189 dt1 = g_date_time_new_utc (2000, 1, 1, 0, 0, 0);
191 for (i = 1; i < 2000; i++)
193 dt2 = g_date_time_new_utc (i, 12, 31, 0, 0, 0);
194 g_assert_cmpint (1, ==, g_date_time_compare (dt1, dt2));
195 g_date_time_unref (dt2);
198 dt2 = g_date_time_new_utc (1999, 12, 31, 23, 59, 59);
199 g_assert_cmpint (1, ==, g_date_time_compare (dt1, dt2));
200 g_date_time_unref (dt2);
202 dt2 = g_date_time_new_utc (2000, 1, 1, 0, 0, 1);
203 g_assert_cmpint (-1, ==, g_date_time_compare (dt1, dt2));
204 g_date_time_unref (dt2);
206 dt2 = g_date_time_new_utc (2000, 1, 1, 0, 0, 0);
207 g_assert_cmpint (0, ==, g_date_time_compare (dt1, dt2));
208 g_date_time_unref (dt2);
209 g_date_time_unref (dt1);
213 test_GDateTime_equal (void)
215 GDateTime *dt1, *dt2;
218 dt1 = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
219 dt2 = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
220 g_assert (g_date_time_equal (dt1, dt2));
221 g_date_time_unref (dt1);
222 g_date_time_unref (dt2);
224 dt1 = g_date_time_new_local (2009, 10, 18, 0, 0, 0);
225 dt2 = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
226 g_assert (!g_date_time_equal (dt1, dt2));
227 g_date_time_unref (dt1);
228 g_date_time_unref (dt2);
230 /* UTC-0300 and not in DST */
231 tz = g_time_zone_new ("-03:00");
232 dt1 = g_date_time_new (tz, 2010, 5, 24, 8, 0, 0);
233 g_time_zone_unref (tz);
234 g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, (-3 * 3600));
236 dt2 = g_date_time_new_utc (2010, 5, 24, 11, 0, 0);
237 g_assert_cmpint (g_date_time_get_utc_offset (dt2), ==, 0);
239 g_assert (g_date_time_equal (dt1, dt2));
240 g_date_time_unref (dt1);
242 /* America/Recife is in UTC-0300 */
244 tz = g_time_zone_new ("America/Recife");
245 #elif defined G_OS_WIN32
246 tz = g_time_zone_new ("E. South America Standard Time");
248 dt1 = g_date_time_new (tz, 2010, 5, 24, 8, 0, 0);
249 g_time_zone_unref (tz);
250 g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, (-3 * 3600));
251 g_assert (g_date_time_equal (dt1, dt2));
252 g_date_time_unref (dt1);
253 g_date_time_unref (dt2);
257 test_GDateTime_get_day_of_week (void)
261 dt = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
262 g_assert_cmpint (1, ==, g_date_time_get_day_of_week (dt));
263 g_date_time_unref (dt);
265 dt = g_date_time_new_local (2000, 10, 1, 0, 0, 0);
266 g_assert_cmpint (7, ==, g_date_time_get_day_of_week (dt));
267 g_date_time_unref (dt);
271 test_GDateTime_get_day_of_month (void)
275 dt = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
276 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 19);
277 g_date_time_unref (dt);
279 dt = g_date_time_new_local (1400, 3, 12, 0, 0, 0);
280 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 12);
281 g_date_time_unref (dt);
283 dt = g_date_time_new_local (1800, 12, 31, 0, 0, 0);
284 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 31);
285 g_date_time_unref (dt);
287 dt = g_date_time_new_local (1000, 1, 1, 0, 0, 0);
288 g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 1);
289 g_date_time_unref (dt);
293 test_GDateTime_get_hour (void)
297 dt = g_date_time_new_utc (2009, 10, 19, 15, 13, 11);
298 g_assert_cmpint (15, ==, g_date_time_get_hour (dt));
299 g_date_time_unref (dt);
301 dt = g_date_time_new_utc (100, 10, 19, 1, 0, 0);
302 g_assert_cmpint (1, ==, g_date_time_get_hour (dt));
303 g_date_time_unref (dt);
305 dt = g_date_time_new_utc (100, 10, 19, 0, 0, 0);
306 g_assert_cmpint (0, ==, g_date_time_get_hour (dt));
307 g_date_time_unref (dt);
309 dt = g_date_time_new_utc (100, 10, 1, 23, 59, 59);
310 g_assert_cmpint (23, ==, g_date_time_get_hour (dt));
311 g_date_time_unref (dt);
314 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
316 test_GDateTime_get_microsecond (void)
321 g_get_current_time (&tv);
322 dt = g_date_time_new_from_timeval_local (&tv);
323 g_assert_cmpint (tv.tv_usec, ==, g_date_time_get_microsecond (dt));
324 g_date_time_unref (dt);
326 G_GNUC_END_IGNORE_DEPRECATIONS
329 test_GDateTime_get_year (void)
333 dt = g_date_time_new_local (2009, 1, 1, 0, 0, 0);
334 g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
335 g_date_time_unref (dt);
337 dt = g_date_time_new_local (1, 1, 1, 0, 0, 0);
338 g_assert_cmpint (1, ==, g_date_time_get_year (dt));
339 g_date_time_unref (dt);
341 dt = g_date_time_new_local (13, 1, 1, 0, 0, 0);
342 g_assert_cmpint (13, ==, g_date_time_get_year (dt));
343 g_date_time_unref (dt);
345 dt = g_date_time_new_local (3000, 1, 1, 0, 0, 0);
346 g_assert_cmpint (3000, ==, g_date_time_get_year (dt));
347 g_date_time_unref (dt);
351 test_GDateTime_hash (void)
355 h = g_hash_table_new_full (g_date_time_hash, g_date_time_equal,
356 (GDestroyNotify)g_date_time_unref,
358 g_hash_table_add (h, g_date_time_new_now_local ());
359 g_hash_table_remove_all (h);
360 g_hash_table_destroy (h);
363 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
365 test_GDateTime_new_from_timeval (void)
370 g_get_current_time (&tv);
371 dt = g_date_time_new_from_timeval_local (&tv);
373 if (g_test_verbose ())
374 g_printerr ("\nDT%04d-%02d-%02dT%02d:%02d:%02d%s\n",
375 g_date_time_get_year (dt),
376 g_date_time_get_month (dt),
377 g_date_time_get_day_of_month (dt),
378 g_date_time_get_hour (dt),
379 g_date_time_get_minute (dt),
380 g_date_time_get_second (dt),
381 g_date_time_get_timezone_abbreviation (dt));
383 g_date_time_to_timeval (dt, &tv2);
384 g_assert_cmpint (tv.tv_sec, ==, tv2.tv_sec);
385 g_assert_cmpint (tv.tv_usec, ==, tv2.tv_usec);
386 g_date_time_unref (dt);
390 find_maximum_supported_tv_sec (void)
392 glong highest_success = 0, lowest_failure = G_MAXLONG;
394 GDateTime *dt = NULL;
398 /* Corner case of all glong values being valid. */
399 tv.tv_sec = G_MAXLONG;
400 dt = g_date_time_new_from_timeval_utc (&tv);
403 highest_success = tv.tv_sec;
404 g_date_time_unref (dt);
407 while (highest_success < lowest_failure - 1)
409 tv.tv_sec = highest_success + (lowest_failure - highest_success) / 2;
410 dt = g_date_time_new_from_timeval_utc (&tv);
414 highest_success = tv.tv_sec;
415 g_date_time_unref (dt);
419 lowest_failure = tv.tv_sec;
423 return highest_success;
426 /* Check that trying to create a #GDateTime too far in the future reliably
427 * fails. With a #GTimeVal, this is subtle, as the tv_usec are added into the
428 * calculation part-way through.
430 * This varies a bit between 32- and 64-bit architectures, due to the
431 * differences in the size of glong (tv.tv_sec). */
433 test_GDateTime_new_from_timeval_overflow (void)
438 g_test_bug ("782089");
440 tv.tv_sec = find_maximum_supported_tv_sec ();
441 tv.tv_usec = G_USEC_PER_SEC - 1;
443 g_test_message ("Maximum supported GTimeVal.tv_sec = %lu", tv.tv_sec);
445 /* Sanity check: do we support the year 2000? */
446 g_assert_cmpint (tv.tv_sec, >=, 946684800);
448 dt = g_date_time_new_from_timeval_utc (&tv);
449 g_assert_nonnull (dt);
450 g_date_time_unref (dt);
452 if (tv.tv_sec < G_MAXLONG)
457 dt = g_date_time_new_from_timeval_utc (&tv);
463 test_GDateTime_new_from_timeval_utc (void)
468 g_get_current_time (&tv);
469 dt = g_date_time_new_from_timeval_utc (&tv);
471 if (g_test_verbose ())
472 g_printerr ("\nDT%04d-%02d-%02dT%02d:%02d:%02d%s\n",
473 g_date_time_get_year (dt),
474 g_date_time_get_month (dt),
475 g_date_time_get_day_of_month (dt),
476 g_date_time_get_hour (dt),
477 g_date_time_get_minute (dt),
478 g_date_time_get_second (dt),
479 g_date_time_get_timezone_abbreviation (dt));
481 g_date_time_to_timeval (dt, &tv2);
482 g_assert_cmpint (tv.tv_sec, ==, tv2.tv_sec);
483 g_assert_cmpint (tv.tv_usec, ==, tv2.tv_usec);
484 g_date_time_unref (dt);
486 G_GNUC_END_IGNORE_DEPRECATIONS
489 test_GDateTime_new_from_iso8601 (void)
494 /* Need non-empty string */
495 dt = g_date_time_new_from_iso8601 ("", NULL);
498 /* Needs to be correctly formatted */
499 dt = g_date_time_new_from_iso8601 ("not a date", NULL);
502 dt = g_date_time_new_from_iso8601 (" +55", NULL);
505 /* Check common case */
506 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42Z", NULL);
507 ASSERT_DATE (dt, 2016, 8, 24);
508 ASSERT_TIME (dt, 22, 10, 42, 0);
509 g_date_time_unref (dt);
511 /* Timezone is required in text or passed as arg */
512 tz = g_time_zone_new_utc ();
513 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42", tz);
514 ASSERT_DATE (dt, 2016, 8, 24);
515 g_date_time_unref (dt);
516 g_time_zone_unref (tz);
517 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42", NULL);
520 /* Can't have whitespace */
521 dt = g_date_time_new_from_iso8601 ("2016 08 24T22:10:42Z", NULL);
523 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42Z ", NULL);
525 dt = g_date_time_new_from_iso8601 (" 2016-08-24T22:10:42Z", NULL);
528 /* Check lowercase time separator or space allowed */
529 dt = g_date_time_new_from_iso8601 ("2016-08-24t22:10:42Z", NULL);
530 ASSERT_DATE (dt, 2016, 8, 24);
531 ASSERT_TIME (dt, 22, 10, 42, 0);
532 g_date_time_unref (dt);
533 dt = g_date_time_new_from_iso8601 ("2016-08-24 22:10:42Z", NULL);
534 ASSERT_DATE (dt, 2016, 8, 24);
535 ASSERT_TIME (dt, 22, 10, 42, 0);
536 g_date_time_unref (dt);
538 /* Check dates without separators allowed */
539 dt = g_date_time_new_from_iso8601 ("20160824T22:10:42Z", NULL);
540 ASSERT_DATE (dt, 2016, 8, 24);
541 ASSERT_TIME (dt, 22, 10, 42, 0);
542 g_date_time_unref (dt);
544 /* Months are two digits */
545 dt = g_date_time_new_from_iso8601 ("2016-1-01T22:10:42Z", NULL);
548 /* Days are two digits */
549 dt = g_date_time_new_from_iso8601 ("2016-01-1T22:10:42Z", NULL);
552 /* Need consistent usage of separators */
553 dt = g_date_time_new_from_iso8601 ("2016-0824T22:10:42Z", NULL);
555 dt = g_date_time_new_from_iso8601 ("201608-24T22:10:42Z", NULL);
558 /* Check month within valid range */
559 dt = g_date_time_new_from_iso8601 ("2016-00-13T22:10:42Z", NULL);
561 dt = g_date_time_new_from_iso8601 ("2016-13-13T22:10:42Z", NULL);
564 /* Check day within valid range */
565 dt = g_date_time_new_from_iso8601 ("2016-01-00T22:10:42Z", NULL);
567 dt = g_date_time_new_from_iso8601 ("2016-01-31T22:10:42Z", NULL);
568 ASSERT_DATE (dt, 2016, 1, 31);
569 g_date_time_unref (dt);
570 dt = g_date_time_new_from_iso8601 ("2016-01-32T22:10:42Z", NULL);
572 dt = g_date_time_new_from_iso8601 ("2016-02-29T22:10:42Z", NULL);
573 ASSERT_DATE (dt, 2016, 2, 29);
574 g_date_time_unref (dt);
575 dt = g_date_time_new_from_iso8601 ("2016-02-30T22:10:42Z", NULL);
577 dt = g_date_time_new_from_iso8601 ("2017-02-28T22:10:42Z", NULL);
578 ASSERT_DATE (dt, 2017, 2, 28);
579 g_date_time_unref (dt);
580 dt = g_date_time_new_from_iso8601 ("2017-02-29T22:10:42Z", NULL);
582 dt = g_date_time_new_from_iso8601 ("2016-03-31T22:10:42Z", NULL);
583 ASSERT_DATE (dt, 2016, 3, 31);
584 g_date_time_unref (dt);
585 dt = g_date_time_new_from_iso8601 ("2016-03-32T22:10:42Z", NULL);
587 dt = g_date_time_new_from_iso8601 ("2016-04-30T22:10:42Z", NULL);
588 ASSERT_DATE (dt, 2016, 4, 30);
589 g_date_time_unref (dt);
590 dt = g_date_time_new_from_iso8601 ("2016-04-31T22:10:42Z", NULL);
592 dt = g_date_time_new_from_iso8601 ("2016-05-31T22:10:42Z", NULL);
593 ASSERT_DATE (dt, 2016, 5, 31);
594 g_date_time_unref (dt);
595 dt = g_date_time_new_from_iso8601 ("2016-05-32T22:10:42Z", NULL);
597 dt = g_date_time_new_from_iso8601 ("2016-06-30T22:10:42Z", NULL);
598 ASSERT_DATE (dt, 2016, 6, 30);
599 g_date_time_unref (dt);
600 dt = g_date_time_new_from_iso8601 ("2016-06-31T22:10:42Z", NULL);
602 dt = g_date_time_new_from_iso8601 ("2016-07-31T22:10:42Z", NULL);
603 ASSERT_DATE (dt, 2016, 7, 31);
604 g_date_time_unref (dt);
605 dt = g_date_time_new_from_iso8601 ("2016-07-32T22:10:42Z", NULL);
607 dt = g_date_time_new_from_iso8601 ("2016-08-31T22:10:42Z", NULL);
608 ASSERT_DATE (dt, 2016, 8, 31);
609 g_date_time_unref (dt);
610 dt = g_date_time_new_from_iso8601 ("2016-08-32T22:10:42Z", NULL);
612 dt = g_date_time_new_from_iso8601 ("2016-09-30T22:10:42Z", NULL);
613 ASSERT_DATE (dt, 2016, 9, 30);
614 g_date_time_unref (dt);
615 dt = g_date_time_new_from_iso8601 ("2016-09-31T22:10:42Z", NULL);
617 dt = g_date_time_new_from_iso8601 ("2016-10-31T22:10:42Z", NULL);
618 ASSERT_DATE (dt, 2016, 10, 31);
619 g_date_time_unref (dt);
620 dt = g_date_time_new_from_iso8601 ("2016-10-32T22:10:42Z", NULL);
622 dt = g_date_time_new_from_iso8601 ("2016-11-30T22:10:42Z", NULL);
623 ASSERT_DATE (dt, 2016, 11, 30);
624 g_date_time_unref (dt);
625 dt = g_date_time_new_from_iso8601 ("2016-11-31T22:10:42Z", NULL);
627 dt = g_date_time_new_from_iso8601 ("2016-12-31T22:10:42Z", NULL);
628 ASSERT_DATE (dt, 2016, 12, 31);
629 g_date_time_unref (dt);
630 dt = g_date_time_new_from_iso8601 ("2016-12-32T22:10:42Z", NULL);
633 /* Check ordinal days work */
634 dt = g_date_time_new_from_iso8601 ("2016-237T22:10:42Z", NULL);
635 ASSERT_DATE (dt, 2016, 8, 24);
636 ASSERT_TIME (dt, 22, 10, 42, 0);
637 g_date_time_unref (dt);
638 dt = g_date_time_new_from_iso8601 ("2016237T22:10:42Z", NULL);
639 ASSERT_DATE (dt, 2016, 8, 24);
640 ASSERT_TIME (dt, 22, 10, 42, 0);
641 g_date_time_unref (dt);
643 /* Check ordinal leap days */
644 dt = g_date_time_new_from_iso8601 ("2016-366T22:10:42Z", NULL);
645 ASSERT_DATE (dt, 2016, 12, 31);
646 ASSERT_TIME (dt, 22, 10, 42, 0);
647 g_date_time_unref (dt);
648 dt = g_date_time_new_from_iso8601 ("2017-365T22:10:42Z", NULL);
649 ASSERT_DATE (dt, 2017, 12, 31);
650 ASSERT_TIME (dt, 22, 10, 42, 0);
651 g_date_time_unref (dt);
652 dt = g_date_time_new_from_iso8601 ("2017-366T22:10:42Z", NULL);
655 /* Days start at 1 */
656 dt = g_date_time_new_from_iso8601 ("2016-000T22:10:42Z", NULL);
659 /* Limited to number of days in the year (2016 is a leap year) */
660 dt = g_date_time_new_from_iso8601 ("2016-367T22:10:42Z", NULL);
663 /* Days are two digits */
664 dt = g_date_time_new_from_iso8601 ("2016-1T22:10:42Z", NULL);
666 dt = g_date_time_new_from_iso8601 ("2016-12T22:10:42Z", NULL);
669 /* Check week days work */
670 dt = g_date_time_new_from_iso8601 ("2016-W34-3T22:10:42Z", NULL);
671 ASSERT_DATE (dt, 2016, 8, 24);
672 ASSERT_TIME (dt, 22, 10, 42, 0);
673 g_date_time_unref (dt);
674 dt = g_date_time_new_from_iso8601 ("2016W343T22:10:42Z", NULL);
675 ASSERT_DATE (dt, 2016, 8, 24);
676 ASSERT_TIME (dt, 22, 10, 42, 0);
677 g_date_time_unref (dt);
679 /* We don't support weeks without weekdays (valid ISO 8601) */
680 dt = g_date_time_new_from_iso8601 ("2016-W34T22:10:42Z", NULL);
682 dt = g_date_time_new_from_iso8601 ("2016W34T22:10:42Z", NULL);
685 /* Weeks are two digits */
686 dt = g_date_time_new_from_iso8601 ("2016-W3-1T22:10:42Z", NULL);
689 /* Weeks start at 1 */
690 dt = g_date_time_new_from_iso8601 ("2016-W00-1T22:10:42Z", NULL);
693 /* Week one might be in the previous year */
694 dt = g_date_time_new_from_iso8601 ("2015-W01-1T22:10:42Z", NULL);
695 ASSERT_DATE (dt, 2014, 12, 29);
696 g_date_time_unref (dt);
698 /* Last week might be in next year */
699 dt = g_date_time_new_from_iso8601 ("2015-W53-7T22:10:42Z", NULL);
700 ASSERT_DATE (dt, 2016, 1, 3);
701 g_date_time_unref (dt);
703 /* Week 53 doesn't always exist */
704 dt = g_date_time_new_from_iso8601 ("2016-W53-1T22:10:42Z", NULL);
707 /* Limited to number of days in the week */
708 dt = g_date_time_new_from_iso8601 ("2016-W34-0T22:10:42Z", NULL);
710 dt = g_date_time_new_from_iso8601 ("2016-W34-8T22:10:42Z", NULL);
713 /* Days are one digit */
714 dt = g_date_time_new_from_iso8601 ("2016-W34-99T22:10:42Z", NULL);
717 /* Check week day changes depending on year */
718 dt = g_date_time_new_from_iso8601 ("2017-W34-1T22:10:42Z", NULL);
719 ASSERT_DATE (dt, 2017, 8, 21);
720 g_date_time_unref (dt);
722 /* Check week day changes depending on leap years */
723 dt = g_date_time_new_from_iso8601 ("1900-W01-1T22:10:42Z", NULL);
724 ASSERT_DATE (dt, 1900, 1, 1);
725 g_date_time_unref (dt);
727 /* YYYY-MM not allowed (NOT valid ISO 8601) */
728 dt = g_date_time_new_from_iso8601 ("2016-08T22:10:42Z", NULL);
731 /* We don't support omitted year (valid ISO 8601) */
732 dt = g_date_time_new_from_iso8601 ("--08-24T22:10:42Z", NULL);
734 dt = g_date_time_new_from_iso8601 ("--0824T22:10:42Z", NULL);
737 /* Check subseconds work */
738 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42.123456Z", NULL);
739 ASSERT_DATE (dt, 2016, 8, 24);
740 ASSERT_TIME (dt, 22, 10, 42, 123456);
741 g_date_time_unref (dt);
742 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42,123456Z", NULL);
743 ASSERT_DATE (dt, 2016, 8, 24);
744 ASSERT_TIME (dt, 22, 10, 42, 123456);
745 g_date_time_unref (dt);
746 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42.Z", NULL);
748 dt = g_date_time_new_from_iso8601 ("2016-08-24T221042.123456Z", NULL);
749 ASSERT_DATE (dt, 2016, 8, 24);
750 ASSERT_TIME (dt, 22, 10, 42, 123456);
751 g_date_time_unref (dt);
753 /* We don't support times without minutes / seconds (valid ISO 8601) */
754 dt = g_date_time_new_from_iso8601 ("2016-08-24T22Z", NULL);
756 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10Z", NULL);
758 dt = g_date_time_new_from_iso8601 ("2016-08-24T2210Z", NULL);
761 /* UTC time uses 'Z' */
762 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42Z", NULL);
763 ASSERT_DATE (dt, 2016, 8, 24);
764 ASSERT_TIME (dt, 22, 10, 42, 0);
765 g_assert_cmpint (g_date_time_get_utc_offset (dt), ==, 0);
766 g_date_time_unref (dt);
768 /* Check timezone works */
769 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42+12:00", NULL);
770 ASSERT_DATE (dt, 2016, 8, 24);
771 ASSERT_TIME (dt, 22, 10, 42, 0);
772 g_assert_cmpint (g_date_time_get_utc_offset (dt), ==, 12 * G_TIME_SPAN_HOUR);
773 g_date_time_unref (dt);
774 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42+12", NULL);
775 ASSERT_DATE (dt, 2016, 8, 24);
776 ASSERT_TIME (dt, 22, 10, 42, 0);
777 g_assert_cmpint (g_date_time_get_utc_offset (dt), ==, 12 * G_TIME_SPAN_HOUR);
778 g_date_time_unref (dt);
779 dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42-02", NULL);
780 ASSERT_DATE (dt, 2016, 8, 24);
781 ASSERT_TIME (dt, 22, 10, 42, 0);
782 g_assert_cmpint (g_date_time_get_utc_offset (dt), ==, -2 * G_TIME_SPAN_HOUR);
783 g_date_time_unref (dt);
785 /* Timezone seconds not allowed */
786 dt = g_date_time_new_from_iso8601 ("2016-08-24T22-12:00:00", NULL);
788 dt = g_date_time_new_from_iso8601 ("2016-08-24T22-12:00:00.000", NULL);
791 /* Timezone hours two digits */
792 dt = g_date_time_new_from_iso8601 ("2016-08-24T22-2Z", NULL);
800 /* Expected result: */
808 GTimeSpan utc_offset;
812 test_GDateTime_new_from_iso8601_2 (void)
814 const Iso8601ParseTest tests[] = {
815 { TRUE, "1990-11-01T10:21:17Z", 1990, 11, 1, 10, 21, 17, 0, 0 },
816 { TRUE, "19901101T102117Z", 1990, 11, 1, 10, 21, 17, 0, 0 },
817 { TRUE, "1970-01-01T00:00:17.12Z", 1970, 1, 1, 0, 0, 17, 120000, 0 },
818 { TRUE, "1970-01-01T00:00:17.1234Z", 1970, 1, 1, 0, 0, 17, 123400, 0 },
819 { TRUE, "1970-01-01T00:00:17.123456Z", 1970, 1, 1, 0, 0, 17, 123456, 0 },
820 { TRUE, "1980-02-22T12:36:00+02:00", 1980, 2, 22, 12, 36, 0, 0, 2 * G_TIME_SPAN_HOUR },
821 { FALSE, " ", 0, 0, 0, 0, 0, 0, 0, 0 },
822 { FALSE, "x", 0, 0, 0, 0, 0, 0, 0, 0 },
823 { FALSE, "123x", 0, 0, 0, 0, 0, 0, 0, 0 },
824 { FALSE, "2001-10+x", 0, 0, 0, 0, 0, 0, 0, 0 },
825 { FALSE, "1980-02-22T", 0, 0, 0, 0, 0, 0, 0, 0 },
826 { FALSE, "2001-10-08Tx", 0, 0, 0, 0, 0, 0, 0, 0 },
827 { FALSE, "2001-10-08T10:11x", 0, 0, 0, 0, 0, 0, 0, 0 },
828 { FALSE, "Wed Dec 19 17:20:20 GMT 2007", 0, 0, 0, 0, 0, 0, 0, 0 },
829 { FALSE, "1980-02-22T10:36:00Zulu", 0, 0, 0, 0, 0, 0, 0, 0 },
830 { FALSE, "2T0+819855292164632335", 0, 0, 0, 0, 0, 0, 0, 0 },
831 { TRUE, "2018-08-03T14:08:05.446178377+01:00", 2018, 8, 3, 14, 8, 5, 446178, 1 * G_TIME_SPAN_HOUR },
832 { FALSE, "2147483648-08-03T14:08:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
833 { FALSE, "2018-13-03T14:08:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
834 { FALSE, "2018-00-03T14:08:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
835 { FALSE, "2018-08-00T14:08:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
836 { FALSE, "2018-08-32T14:08:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
837 { FALSE, "2018-08-03T24:08:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
838 { FALSE, "2018-08-03T14:60:05.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
839 { FALSE, "2018-08-03T14:08:63.446178377+01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
840 { FALSE, "2018-08-03T14:08:05.446178377+100:00", 0, 0, 0, 0, 0, 0, 0, 0 },
841 { TRUE, "20180803T140805.446178377+0100", 2018, 8, 3, 14, 8, 5, 446178, 1 * G_TIME_SPAN_HOUR },
842 { FALSE, "21474836480803T140805.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
843 { FALSE, "20181303T140805.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
844 { FALSE, "20180003T140805.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
845 { FALSE, "20180800T140805.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
846 { FALSE, "20180832T140805.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
847 { FALSE, "20180803T240805.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
848 { FALSE, "20180803T146005.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
849 { FALSE, "20180803T140863.446178377+0100", 0, 0, 0, 0, 0, 0, 0, 0 },
850 { FALSE, "20180803T140805.446178377+10000", 0, 0, 0, 0, 0, 0, 0, 0 },
851 { FALSE, "-0005-01-01T00:00:00Z", 0, 0, 0, 0, 0, 0, 0, 0 },
852 { FALSE, "2018-08-06", 0, 0, 0, 0, 0, 0, 0, 0 },
853 /* This is not accepted by g_time_val_from_iso8601(), but is accepted by g_date_time_new_from_iso8601():
854 { FALSE, "2018-08-06 13:51:00Z", 0, 0, 0, 0, 0, 0, 0, 0 },
856 { TRUE, "20180803T140805,446178377+0100", 2018, 8, 3, 14, 8, 5, 446178, 1 * G_TIME_SPAN_HOUR },
857 { TRUE, "2018-08-03T14:08:05.446178377-01:00", 2018, 8, 3, 14, 8, 5, 446178, -1 * G_TIME_SPAN_HOUR },
858 { FALSE, "2018-08-03T14:08:05.446178377 01:00", 0, 0, 0, 0, 0, 0, 0, 0 },
859 { TRUE, "1990-11-01T10:21:17", 1990, 11, 1, 10, 21, 17, 0, 0 },
860 /* These are accepted by g_time_val_from_iso8601(), but not by g_date_time_new_from_iso8601():
861 { TRUE, "19901101T102117+5", 1990, 11, 1, 10, 21, 17, 0, 5 * G_TIME_SPAN_HOUR },
862 { TRUE, "19901101T102117+3:15", 1990, 11, 1, 10, 21, 17, 0, 3 * G_TIME_SPAN_HOUR + 15 * G_TIME_SPAN_MINUTE },
863 { TRUE, " 1990-11-01T10:21:17Z ", 1990, 11, 1, 10, 21, 17, 0, 0 },
864 { FALSE, "2018-08-03T14:08:05.446178377+01:60", 0, 0, 0, 0, 0, 0, 0, 0 },
865 { FALSE, "20180803T140805.446178377+0160", 0, 0, 0, 0, 0, 0, 0, 0 },
866 { TRUE, "+1980-02-22T12:36:00+02:00", 1980, 2, 22, 12, 36, 0, 0, 2 * G_TIME_SPAN_HOUR },
867 { TRUE, "1990-11-01T10:21:17 ", 1990, 11, 1, 10, 21, 17, 0, 0 },
870 GTimeZone *tz = NULL;
871 GDateTime *dt = NULL;
874 g_test_summary ("Further parser tests for g_date_time_new_from_iso8601(), "
875 "checking success and failure using test vectors.");
877 tz = g_time_zone_new_utc ();
879 for (i = 0; i < G_N_ELEMENTS (tests); i++)
881 g_test_message ("Vector %" G_GSIZE_FORMAT ": %s", i, tests[i].in);
883 dt = g_date_time_new_from_iso8601 (tests[i].in, tz);
884 if (tests[i].success)
886 g_assert_nonnull (dt);
887 ASSERT_DATE (dt, tests[i].year, tests[i].month, tests[i].day);
888 ASSERT_TIME (dt, tests[i].hour, tests[i].minute, tests[i].second, tests[i].microsecond);
889 g_assert_cmpint (g_date_time_get_utc_offset (dt), ==, tests[i].utc_offset);
896 g_clear_pointer (&dt, g_date_time_unref);
899 g_time_zone_unref (tz);
903 test_GDateTime_to_unix (void)
909 g_assert_cmpint (t, !=, (time_t) -1);
910 dt = g_date_time_new_from_unix_local (t);
911 g_assert_cmpint (g_date_time_to_unix (dt), ==, t);
912 g_date_time_unref (dt);
916 test_GDateTime_add_years (void)
920 dt = g_date_time_new_local (2009, 10, 19, 0, 0, 0);
921 dt2 = g_date_time_add_years (dt, 1);
922 g_assert_cmpint (2010, ==, g_date_time_get_year (dt2));
923 g_date_time_unref (dt);
924 g_date_time_unref (dt2);
928 test_GDateTime_add_months (void)
930 #define TEST_ADD_MONTHS(y,m,d,a,ny,nm,nd) G_STMT_START { \
931 GDateTime *dt, *dt2; \
932 dt = g_date_time_new_utc (y, m, d, 0, 0, 0); \
933 dt2 = g_date_time_add_months (dt, a); \
934 ASSERT_DATE (dt2, ny, nm, nd); \
935 g_date_time_unref (dt); \
936 g_date_time_unref (dt2); \
939 TEST_ADD_MONTHS (2009, 12, 31, 1, 2010, 1, 31);
940 TEST_ADD_MONTHS (2009, 12, 31, 1, 2010, 1, 31);
941 TEST_ADD_MONTHS (2009, 6, 15, 1, 2009, 7, 15);
942 TEST_ADD_MONTHS (1400, 3, 1, 1, 1400, 4, 1);
943 TEST_ADD_MONTHS (1400, 1, 31, 1, 1400, 2, 28);
944 TEST_ADD_MONTHS (1400, 1, 31, 7200, 2000, 1, 31);
945 TEST_ADD_MONTHS (2008, 2, 29, 12, 2009, 2, 28);
946 TEST_ADD_MONTHS (2000, 8, 16, -5, 2000, 3, 16);
947 TEST_ADD_MONTHS (2000, 8, 16, -12, 1999, 8, 16);
948 TEST_ADD_MONTHS (2011, 2, 1, -13, 2010, 1, 1);
949 TEST_ADD_MONTHS (1776, 7, 4, 1200, 1876, 7, 4);
953 test_GDateTime_add_days (void)
955 #define TEST_ADD_DAYS(y,m,d,a,ny,nm,nd) G_STMT_START { \
956 GDateTime *dt, *dt2; \
957 dt = g_date_time_new_local (y, m, d, 0, 0, 0); \
958 dt2 = g_date_time_add_days (dt, a); \
959 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
960 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
961 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
962 g_date_time_unref (dt); \
963 g_date_time_unref (dt2); \
966 TEST_ADD_DAYS (2009, 1, 31, 1, 2009, 2, 1);
967 TEST_ADD_DAYS (2009, 2, 1, -1, 2009, 1, 31);
968 TEST_ADD_DAYS (2008, 2, 28, 1, 2008, 2, 29);
969 TEST_ADD_DAYS (2008, 12, 31, 1, 2009, 1, 1);
970 TEST_ADD_DAYS (1, 1, 1, 1, 1, 1, 2);
971 TEST_ADD_DAYS (1955, 5, 24, 10, 1955, 6, 3);
972 TEST_ADD_DAYS (1955, 5, 24, -10, 1955, 5, 14);
976 test_GDateTime_add_weeks (void)
978 #define TEST_ADD_WEEKS(y,m,d,a,ny,nm,nd) G_STMT_START { \
979 GDateTime *dt, *dt2; \
980 dt = g_date_time_new_local (y, m, d, 0, 0, 0); \
981 dt2 = g_date_time_add_weeks (dt, a); \
982 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
983 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
984 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
985 g_date_time_unref (dt); \
986 g_date_time_unref (dt2); \
989 TEST_ADD_WEEKS (2009, 1, 1, 1, 2009, 1, 8);
990 TEST_ADD_WEEKS (2009, 8, 30, 1, 2009, 9, 6);
991 TEST_ADD_WEEKS (2009, 12, 31, 1, 2010, 1, 7);
992 TEST_ADD_WEEKS (2009, 1, 1, -1, 2008, 12, 25);
996 test_GDateTime_add_hours (void)
998 #define TEST_ADD_HOURS(y,m,d,h,mi,s,a,ny,nm,nd,nh,nmi,ns) G_STMT_START { \
999 GDateTime *dt, *dt2; \
1000 dt = g_date_time_new_utc (y, m, d, h, mi, s); \
1001 dt2 = g_date_time_add_hours (dt, a); \
1002 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
1003 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
1004 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
1005 g_assert_cmpint (nh, ==, g_date_time_get_hour (dt2)); \
1006 g_assert_cmpint (nmi, ==, g_date_time_get_minute (dt2)); \
1007 g_assert_cmpint (ns, ==, g_date_time_get_second (dt2)); \
1008 g_date_time_unref (dt); \
1009 g_date_time_unref (dt2); \
1012 TEST_ADD_HOURS (2009, 1, 1, 0, 0, 0, 1, 2009, 1, 1, 1, 0, 0);
1013 TEST_ADD_HOURS (2008, 12, 31, 23, 0, 0, 1, 2009, 1, 1, 0, 0, 0);
1017 test_GDateTime_add_full (void)
1019 #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 { \
1020 GDateTime *dt, *dt2; \
1021 dt = g_date_time_new_utc (y, m, d, h, mi, s); \
1022 dt2 = g_date_time_add_full (dt, ay, am, ad, ah, ami, as); \
1023 g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
1024 g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
1025 g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
1026 g_assert_cmpint (nh, ==, g_date_time_get_hour (dt2)); \
1027 g_assert_cmpint (nmi, ==, g_date_time_get_minute (dt2)); \
1028 g_assert_cmpint (ns, ==, g_date_time_get_second (dt2)); \
1029 g_date_time_unref (dt); \
1030 g_date_time_unref (dt2); \
1033 TEST_ADD_FULL (2009, 10, 21, 0, 0, 0,
1035 2010, 11, 22, 1, 1, 1);
1036 TEST_ADD_FULL (2000, 1, 1, 1, 1, 1,
1038 2000, 2, 1, 1, 1, 1);
1039 TEST_ADD_FULL (2000, 1, 1, 0, 0, 0,
1041 1999, 2, 1, 0, 0, 0);
1042 TEST_ADD_FULL (2010, 10, 31, 0, 0, 0,
1044 2011, 2, 28, 0, 0, 0);
1045 TEST_ADD_FULL (2010, 8, 25, 22, 45, 0,
1047 2010, 10, 2, 0, 10, 0);
1051 test_GDateTime_add_minutes (void)
1053 #define TEST_ADD_MINUTES(i,o) G_STMT_START { \
1054 GDateTime *dt, *dt2; \
1055 dt = g_date_time_new_local (2000, 1, 1, 0, 0, 0); \
1056 dt2 = g_date_time_add_minutes (dt, i); \
1057 g_assert_cmpint (o, ==, g_date_time_get_minute (dt2)); \
1058 g_date_time_unref (dt); \
1059 g_date_time_unref (dt2); \
1062 TEST_ADD_MINUTES (60, 0);
1063 TEST_ADD_MINUTES (100, 40);
1064 TEST_ADD_MINUTES (5, 5);
1065 TEST_ADD_MINUTES (1441, 1);
1066 TEST_ADD_MINUTES (-1441, 59);
1070 test_GDateTime_add_seconds (void)
1072 #define TEST_ADD_SECONDS(i,o) G_STMT_START { \
1073 GDateTime *dt, *dt2; \
1074 dt = g_date_time_new_local (2000, 1, 1, 0, 0, 0); \
1075 dt2 = g_date_time_add_seconds (dt, i); \
1076 g_assert_cmpint (o, ==, g_date_time_get_second (dt2)); \
1077 g_date_time_unref (dt); \
1078 g_date_time_unref (dt2); \
1081 TEST_ADD_SECONDS (1, 1);
1082 TEST_ADD_SECONDS (60, 0);
1083 TEST_ADD_SECONDS (61, 1);
1084 TEST_ADD_SECONDS (120, 0);
1085 TEST_ADD_SECONDS (-61, 59);
1086 TEST_ADD_SECONDS (86401, 1);
1087 TEST_ADD_SECONDS (-86401, 59);
1088 TEST_ADD_SECONDS (-31, 29);
1089 TEST_ADD_SECONDS (13, 13);
1093 test_GDateTime_diff (void)
1095 #define TEST_DIFF(y,m,d,y2,m2,d2,u) G_STMT_START { \
1096 GDateTime *dt1, *dt2; \
1098 dt1 = g_date_time_new_utc (y, m, d, 0, 0, 0); \
1099 dt2 = g_date_time_new_utc (y2, m2, d2, 0, 0, 0); \
1100 ts = g_date_time_difference (dt2, dt1); \
1101 g_assert_cmpint (ts, ==, u); \
1102 g_date_time_unref (dt1); \
1103 g_date_time_unref (dt2); \
1106 TEST_DIFF (2009, 1, 1, 2009, 2, 1, G_TIME_SPAN_DAY * 31);
1107 TEST_DIFF (2009, 1, 1, 2010, 1, 1, G_TIME_SPAN_DAY * 365);
1108 TEST_DIFF (2008, 2, 28, 2008, 2, 29, G_TIME_SPAN_DAY);
1109 TEST_DIFF (2008, 2, 29, 2008, 2, 28, -G_TIME_SPAN_DAY);
1111 /* TODO: Add usec tests */
1115 test_GDateTime_get_minute (void)
1119 dt = g_date_time_new_utc (2009, 12, 1, 1, 31, 0);
1120 g_assert_cmpint (31, ==, g_date_time_get_minute (dt));
1121 g_date_time_unref (dt);
1125 test_GDateTime_get_month (void)
1129 dt = g_date_time_new_utc (2009, 12, 1, 1, 31, 0);
1130 g_assert_cmpint (12, ==, g_date_time_get_month (dt));
1131 g_date_time_unref (dt);
1135 test_GDateTime_get_second (void)
1139 dt = g_date_time_new_utc (2009, 12, 1, 1, 31, 44);
1140 g_assert_cmpint (44, ==, g_date_time_get_second (dt));
1141 g_date_time_unref (dt);
1145 test_GDateTime_new_full (void)
1147 GTimeZone *tz, *dt_tz;
1151 LCID currLcid = GetThreadLocale ();
1152 LANGID currLangId = LANGIDFROMLCID (currLcid);
1153 LANGID en = MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US);
1154 SetThreadUILanguage (en);
1157 dt = g_date_time_new_utc (2009, 12, 11, 12, 11, 10);
1158 g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
1159 g_assert_cmpint (12, ==, g_date_time_get_month (dt));
1160 g_assert_cmpint (11, ==, g_date_time_get_day_of_month (dt));
1161 g_assert_cmpint (12, ==, g_date_time_get_hour (dt));
1162 g_assert_cmpint (11, ==, g_date_time_get_minute (dt));
1163 g_assert_cmpint (10, ==, g_date_time_get_second (dt));
1164 g_date_time_unref (dt);
1167 tz = g_time_zone_new ("America/Tijuana");
1168 #elif defined G_OS_WIN32
1169 tz = g_time_zone_new ("Pacific Standard Time");
1171 dt = g_date_time_new (tz, 2010, 11, 24, 8, 4, 0);
1173 dt_tz = g_date_time_get_timezone (dt);
1174 g_assert_cmpstr (g_time_zone_get_identifier (dt_tz), ==,
1175 g_time_zone_get_identifier (tz));
1177 g_assert_cmpint (2010, ==, g_date_time_get_year (dt));
1178 g_assert_cmpint (11, ==, g_date_time_get_month (dt));
1179 g_assert_cmpint (24, ==, g_date_time_get_day_of_month (dt));
1180 g_assert_cmpint (8, ==, g_date_time_get_hour (dt));
1181 g_assert_cmpint (4, ==, g_date_time_get_minute (dt));
1182 g_assert_cmpint (0, ==, g_date_time_get_second (dt));
1184 g_assert_cmpstr ("PST", ==, g_date_time_get_timezone_abbreviation (dt));
1185 g_assert_cmpstr ("America/Tijuana", ==, g_time_zone_get_identifier (dt_tz));
1186 #elif defined G_OS_WIN32
1187 g_assert_cmpstr ("Pacific Standard Time", ==,
1188 g_date_time_get_timezone_abbreviation (dt));
1189 g_assert_cmpstr ("Pacific Standard Time", ==,
1190 g_time_zone_get_identifier (dt_tz));
1191 SetThreadUILanguage (currLangId);
1193 g_assert (!g_date_time_is_daylight_savings (dt));
1194 g_date_time_unref (dt);
1195 g_time_zone_unref (tz);
1197 /* Check month limits */
1198 dt = g_date_time_new_utc (2016, 1, 31, 22, 10, 42);
1199 ASSERT_DATE (dt, 2016, 1, 31);
1200 g_date_time_unref (dt);
1201 dt = g_date_time_new_utc (2016, 1, 32, 22, 10, 42);
1203 dt = g_date_time_new_utc (2016, 2, 29, 22, 10, 42);
1204 ASSERT_DATE (dt, 2016, 2, 29);
1205 g_date_time_unref (dt);
1206 dt = g_date_time_new_utc (2016, 2, 30, 22, 10, 42);
1208 dt = g_date_time_new_utc (2017, 2, 28, 22, 10, 42);
1209 ASSERT_DATE (dt, 2017, 2, 28);
1210 g_date_time_unref (dt);
1211 dt = g_date_time_new_utc (2017, 2, 29, 22, 10, 42);
1213 dt = g_date_time_new_utc (2016, 3, 31, 22, 10, 42);
1214 ASSERT_DATE (dt, 2016, 3, 31);
1215 g_date_time_unref (dt);
1216 dt = g_date_time_new_utc (2016, 3, 32, 22, 10, 42);
1218 dt = g_date_time_new_utc (2016, 4, 30, 22, 10, 42);
1219 ASSERT_DATE (dt, 2016, 4, 30);
1220 g_date_time_unref (dt);
1221 dt = g_date_time_new_utc (2016, 4, 31, 22, 10, 42);
1223 dt = g_date_time_new_utc (2016, 5, 31, 22, 10, 42);
1224 ASSERT_DATE (dt, 2016, 5, 31);
1225 g_date_time_unref (dt);
1226 dt = g_date_time_new_utc (2016, 5, 32, 22, 10, 42);
1228 dt = g_date_time_new_utc (2016, 6, 30, 22, 10, 42);
1229 ASSERT_DATE (dt, 2016, 6, 30);
1230 g_date_time_unref (dt);
1231 dt = g_date_time_new_utc (2016, 6, 31, 22, 10, 42);
1233 dt = g_date_time_new_utc (2016, 7, 31, 22, 10, 42);
1234 ASSERT_DATE (dt, 2016, 7, 31);
1235 g_date_time_unref (dt);
1236 dt = g_date_time_new_utc (2016, 7, 32, 22, 10, 42);
1238 dt = g_date_time_new_utc (2016, 8, 31, 22, 10, 42);
1239 ASSERT_DATE (dt, 2016, 8, 31);
1240 g_date_time_unref (dt);
1241 dt = g_date_time_new_utc (2016, 8, 32, 22, 10, 42);
1243 dt = g_date_time_new_utc (2016, 9, 30, 22, 10, 42);
1244 ASSERT_DATE (dt, 2016, 9, 30);
1245 g_date_time_unref (dt);
1246 dt = g_date_time_new_utc (2016, 9, 31, 22, 10, 42);
1248 dt = g_date_time_new_utc (2016, 10, 31, 22, 10, 42);
1249 ASSERT_DATE (dt, 2016, 10, 31);
1250 g_date_time_unref (dt);
1251 dt = g_date_time_new_utc (2016, 10, 32, 22, 10, 42);
1253 dt = g_date_time_new_utc (2016, 11, 30, 22, 10, 42);
1254 ASSERT_DATE (dt, 2016, 11, 30);
1255 g_date_time_unref (dt);
1256 dt = g_date_time_new_utc (2016, 11, 31, 22, 10, 42);
1258 dt = g_date_time_new_utc (2016, 12, 31, 22, 10, 42);
1259 ASSERT_DATE (dt, 2016, 12, 31);
1260 g_date_time_unref (dt);
1261 dt = g_date_time_new_utc (2016, 12, 32, 22, 10, 42);
1266 test_GDateTime_now_utc (void)
1273 /* t <= dt.to_unix() <= after, but the inequalities might not be
1274 * equality if we're close to the boundary between seconds.
1275 * We loop until t == after (and hence dt.to_unix() should equal both)
1276 * to guard against that. */
1279 t = g_get_real_time () / G_TIME_SPAN_SECOND;
1280 #ifdef HAVE_GMTIME_R
1284 struct tm *tmp = gmtime (&t);
1285 /* Assume gmtime() can't fail as we got t from time(NULL). (Note
1286 * that on Windows, gmtime() *is* MT-safe, it uses a thread-local
1289 memcpy (&tm, tmp, sizeof (struct tm));
1292 dt = g_date_time_new_now_utc ();
1294 after = g_get_real_time () / G_TIME_SPAN_SECOND;
1298 g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
1299 g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
1300 g_assert_cmpint (tm.tm_mday, ==, g_date_time_get_day_of_month (dt));
1301 g_assert_cmpint (tm.tm_hour, ==, g_date_time_get_hour (dt));
1302 g_assert_cmpint (tm.tm_min, ==, g_date_time_get_minute (dt));
1303 g_assert_cmpint (tm.tm_sec, ==, g_date_time_get_second (dt));
1304 g_date_time_unref (dt);
1308 test_GDateTime_new_from_unix_utc (void)
1313 t = g_get_real_time ();
1316 dt = g_date_time_new_from_unix_utc (t);
1317 g_assert (dt == NULL);
1320 t = t / 1e6; /* oops, this was microseconds */
1322 dt = g_date_time_new_from_unix_utc (t);
1323 g_assert (dt != NULL);
1325 g_assert (dt == g_date_time_ref (dt));
1326 g_date_time_unref (dt);
1327 g_assert_cmpint (g_date_time_to_unix (dt), ==, t);
1328 g_date_time_unref (dt);
1332 test_GDateTime_get_utc_offset (void)
1334 #if defined (HAVE_STRUCT_TM_TM_GMTOFF) || defined (HAVE_STRUCT_TM___TM_GMTOFF)
1339 memset (&tm, 0, sizeof (tm));
1340 get_localtime_tm (g_get_real_time () / G_TIME_SPAN_SECOND, &tm);
1342 dt = g_date_time_new_now_local ();
1343 ts = g_date_time_get_utc_offset (dt);
1344 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
1345 g_assert_cmpint (ts, ==, (tm.tm_gmtoff * G_TIME_SPAN_SECOND));
1347 #ifdef HAVE_STRUCT_TM___TM_GMTOFF
1348 g_assert_cmpint (ts, ==, (tm.__tm_gmtoff * G_TIME_SPAN_SECOND));
1350 g_date_time_unref (dt);
1354 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1356 test_GDateTime_to_timeval (void)
1361 memset (&tv1, 0, sizeof (tv1));
1362 memset (&tv2, 0, sizeof (tv2));
1364 g_get_current_time (&tv1);
1365 dt = g_date_time_new_from_timeval_local (&tv1);
1366 g_date_time_to_timeval (dt, &tv2);
1367 g_assert_cmpint (tv1.tv_sec, ==, tv2.tv_sec);
1368 g_assert_cmpint (tv1.tv_usec, ==, tv2.tv_usec);
1369 g_date_time_unref (dt);
1371 G_GNUC_END_IGNORE_DEPRECATIONS
1374 test_GDateTime_to_local (void)
1376 GDateTime *utc = NULL, *now = NULL, *dt;
1377 time_t before, after;
1379 /* before <= utc.to_unix() <= now.to_unix() <= after, but the inequalities
1380 * might not be equality if we're close to the boundary between seconds.
1381 * We loop until before == after (and hence the GDateTimes should match)
1382 * to guard against that. */
1385 before = g_get_real_time () / G_TIME_SPAN_SECOND;
1386 g_clear_pointer (&utc, g_date_time_unref);
1387 g_clear_pointer (&now, g_date_time_unref);
1388 utc = g_date_time_new_now_utc ();
1389 now = g_date_time_new_now_local ();
1390 after = g_get_real_time () / G_TIME_SPAN_SECOND;
1392 while (before != after);
1394 dt = g_date_time_to_local (utc);
1396 g_assert_cmpint (g_date_time_get_year (now), ==, g_date_time_get_year (dt));
1397 g_assert_cmpint (g_date_time_get_month (now), ==, g_date_time_get_month (dt));
1398 g_assert_cmpint (g_date_time_get_day_of_month (now), ==, g_date_time_get_day_of_month (dt));
1399 g_assert_cmpint (g_date_time_get_hour (now), ==, g_date_time_get_hour (dt));
1400 g_assert_cmpint (g_date_time_get_minute (now), ==, g_date_time_get_minute (dt));
1401 g_assert_cmpint (g_date_time_get_second (now), ==, g_date_time_get_second (dt));
1403 g_date_time_unref (now);
1404 g_date_time_unref (utc);
1405 g_date_time_unref (dt);
1409 test_GDateTime_to_utc (void)
1411 GDateTime *dt, *dt2;
1416 g_assert_cmpint (t, !=, (time_t) -1);
1417 #ifdef HAVE_GMTIME_R
1421 struct tm *tmp = gmtime (&t);
1422 memcpy (&tm, tmp, sizeof (struct tm));
1425 dt2 = g_date_time_new_from_unix_local (t);
1426 dt = g_date_time_to_utc (dt2);
1427 g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
1428 g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
1429 g_assert_cmpint (tm.tm_mday, ==, g_date_time_get_day_of_month (dt));
1430 g_assert_cmpint (tm.tm_hour, ==, g_date_time_get_hour (dt));
1431 g_assert_cmpint (tm.tm_min, ==, g_date_time_get_minute (dt));
1432 g_assert_cmpint (tm.tm_sec, ==, g_date_time_get_second (dt));
1433 g_date_time_unref (dt);
1434 g_date_time_unref (dt2);
1438 test_GDateTime_get_day_of_year (void)
1440 #define TEST_DAY_OF_YEAR(y,m,d,o) G_STMT_START { \
1441 GDateTime *__dt = g_date_time_new_local ((y), (m), (d), 0, 0, 0); \
1442 g_assert_cmpint ((o), ==, g_date_time_get_day_of_year (__dt)); \
1443 g_date_time_unref (__dt); } G_STMT_END
1445 TEST_DAY_OF_YEAR (2009, 1, 1, 1);
1446 TEST_DAY_OF_YEAR (2009, 2, 1, 32);
1447 TEST_DAY_OF_YEAR (2009, 8, 16, 228);
1448 TEST_DAY_OF_YEAR (2008, 8, 16, 229);
1452 test_GDateTime_printf (void)
1454 /* 64 seems big, but one zoneinfo file, Factory, has an abbreviation
1455 * that long, and it will cause the test to fail if dst isn't big
1459 gchar *old_lc_messages;
1465 gchar *current_tz = NULL;
1466 DYNAMIC_TIME_ZONE_INFORMATION dtz_info;
1469 #define TEST_PRINTF(f,o) G_STMT_START { \
1470 GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
1471 gchar *__p = g_date_time_format (__dt, (f)); \
1472 g_assert_cmpstr (__p, ==, (o)); \
1473 g_date_time_unref (__dt); \
1474 g_free (__p); } G_STMT_END
1476 #define TEST_PRINTF_DATE(y,m,d,f,o) G_STMT_START { \
1477 GDateTime *dt = g_date_time_new_local (y, m, d, 0, 0, 0); \
1478 gchar *p = g_date_time_format (dt, (f)); \
1479 gchar *o_casefold = g_utf8_casefold (o, -1); \
1480 gchar *p_casefold = g_utf8_casefold (p, -1); \
1481 g_assert_cmpstr (p_casefold, ==, (o_casefold)); \
1482 g_date_time_unref (dt); \
1483 g_free (p_casefold); \
1484 g_free (o_casefold); \
1485 g_free (p); } G_STMT_END
1487 #define TEST_PRINTF_TIME(h,m,s,f,o) G_STMT_START { \
1488 GDateTime *dt = g_date_time_new_local (2009, 10, 24, (h), (m), (s)); \
1489 gchar *p = g_date_time_format (dt, (f)); \
1490 g_assert_cmpstr (p, ==, (o)); \
1491 g_date_time_unref (dt); \
1492 g_free (p); } G_STMT_END
1494 old_lc_all = g_strdup (g_getenv ("LC_ALL"));
1495 g_unsetenv ("LC_ALL");
1497 old_lc_messages = g_strdup (g_getenv ("LC_MESSAGES"));
1498 g_setenv ("LC_MESSAGES", "C", TRUE);
1501 * This is a little helper to make sure we can compare timezones to
1502 * that of the generated timezone.
1505 g_assert_cmpint (t, !=, (time_t) -1);
1506 memset (&tt, 0, sizeof(tt));
1507 get_localtime_tm (t, &tt);
1508 tt.tm_year = 2009 - 1900;
1509 tt.tm_mon = 9; /* 0 indexed */
1512 memset (&tt, 0, sizeof(tt));
1513 get_localtime_tm (t, &tt);
1514 strftime (dst, sizeof(dst), "%Z", &tt);
1516 /* get current time_t for 20090924 in the local timezone */
1522 TEST_PRINTF ("%a", "Sat");
1523 TEST_PRINTF ("%A", "Saturday");
1524 TEST_PRINTF ("%b", "Oct");
1525 TEST_PRINTF ("%B", "October");
1526 TEST_PRINTF ("%d", "24");
1527 TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
1528 TEST_PRINTF ("%e", "24"); // fixme
1529 TEST_PRINTF ("%h", "Oct");
1530 TEST_PRINTF ("%H", "00");
1531 TEST_PRINTF_TIME (15, 0, 0, "%H", "15");
1532 TEST_PRINTF ("%I", "12");
1533 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1534 TEST_PRINTF_TIME (15, 0, 0, "%I", "03");
1535 TEST_PRINTF ("%j", "297");
1536 TEST_PRINTF ("%k", " 0");
1537 TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
1538 TEST_PRINTF ("%l", "12");
1539 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1540 TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
1541 TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
1542 TEST_PRINTF ("%m", "10");
1543 TEST_PRINTF ("%M", "00");
1544 TEST_PRINTF ("%p", "AM");
1545 TEST_PRINTF_TIME (13, 13, 13, "%p", "PM");
1546 TEST_PRINTF ("%P", "am");
1547 TEST_PRINTF_TIME (13, 13, 13, "%P", "pm");
1548 TEST_PRINTF ("%r", "12:00:00 AM");
1549 TEST_PRINTF_TIME (13, 13, 13, "%r", "01:13:13 PM");
1550 TEST_PRINTF ("%R", "00:00");
1551 TEST_PRINTF_TIME (13, 13, 31, "%R", "13:13");
1552 TEST_PRINTF ("%S", "00");
1553 TEST_PRINTF ("%t", " ");
1554 TEST_PRINTF ("%u", "6");
1555 TEST_PRINTF ("%x", "10/24/09");
1556 TEST_PRINTF ("%X", "00:00:00");
1557 TEST_PRINTF_TIME (13, 14, 15, "%X", "13:14:15");
1558 TEST_PRINTF ("%y", "09");
1559 TEST_PRINTF ("%Y", "2009");
1560 TEST_PRINTF ("%%", "%");
1561 TEST_PRINTF ("%", "");
1562 TEST_PRINTF ("%9", NULL);
1564 TEST_PRINTF ("%Z", dst);
1565 #elif defined G_OS_WIN32
1566 g_assert (GetDynamicTimeZoneInformation (&dtz_info) != TIME_ZONE_ID_INVALID);
1567 if (wcscmp (dtz_info.StandardName, L"") != 0)
1568 current_tz = g_utf16_to_utf8 (dtz_info.StandardName, -1, NULL, NULL, NULL);
1570 current_tz = g_utf16_to_utf8 (dtz_info.DaylightName, -1, NULL, NULL, NULL);
1572 TEST_PRINTF ("%Z", current_tz);
1573 g_free (current_tz);
1576 if (old_lc_messages != NULL)
1577 g_setenv ("LC_MESSAGES", old_lc_messages, TRUE);
1579 g_unsetenv ("LC_MESSAGES");
1580 g_free (old_lc_messages);
1582 if (old_lc_all != NULL)
1583 g_setenv ("LC_ALL", old_lc_all, TRUE);
1584 g_free (old_lc_all);
1588 test_non_utf8_printf (void)
1592 /* If running uninstalled (G_TEST_BUILDDIR is set), skip this test, since we
1593 * need the translations to be installed. We can’t mess around with
1594 * bindtextdomain() here, as the compiled .gmo files in po/ are not in the
1595 * right installed directory hierarchy to be successfully loaded by gettext. */
1596 if (g_getenv ("G_TEST_BUILDDIR") != NULL)
1598 g_test_skip ("Skipping due to running uninstalled. "
1599 "This test can only be run when the translations are installed.");
1603 oldlocale = g_strdup (setlocale (LC_ALL, NULL));
1604 setlocale (LC_ALL, "ja_JP.eucjp");
1605 if (strstr (setlocale (LC_ALL, NULL), "ja_JP") == NULL)
1607 g_test_skip ("locale ja_JP.eucjp not available, skipping non-UTF8 tests");
1611 if (g_get_charset (NULL))
1613 g_test_skip ("locale ja_JP.eucjp may be available, but glib seems to think that it's equivalent to UTF-8, skipping non-UTF-8 tests. This is a known issue on Darwin");
1614 setlocale (LC_ALL, oldlocale);
1619 /* These are the outputs that ja_JP.UTF-8 generates; if everything
1620 * is working then ja_JP.eucjp should generate the same.
1622 TEST_PRINTF ("%a", "\345\234\237");
1623 TEST_PRINTF ("%A", "\345\234\237\346\233\234\346\227\245");
1624 #ifndef __APPLE__ /* OSX just returns the number */
1625 TEST_PRINTF ("%b", "10\346\234\210");
1627 TEST_PRINTF ("%B", "10\346\234\210");
1628 TEST_PRINTF ("%d", "24");
1629 TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
1630 TEST_PRINTF ("%e", "24"); // fixme
1631 #ifndef __APPLE__ /* OSX just returns the number */
1632 TEST_PRINTF ("%h", "10\346\234\210");
1634 TEST_PRINTF ("%H", "00");
1635 TEST_PRINTF_TIME (15, 0, 0, "%H", "15");
1636 TEST_PRINTF ("%I", "12");
1637 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1638 TEST_PRINTF_TIME (15, 0, 0, "%I", "03");
1639 TEST_PRINTF ("%j", "297");
1640 TEST_PRINTF ("%k", " 0");
1641 TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
1642 TEST_PRINTF ("%l", "12");
1643 TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
1644 TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
1645 TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
1646 TEST_PRINTF ("%m", "10");
1647 TEST_PRINTF ("%M", "00");
1648 #ifndef __APPLE__ /* OSX returns latin "AM", not japanese */
1649 TEST_PRINTF ("%p", "\345\215\210\345\211\215");
1650 TEST_PRINTF_TIME (13, 13, 13, "%p", "\345\215\210\345\276\214");
1651 TEST_PRINTF ("%P", "\345\215\210\345\211\215");
1652 TEST_PRINTF_TIME (13, 13, 13, "%P", "\345\215\210\345\276\214");
1653 TEST_PRINTF ("%r", "\345\215\210\345\211\21512\346\231\20200\345\210\20600\347\247\222");
1654 TEST_PRINTF_TIME (13, 13, 13, "%r", "\345\215\210\345\276\21401\346\231\20213\345\210\20613\347\247\222");
1656 TEST_PRINTF ("%R", "00:00");
1657 TEST_PRINTF_TIME (13, 13, 31, "%R", "13:13");
1658 TEST_PRINTF ("%S", "00");
1659 TEST_PRINTF ("%t", " ");
1660 TEST_PRINTF ("%u", "6");
1661 #ifndef __APPLE__ /* OSX returns YYYY/MM/DD in ASCII */
1662 TEST_PRINTF ("%x", "2009\345\271\26410\346\234\21024\346\227\245");
1664 TEST_PRINTF ("%X", "00\346\231\20200\345\210\20600\347\247\222");
1665 TEST_PRINTF_TIME (13, 14, 15, "%X", "13\346\231\20214\345\210\20615\347\247\222");
1666 TEST_PRINTF ("%y", "09");
1667 TEST_PRINTF ("%Y", "2009");
1668 TEST_PRINTF ("%%", "%");
1669 TEST_PRINTF ("%", "");
1670 TEST_PRINTF ("%9", NULL);
1672 setlocale (LC_ALL, oldlocale);
1676 /* Checks that it is possible to use format string that
1677 * is unrepresentable in current locale charset. */
1679 test_format_unrepresentable (void)
1681 gchar *oldlocale = g_strdup (setlocale (LC_ALL, NULL));
1682 setlocale (LC_ALL, "POSIX");
1684 TEST_PRINTF ("ąśćł", "ąśćł");
1686 /* We are using Unicode ratio symbol here, which is outside ASCII. */
1687 TEST_PRINTF_TIME (23, 15, 0, "%H∶%M", "23∶15");
1689 /* Test again, this time in locale with non ASCII charset. */
1690 if (setlocale (LC_ALL, "pl_PL.ISO-8859-2") != NULL)
1691 TEST_PRINTF_TIME (23, 15, 0, "%H∶%M", "23∶15");
1693 g_test_skip ("locale pl_PL.ISO-8859-2 not available, skipping test");
1695 setlocale (LC_ALL, oldlocale);
1700 test_modifiers (void)
1704 TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
1705 TEST_PRINTF_DATE (2009, 1, 1, "%_d", " 1");
1706 TEST_PRINTF_DATE (2009, 1, 1, "%-d", "1");
1707 TEST_PRINTF_DATE (2009, 1, 1, "%0d", "01");
1708 TEST_PRINTF_DATE (2009, 1, 21, "%d", "21");
1709 TEST_PRINTF_DATE (2009, 1, 21, "%_d", "21");
1710 TEST_PRINTF_DATE (2009, 1, 21, "%-d", "21");
1711 TEST_PRINTF_DATE (2009, 1, 21, "%0d", "21");
1713 TEST_PRINTF_DATE (2009, 1, 1, "%e", " 1");
1714 TEST_PRINTF_DATE (2009, 1, 1, "%_e", " 1");
1715 TEST_PRINTF_DATE (2009, 1, 1, "%-e", "1");
1716 TEST_PRINTF_DATE (2009, 1, 1, "%0e", "01");
1717 TEST_PRINTF_DATE (2009, 1, 21, "%e", "21");
1718 TEST_PRINTF_DATE (2009, 1, 21, "%_e", "21");
1719 TEST_PRINTF_DATE (2009, 1, 21, "%-e", "21");
1720 TEST_PRINTF_DATE (2009, 1, 21, "%0e", "21");
1722 TEST_PRINTF_TIME ( 1, 0, 0, "%H", "01");
1723 TEST_PRINTF_TIME ( 1, 0, 0, "%_H", " 1");
1724 TEST_PRINTF_TIME ( 1, 0, 0, "%-H", "1");
1725 TEST_PRINTF_TIME ( 1, 0, 0, "%0H", "01");
1726 TEST_PRINTF_TIME (21, 0, 0, "%H", "21");
1727 TEST_PRINTF_TIME (21, 0, 0, "%_H", "21");
1728 TEST_PRINTF_TIME (21, 0, 0, "%-H", "21");
1729 TEST_PRINTF_TIME (21, 0, 0, "%0H", "21");
1731 TEST_PRINTF_TIME ( 1, 0, 0, "%I", "01");
1732 TEST_PRINTF_TIME ( 1, 0, 0, "%_I", " 1");
1733 TEST_PRINTF_TIME ( 1, 0, 0, "%-I", "1");
1734 TEST_PRINTF_TIME ( 1, 0, 0, "%0I", "01");
1735 TEST_PRINTF_TIME (23, 0, 0, "%I", "11");
1736 TEST_PRINTF_TIME (23, 0, 0, "%_I", "11");
1737 TEST_PRINTF_TIME (23, 0, 0, "%-I", "11");
1738 TEST_PRINTF_TIME (23, 0, 0, "%0I", "11");
1740 TEST_PRINTF_TIME ( 1, 0, 0, "%k", " 1");
1741 TEST_PRINTF_TIME ( 1, 0, 0, "%_k", " 1");
1742 TEST_PRINTF_TIME ( 1, 0, 0, "%-k", "1");
1743 TEST_PRINTF_TIME ( 1, 0, 0, "%0k", "01");
1745 oldlocale = g_strdup (setlocale (LC_ALL, NULL));
1746 setlocale (LC_ALL, "fa_IR.utf-8");
1747 if (strstr (setlocale (LC_ALL, NULL), "fa_IR") != NULL)
1749 TEST_PRINTF_TIME (23, 0, 0, "%OH", "\333\262\333\263"); /* '23' */
1750 TEST_PRINTF_TIME (23, 0, 0, "%OI", "\333\261\333\261"); /* '11' */
1751 TEST_PRINTF_TIME (23, 0, 0, "%OM", "\333\260\333\260"); /* '00' */
1753 TEST_PRINTF_DATE (2011, 7, 1, "%Om", "\333\260\333\267"); /* '07' */
1754 TEST_PRINTF_DATE (2011, 7, 1, "%0Om", "\333\260\333\267"); /* '07' */
1755 TEST_PRINTF_DATE (2011, 7, 1, "%-Om", "\333\267"); /* '7' */
1756 TEST_PRINTF_DATE (2011, 7, 1, "%_Om", " \333\267"); /* ' 7' */
1759 g_test_skip ("locale fa_IR not available, skipping O modifier tests");
1760 setlocale (LC_ALL, oldlocale);
1764 /* Test that the `O` modifier for g_date_time_format() works with %B, %b and %h;
1765 * i.e. whether genitive month names are supported. */
1767 test_month_names (void)
1771 g_test_bug ("749206");
1773 /* If running uninstalled (G_TEST_BUILDDIR is set), skip this test, since we
1774 * need the translations to be installed. We can’t mess around with
1775 * bindtextdomain() here, as the compiled .gmo files in po/ are not in the
1776 * right installed directory hierarchy to be successfully loaded by gettext. */
1777 if (g_getenv ("G_TEST_BUILDDIR") != NULL)
1779 g_test_skip ("Skipping due to running uninstalled. "
1780 "This test can only be run when the translations are installed.");
1784 oldlocale = g_strdup (setlocale (LC_ALL, NULL));
1786 /* Make sure that nothing has been changed in western European languages. */
1787 setlocale (LC_ALL, "en_GB.utf-8");
1788 if (strstr (setlocale (LC_ALL, NULL), "en_GB") != NULL)
1790 TEST_PRINTF_DATE (2018, 1, 1, "%B", "January");
1791 TEST_PRINTF_DATE (2018, 2, 1, "%OB", "February");
1792 TEST_PRINTF_DATE (2018, 3, 1, "%b", "Mar");
1793 TEST_PRINTF_DATE (2018, 4, 1, "%Ob", "Apr");
1794 TEST_PRINTF_DATE (2018, 5, 1, "%h", "May");
1795 TEST_PRINTF_DATE (2018, 6, 1, "%Oh", "Jun");
1798 g_test_skip ("locale en_GB not available, skipping English month names test");
1800 setlocale (LC_ALL, "de_DE.utf-8");
1801 if (strstr (setlocale (LC_ALL, NULL), "de_DE") != NULL)
1803 TEST_PRINTF_DATE (2018, 7, 1, "%B", "Juli");
1804 TEST_PRINTF_DATE (2018, 8, 1, "%OB", "August");
1805 TEST_PRINTF_DATE (2018, 9, 1, "%b", "Sep");
1806 TEST_PRINTF_DATE (2018, 10, 1, "%Ob", "Okt");
1807 TEST_PRINTF_DATE (2018, 11, 1, "%h", "Nov");
1808 TEST_PRINTF_DATE (2018, 12, 1, "%Oh", "Dez");
1811 g_test_skip ("locale de_DE not available, skipping German month names test");
1813 setlocale (LC_ALL, "es_ES.utf-8");
1814 if (strstr (setlocale (LC_ALL, NULL), "es_ES") != NULL)
1816 TEST_PRINTF_DATE (2018, 1, 1, "%B", "enero");
1817 TEST_PRINTF_DATE (2018, 2, 1, "%OB", "febrero");
1818 TEST_PRINTF_DATE (2018, 3, 1, "%b", "mar");
1819 TEST_PRINTF_DATE (2018, 4, 1, "%Ob", "abr");
1820 TEST_PRINTF_DATE (2018, 5, 1, "%h", "may");
1821 TEST_PRINTF_DATE (2018, 6, 1, "%Oh", "jun");
1824 g_test_skip ("locale es_ES not available, skipping Spanish month names test");
1826 setlocale (LC_ALL, "fr_FR.utf-8");
1827 if (strstr (setlocale (LC_ALL, NULL), "fr_FR") != NULL)
1829 TEST_PRINTF_DATE (2018, 7, 1, "%B", "juillet");
1830 TEST_PRINTF_DATE (2018, 8, 1, "%OB", "août");
1831 TEST_PRINTF_DATE (2018, 9, 1, "%b", "sept.");
1832 TEST_PRINTF_DATE (2018, 10, 1, "%Ob", "oct.");
1833 TEST_PRINTF_DATE (2018, 11, 1, "%h", "nov.");
1834 TEST_PRINTF_DATE (2018, 12, 1, "%Oh", "déc.");
1837 g_test_skip ("locale fr_FR not available, skipping French month names test");
1839 /* Make sure that there are visible changes in some European languages. */
1840 setlocale (LC_ALL, "el_GR.utf-8");
1841 if (strstr (setlocale (LC_ALL, NULL), "el_GR") != NULL)
1843 TEST_PRINTF_DATE (2018, 1, 1, "%B", "Ιανουαρίου");
1844 TEST_PRINTF_DATE (2018, 2, 1, "%B", "Φεβρουαρίου");
1845 TEST_PRINTF_DATE (2018, 3, 1, "%B", "Μαρτίου");
1846 TEST_PRINTF_DATE (2018, 4, 1, "%OB", "Απρίλιος");
1847 TEST_PRINTF_DATE (2018, 5, 1, "%OB", "Μάιος");
1848 TEST_PRINTF_DATE (2018, 6, 1, "%OB", "Ιούνιος");
1849 TEST_PRINTF_DATE (2018, 7, 1, "%b", "Ιουλ");
1850 TEST_PRINTF_DATE (2018, 8, 1, "%Ob", "Αύγ");
1853 g_test_skip ("locale el_GR not available, skipping Greek month names test");
1855 setlocale (LC_ALL, "hr_HR.utf-8");
1856 if (strstr (setlocale (LC_ALL, NULL), "hr_HR") != NULL)
1858 TEST_PRINTF_DATE (2018, 5, 1, "%B", "svibnja");
1859 TEST_PRINTF_DATE (2018, 6, 1, "%B", "lipnja");
1860 TEST_PRINTF_DATE (2018, 7, 1, "%B", "srpnja");
1861 TEST_PRINTF_DATE (2018, 8, 1, "%OB", "Kolovoz");
1862 TEST_PRINTF_DATE (2018, 9, 1, "%OB", "Rujan");
1863 TEST_PRINTF_DATE (2018, 10, 1, "%OB", "Listopad");
1864 TEST_PRINTF_DATE (2018, 11, 1, "%b", "Stu");
1865 TEST_PRINTF_DATE (2018, 12, 1, "%Ob", "Pro");
1868 g_test_skip ("locale hr_HR not available, skipping Croatian month names test");
1870 setlocale (LC_ALL, "lt_LT.utf-8");
1871 if (strstr (setlocale (LC_ALL, NULL), "lt_LT") != NULL)
1873 TEST_PRINTF_DATE (2018, 1, 1, "%B", "sausio");
1874 TEST_PRINTF_DATE (2018, 2, 1, "%B", "vasario");
1875 TEST_PRINTF_DATE (2018, 3, 1, "%B", "kovo");
1876 TEST_PRINTF_DATE (2018, 4, 1, "%OB", "balandis");
1877 TEST_PRINTF_DATE (2018, 5, 1, "%OB", "gegužė");
1878 TEST_PRINTF_DATE (2018, 6, 1, "%OB", "birželis");
1879 TEST_PRINTF_DATE (2018, 7, 1, "%b", "liep.");
1880 TEST_PRINTF_DATE (2018, 8, 1, "%Ob", "rugp.");
1883 g_test_skip ("locale lt_LT not available, skipping Lithuanian month names test");
1885 setlocale (LC_ALL, "pl_PL.utf-8");
1886 if (strstr (setlocale (LC_ALL, NULL), "pl_PL") != NULL)
1888 TEST_PRINTF_DATE (2018, 5, 1, "%B", "maja");
1889 TEST_PRINTF_DATE (2018, 6, 1, "%B", "czerwca");
1890 TEST_PRINTF_DATE (2018, 7, 1, "%B", "lipca");
1891 TEST_PRINTF_DATE (2018, 8, 1, "%OB", "sierpień");
1892 TEST_PRINTF_DATE (2018, 9, 1, "%OB", "wrzesień");
1893 TEST_PRINTF_DATE (2018, 10, 1, "%OB", "październik");
1894 TEST_PRINTF_DATE (2018, 11, 1, "%b", "lis");
1895 TEST_PRINTF_DATE (2018, 12, 1, "%Ob", "gru");
1898 g_test_skip ("locale pl_PL not available, skipping Polish month names test");
1900 setlocale (LC_ALL, "ru_RU.utf-8");
1901 if (strstr (setlocale (LC_ALL, NULL), "ru_RU") != NULL)
1903 TEST_PRINTF_DATE (2018, 1, 1, "%B", "января");
1904 TEST_PRINTF_DATE (2018, 2, 1, "%B", "февраля");
1905 TEST_PRINTF_DATE (2018, 3, 1, "%B", "марта");
1906 TEST_PRINTF_DATE (2018, 4, 1, "%OB", "Апрель");
1907 TEST_PRINTF_DATE (2018, 5, 1, "%OB", "Май");
1908 TEST_PRINTF_DATE (2018, 6, 1, "%OB", "Июнь");
1909 TEST_PRINTF_DATE (2018, 7, 1, "%b", "июл");
1910 TEST_PRINTF_DATE (2018, 8, 1, "%Ob", "авг");
1911 /* This difference is very important in Russian: */
1912 TEST_PRINTF_DATE (2018, 5, 1, "%b", "мая");
1913 TEST_PRINTF_DATE (2018, 5, 1, "%Ob", "май");
1916 g_test_skip ("locale ru_RU not available, skipping Russian month names test");
1918 setlocale (LC_ALL, oldlocale);
1923 test_GDateTime_dst (void)
1925 GDateTime *dt1, *dt2;
1928 /* this date has the DST state set for Europe/London */
1930 tz = g_time_zone_new ("Europe/London");
1931 #elif defined G_OS_WIN32
1932 tz = g_time_zone_new ("GMT Standard Time");
1934 dt1 = g_date_time_new (tz, 2009, 8, 15, 3, 0, 1);
1935 g_assert (g_date_time_is_daylight_savings (dt1));
1936 g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, 3600);
1937 g_assert_cmpint (g_date_time_get_hour (dt1), ==, 3);
1939 /* add 6 months to clear the DST flag but keep the same time */
1940 dt2 = g_date_time_add_months (dt1, 6);
1941 g_assert (!g_date_time_is_daylight_savings (dt2));
1942 g_assert_cmpint (g_date_time_get_utc_offset (dt2) / G_USEC_PER_SEC, ==, 0);
1943 g_assert_cmpint (g_date_time_get_hour (dt2), ==, 3);
1945 g_date_time_unref (dt2);
1946 g_date_time_unref (dt1);
1948 /* now do the reverse: start with a non-DST state and move to DST */
1949 dt1 = g_date_time_new (tz, 2009, 2, 15, 2, 0, 1);
1950 g_assert (!g_date_time_is_daylight_savings (dt1));
1951 g_assert_cmpint (g_date_time_get_hour (dt1), ==, 2);
1953 dt2 = g_date_time_add_months (dt1, 6);
1954 g_assert (g_date_time_is_daylight_savings (dt2));
1955 g_assert_cmpint (g_date_time_get_hour (dt2), ==, 2);
1957 g_date_time_unref (dt2);
1958 g_date_time_unref (dt1);
1959 g_time_zone_unref (tz);
1962 static inline gboolean
1963 is_leap_year (gint year)
1965 g_assert (1 <= year && year <= 9999);
1967 return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
1971 days_in_month (gint year, gint month)
1973 const gint table[2][13] = {
1974 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
1975 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
1978 g_assert (1 <= month && month <= 12);
1980 return table[is_leap_year (year)][month];
1984 test_all_dates (void)
1986 gint year, month, day;
1987 GTimeZone *timezone;
1994 /* save some time by hanging on to this. */
1995 timezone = g_time_zone_new_utc ();
1997 unix_time = G_GINT64_CONSTANT(-62135596800);
1999 /* 0001-01-01 is 0001-W01-1 */
2005 /* The calendar makes a full cycle every 400 years, so we could
2006 * theoretically just test years 1 through 400. That assumes that our
2007 * software has no bugs, so probably we should just test them all. :)
2009 for (year = 1; year <= 9999; year++)
2013 for (month = 1; month <= 12; month++)
2014 for (day = 1; day <= days_in_month (year, month); day++)
2018 dt = g_date_time_new (timezone, year, month, day, 0, 0, 0);
2021 g_printerr ("%04d-%02d-%02d = %04d-W%02d-%d = %04d-%03d\n",
2023 week_year, week_num, weekday,
2028 if G_UNLIKELY (g_date_time_get_year (dt) != year ||
2029 g_date_time_get_month (dt) != month ||
2030 g_date_time_get_day_of_month (dt) != day)
2031 g_error ("%04d-%02d-%02d comes out as %04d-%02d-%02d",
2033 g_date_time_get_year (dt),
2034 g_date_time_get_month (dt),
2035 g_date_time_get_day_of_month (dt));
2037 if G_UNLIKELY (g_date_time_get_week_numbering_year (dt) != week_year ||
2038 g_date_time_get_week_of_year (dt) != week_num ||
2039 g_date_time_get_day_of_week (dt) != weekday)
2040 g_error ("%04d-%02d-%02d should be %04d-W%02d-%d but "
2041 "comes out as %04d-W%02d-%d", year, month, day,
2042 week_year, week_num, weekday,
2043 g_date_time_get_week_numbering_year (dt),
2044 g_date_time_get_week_of_year (dt),
2045 g_date_time_get_day_of_week (dt));
2047 if G_UNLIKELY (g_date_time_to_unix (dt) != unix_time)
2048 g_error ("%04d-%02d-%02d 00:00:00 UTC should have unix time %"
2049 G_GINT64_FORMAT " but comes out as %"G_GINT64_FORMAT,
2050 year, month, day, unix_time, g_date_time_to_unix (dt));
2052 if G_UNLIKELY (g_date_time_get_day_of_year (dt) != day_of_year)
2053 g_error ("%04d-%02d-%02d should be day of year %d"
2054 " but comes out as %d", year, month, day,
2055 day_of_year, g_date_time_get_day_of_year (dt));
2057 if G_UNLIKELY (g_date_time_get_hour (dt) != 0 ||
2058 g_date_time_get_minute (dt) != 0 ||
2059 g_date_time_get_seconds (dt) != 0)
2060 g_error ("%04d-%02d-%02d 00:00:00 UTC comes out "
2061 "as %02d:%02d:%02.6f", year, month, day,
2062 g_date_time_get_hour (dt),
2063 g_date_time_get_minute (dt),
2064 g_date_time_get_seconds (dt));
2067 /* add 24 hours to unix time */
2068 unix_time += 24 * 60 * 60;
2070 /* move day of year forward */
2073 /* move the week date forward */
2076 weekday = 1; /* Sunday -> Monday */
2078 /* NOTE: year/month/day is the final day of the week we
2081 * If we just finished the last week of last year then
2082 * we are definitely starting the first week of this
2085 * Otherwise, if we're still in this year, but Sunday
2086 * fell on or after December 28 then December 29, 30, 31
2087 * could be days within the next year's first year.
2089 if (year != week_year || (month == 12 && day >= 28))
2091 /* first week of the new year */
2099 g_date_time_unref (dt);
2103 g_time_zone_unref (timezone);
2113 g_test_bug ("642935");
2115 tz = g_time_zone_new ("-08:00");
2116 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
2118 p = g_date_time_format (dt, "%z");
2119 g_assert_cmpstr (p, ==, "-0800");
2122 p = g_date_time_format (dt, "%:z");
2123 g_assert_cmpstr (p, ==, "-08:00");
2126 p = g_date_time_format (dt, "%::z");
2127 g_assert_cmpstr (p, ==, "-08:00:00");
2130 p = g_date_time_format (dt, "%:::z");
2131 g_assert_cmpstr (p, ==, "-08");
2134 g_date_time_unref (dt);
2135 g_time_zone_unref (tz);
2137 tz = g_time_zone_new ("+00:00");
2138 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
2139 p = g_date_time_format (dt, "%:::z");
2140 g_assert_cmpstr (p, ==, "+00");
2142 g_date_time_unref (dt);
2143 g_time_zone_unref (tz);
2145 tz = g_time_zone_new ("+08:23");
2146 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
2147 p = g_date_time_format (dt, "%:::z");
2148 g_assert_cmpstr (p, ==, "+08:23");
2150 g_date_time_unref (dt);
2151 g_time_zone_unref (tz);
2153 tz = g_time_zone_new ("+08:23:45");
2154 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
2155 p = g_date_time_format (dt, "%:::z");
2156 g_assert_cmpstr (p, ==, "+08:23:45");
2158 g_date_time_unref (dt);
2159 g_time_zone_unref (tz);
2161 tz = g_time_zone_new ("-00:15");
2162 dt = g_date_time_new (tz, 1, 1, 1, 0, 0, 0);
2164 p = g_date_time_format (dt, "%z");
2165 g_assert_cmpstr (p, ==, "-0015");
2168 p = g_date_time_format (dt, "%:z");
2169 g_assert_cmpstr (p, ==, "-00:15");
2172 p = g_date_time_format (dt, "%::z");
2173 g_assert_cmpstr (p, ==, "-00:15:00");
2176 p = g_date_time_format (dt, "%:::z");
2177 g_assert_cmpstr (p, ==, "-00:15");
2180 g_date_time_unref (dt);
2181 g_time_zone_unref (tz);
2185 test_format_iso8601 (void)
2187 GTimeZone *tz = NULL;
2188 GDateTime *dt = NULL;
2191 tz = g_time_zone_new_utc ();
2192 dt = g_date_time_new (tz, 2019, 6, 26, 15, 1, 5);
2193 p = g_date_time_format_iso8601 (dt);
2194 g_assert_cmpstr (p, ==, "2019-06-26T15:01:05Z");
2196 g_date_time_unref (dt);
2197 g_time_zone_unref (tz);
2199 tz = g_time_zone_new_offset (-60 * 60);
2200 dt = g_date_time_new (tz, 2019, 6, 26, 15, 1, 5);
2201 p = g_date_time_format_iso8601 (dt);
2202 g_assert_cmpstr (p, ==, "2019-06-26T15:01:05-01");
2204 g_date_time_unref (dt);
2205 g_time_zone_unref (tz);
2208 #pragma GCC diagnostic push
2209 #pragma GCC diagnostic ignored "-Wformat-y2k"
2211 test_strftime (void)
2214 #define TEST_FORMAT \
2215 "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 " \
2216 "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 %%"
2219 /* 127997 is prime, 1315005118 is now */
2220 for (t = 0; t < 1315005118; t += 127997)
2222 GDateTime *date_time;
2226 date_time = g_date_time_new_from_unix_local (t);
2227 dt_str = g_date_time_format (date_time, TEST_FORMAT);
2228 strftime (c_str, sizeof c_str, TEST_FORMAT, localtime (&t));
2229 g_assert_cmpstr (c_str, ==, dt_str);
2230 g_date_time_unref (date_time);
2235 #pragma GCC diagnostic pop
2237 /* Check that g_date_time_format() correctly returns %NULL for format
2238 * placeholders which are not supported in the current locale. */
2240 test_GDateTime_strftime_error_handling (void)
2244 oldlocale = g_strdup (setlocale (LC_ALL, NULL));
2245 setlocale (LC_ALL, "de_DE.utf-8");
2246 if (strstr (setlocale (LC_ALL, NULL), "de_DE") != NULL)
2248 /* de_DE doesn’t ever write time in 12-hour notation, so %r is
2249 * unsupported for it. */
2250 TEST_PRINTF_TIME (23, 0, 0, "%r", NULL);
2253 g_test_skip ("locale de_DE not available, skipping error handling tests");
2254 setlocale (LC_ALL, oldlocale);
2259 test_find_interval (void)
2267 tz = g_time_zone_new ("America/Toronto");
2268 #elif defined G_OS_WIN32
2269 tz = g_time_zone_new ("Eastern Standard Time");
2271 dt = g_date_time_new_utc (2010, 11, 7, 1, 30, 0);
2272 u = g_date_time_to_unix (dt);
2274 i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, u);
2275 i2 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, u);
2277 g_assert_cmpint (i1, !=, i2);
2279 g_date_time_unref (dt);
2281 dt = g_date_time_new_utc (2010, 3, 14, 2, 0, 0);
2282 u = g_date_time_to_unix (dt);
2284 i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_STANDARD, u);
2285 g_assert_cmpint (i1, ==, -1);
2287 g_date_time_unref (dt);
2288 g_time_zone_unref (tz);
2292 test_adjust_time (void)
2300 tz = g_time_zone_new ("America/Toronto");
2301 #elif defined G_OS_WIN32
2302 tz = g_time_zone_new ("Eastern Standard Time");
2304 dt = g_date_time_new_utc (2010, 11, 7, 1, 30, 0);
2305 u = g_date_time_to_unix (dt);
2308 i1 = g_time_zone_find_interval (tz, G_TIME_TYPE_DAYLIGHT, u);
2309 i2 = g_time_zone_adjust_time (tz, G_TIME_TYPE_DAYLIGHT, &u2);
2311 g_assert_cmpint (i1, ==, i2);
2314 g_date_time_unref (dt);
2316 dt = g_date_time_new_utc (2010, 3, 14, 2, 30, 0);
2317 u2 = g_date_time_to_unix (dt);
2318 g_date_time_unref (dt);
2320 dt = g_date_time_new_utc (2010, 3, 14, 3, 0, 0);
2321 u = g_date_time_to_unix (dt);
2322 g_date_time_unref (dt);
2324 i1 = g_time_zone_adjust_time (tz, G_TIME_TYPE_DAYLIGHT, &u2);
2327 g_time_zone_unref (tz);
2331 test_no_header (void)
2335 tz = g_time_zone_new ("blabla");
2337 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2338 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
2339 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 0);
2340 g_assert (!g_time_zone_is_dst (tz, 0));
2342 g_time_zone_unref (tz);
2346 test_posix_parse (void)
2349 GDateTime *gdt1, *gdt2;
2351 /* Check that an unknown zone name falls back to UTC. */
2352 tz = g_time_zone_new ("nonexistent");
2353 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2354 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
2355 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 0);
2356 g_assert (!g_time_zone_is_dst (tz, 0));
2357 g_time_zone_unref (tz);
2359 /* An existent zone name should not fall back to UTC. */
2360 tz = g_time_zone_new ("PST8");
2361 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "PST8");
2362 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
2363 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
2364 g_assert (!g_time_zone_is_dst (tz, 0));
2365 g_time_zone_unref (tz);
2367 /* This fails rules_from_identifier on Unix (though not on Windows)
2368 * but passes anyway because PST8PDT is a zone name.
2370 tz = g_time_zone_new ("PST8PDT");
2371 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "PST8PDT");
2372 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
2373 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
2374 g_assert (!g_time_zone_is_dst (tz, 0));
2375 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "PDT");
2376 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==,- 7 * 3600);
2377 g_assert (g_time_zone_is_dst (tz, 1));
2378 g_time_zone_unref (tz);
2380 tz = g_time_zone_new ("PST8PDT6:32:15");
2382 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "PST8PDT6:32:15");
2383 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "PST");
2384 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, - 8 * 3600);
2385 g_assert (!g_time_zone_is_dst (tz, 0));
2386 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "PDT");
2387 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, - 6 * 3600 - 32 *60 - 15);
2388 g_assert (g_time_zone_is_dst (tz, 1));
2389 gdt1 = g_date_time_new (tz, 2012, 12, 6, 11, 15, 23.0);
2390 gdt2 = g_date_time_new (tz, 2012, 6, 6, 11, 15, 23.0);
2391 g_assert (!g_date_time_is_daylight_savings (gdt1));
2392 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, -28800);
2393 g_assert (g_date_time_is_daylight_savings (gdt2));
2394 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, -23535);
2395 g_date_time_unref (gdt1);
2396 g_date_time_unref (gdt2);
2398 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2399 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "UTC");
2400 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 0);
2401 g_assert (!g_time_zone_is_dst (tz, 0));
2403 g_time_zone_unref (tz);
2405 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0");
2406 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0");
2407 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
2408 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
2409 g_assert (!g_time_zone_is_dst (tz, 0));
2410 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
2411 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
2412 g_assert (g_time_zone_is_dst (tz, 1));
2413 gdt1 = g_date_time_new (tz, 2012, 3, 18, 0, 15, 23.0);
2414 gdt2 = g_date_time_new (tz, 2012, 3, 18, 3, 15, 23.0);
2415 g_assert (g_date_time_is_daylight_savings (gdt1));
2416 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2417 g_assert (!g_date_time_is_daylight_savings (gdt2));
2418 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2419 g_date_time_unref (gdt1);
2420 g_date_time_unref (gdt2);
2421 gdt1 = g_date_time_new (tz, 2012, 10, 7, 3, 15, 23.0);
2422 gdt2 = g_date_time_new (tz, 2012, 10, 7, 1, 15, 23.0);
2423 g_assert (g_date_time_is_daylight_savings (gdt1));
2424 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2425 g_assert (!g_date_time_is_daylight_savings (gdt2));
2426 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2427 g_date_time_unref (gdt1);
2428 g_date_time_unref (gdt2);
2429 g_time_zone_unref (tz);
2431 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,280,77");
2432 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "NZST-12:00:00NZDT-13:00:00,280,77");
2433 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
2434 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
2435 g_assert (!g_time_zone_is_dst (tz, 0));
2436 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
2437 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
2438 g_assert (g_time_zone_is_dst (tz, 1));
2439 gdt1 = g_date_time_new (tz, 2012, 3, 18, 0, 15, 23.0);
2440 gdt2 = g_date_time_new (tz, 2012, 3, 18, 3, 15, 23.0);
2441 g_assert (g_date_time_is_daylight_savings (gdt1));
2442 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2443 g_assert (!g_date_time_is_daylight_savings (gdt2));
2444 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2445 g_date_time_unref (gdt1);
2446 g_date_time_unref (gdt2);
2447 gdt1 = g_date_time_new (tz, 2012, 10, 7, 3, 15, 23.0);
2448 gdt2 = g_date_time_new (tz, 2012, 10, 7, 1, 15, 23.0);
2449 g_assert (g_date_time_is_daylight_savings (gdt1));
2450 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2451 g_assert (!g_date_time_is_daylight_savings (gdt2));
2452 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2453 g_date_time_unref (gdt1);
2454 g_date_time_unref (gdt2);
2455 g_time_zone_unref (tz);
2457 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,J279,J76");
2458 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "NZST-12:00:00NZDT-13:00:00,J279,J76");
2459 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
2460 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
2461 g_assert (!g_time_zone_is_dst (tz, 0));
2462 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
2463 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
2464 g_assert (g_time_zone_is_dst (tz, 1));
2465 gdt1 = g_date_time_new (tz, 2012, 3, 18, 0, 15, 23.0);
2466 gdt2 = g_date_time_new (tz, 2012, 3, 18, 3, 15, 23.0);
2467 g_assert (g_date_time_is_daylight_savings (gdt1));
2468 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2469 g_assert (!g_date_time_is_daylight_savings (gdt2));
2470 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2471 g_date_time_unref (gdt1);
2472 g_date_time_unref (gdt2);
2473 gdt1 = g_date_time_new (tz, 2012, 10, 7, 3, 15, 23.0);
2474 gdt2 = g_date_time_new (tz, 2012, 10, 7, 1, 15, 23.0);
2475 g_assert (g_date_time_is_daylight_savings (gdt1));
2476 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2477 g_assert (!g_date_time_is_daylight_savings (gdt2));
2478 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2479 g_date_time_unref (gdt1);
2480 g_date_time_unref (gdt2);
2481 g_time_zone_unref (tz);
2483 tz = g_time_zone_new ("NZST-12:00:00NZDT-13:00:00,M10.1.0/07:00,M3.3.0/07:00");
2484 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "NZST-12:00:00NZDT-13:00:00,M10.1.0/07:00,M3.3.0/07:00");
2485 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 0), ==, "NZST");
2486 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, 12 * 3600);
2487 g_assert (!g_time_zone_is_dst (tz, 0));
2488 g_assert_cmpstr (g_time_zone_get_abbreviation (tz, 1), ==, "NZDT");
2489 g_assert_cmpint (g_time_zone_get_offset (tz, 1), ==, 13 * 3600);
2490 g_assert (g_time_zone_is_dst (tz, 1));
2491 gdt1 = g_date_time_new (tz, 2012, 3, 18, 5, 15, 23.0);
2492 gdt2 = g_date_time_new (tz, 2012, 3, 18, 8, 15, 23.0);
2493 g_assert (g_date_time_is_daylight_savings (gdt1));
2494 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2495 g_assert (!g_date_time_is_daylight_savings (gdt2));
2496 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2497 g_date_time_unref (gdt1);
2498 g_date_time_unref (gdt2);
2499 gdt1 = g_date_time_new (tz, 2012, 10, 7, 8, 15, 23.0);
2500 gdt2 = g_date_time_new (tz, 2012, 10, 7, 6, 15, 23.0);
2501 g_assert (g_date_time_is_daylight_savings (gdt1));
2502 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2503 g_assert (!g_date_time_is_daylight_savings (gdt2));
2504 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2505 g_date_time_unref (gdt1);
2506 g_date_time_unref (gdt2);
2507 gdt1 = g_date_time_new (tz, 1902, 10, 7, 8, 15, 23.0);
2508 gdt2 = g_date_time_new (tz, 1902, 10, 7, 6, 15, 23.0);
2509 g_assert (!g_date_time_is_daylight_savings (gdt1));
2510 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 43200);
2511 g_assert (!g_date_time_is_daylight_savings (gdt2));
2512 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2513 g_date_time_unref (gdt1);
2514 g_date_time_unref (gdt2);
2515 gdt1 = g_date_time_new (tz, 2142, 10, 7, 8, 15, 23.0);
2516 gdt2 = g_date_time_new (tz, 2142, 10, 7, 6, 15, 23.0);
2517 g_assert (g_date_time_is_daylight_savings (gdt1));
2518 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 46800);
2519 g_assert (!g_date_time_is_daylight_savings (gdt2));
2520 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2521 g_date_time_unref (gdt1);
2522 g_date_time_unref (gdt2);
2523 gdt1 = g_date_time_new (tz, 3212, 10, 7, 8, 15, 23.0);
2524 gdt2 = g_date_time_new (tz, 3212, 10, 7, 6, 15, 23.0);
2525 g_assert (!g_date_time_is_daylight_savings (gdt1));
2526 g_assert_cmpint (g_date_time_get_utc_offset (gdt1) / 1000000, ==, 43200);
2527 g_assert (!g_date_time_is_daylight_savings (gdt2));
2528 g_assert_cmpint (g_date_time_get_utc_offset (gdt2) / 1000000, ==, 43200);
2529 g_date_time_unref (gdt1);
2530 g_date_time_unref (gdt2);
2531 g_time_zone_unref (tz);
2535 test_GDateTime_floating_point (void)
2540 g_test_bug ("697715");
2542 tz = g_time_zone_new ("-03:00");
2543 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "-03:00");
2544 dt = g_date_time_new (tz, 2010, 5, 24, 8, 0, 1.000001);
2545 g_time_zone_unref (tz);
2546 g_assert_cmpint (g_date_time_get_microsecond (dt), ==, 1);
2547 g_date_time_unref (dt);
2550 /* Check that g_time_zone_get_identifier() returns the identifier given to
2551 * g_time_zone_new(), or "UTC" if loading the timezone failed. */
2553 test_identifier (void)
2556 gchar *old_tz = g_strdup (g_getenv ("TZ"));
2559 const char *recife_tz = "SA Eastern Standard Time";
2561 const char *recife_tz = "America/Recife";
2564 tz = g_time_zone_new ("UTC");
2565 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2566 g_time_zone_unref (tz);
2568 tz = g_time_zone_new_utc ();
2569 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2570 g_time_zone_unref (tz);
2572 tz = g_time_zone_new ("some rubbish");
2573 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2574 g_time_zone_unref (tz);
2576 tz = g_time_zone_new ("Z");
2577 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "Z");
2578 g_time_zone_unref (tz);
2580 tz = g_time_zone_new ("+03:15");
2581 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "+03:15");
2582 g_time_zone_unref (tz);
2584 /* System timezone. We can’t change this, but we can at least assert that
2585 * the identifier is non-NULL and doesn’t start with a slash. */
2586 tz = g_time_zone_new (NULL);
2587 g_assert_nonnull (g_time_zone_get_identifier (tz));
2588 g_assert_cmpstr (g_time_zone_get_identifier (tz), !=, "");
2589 g_assert_true (*g_time_zone_get_identifier (tz) != '/');
2590 g_time_zone_unref (tz);
2592 /* Local timezone tests. */
2593 if (g_setenv ("TZ", recife_tz, TRUE))
2595 tz = g_time_zone_new_local ();
2596 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, recife_tz);
2597 g_time_zone_unref (tz);
2600 if (g_setenv ("TZ", "some rubbish", TRUE))
2602 tz = g_time_zone_new_local ();
2603 g_assert_cmpstr (g_time_zone_get_identifier (tz), ==, "UTC");
2604 g_time_zone_unref (tz);
2608 g_assert_true (g_setenv ("TZ", old_tz, TRUE));
2615 /* Test various calls to g_time_zone_new_offset(). */
2617 test_new_offset (void)
2619 const gint32 vectors[] =
2635 for (i = 0; i < G_N_ELEMENTS (vectors); i++)
2637 GTimeZone *tz = NULL;
2639 g_test_message ("Vector %" G_GSIZE_FORMAT ": %d", i, vectors[i]);
2641 tz = g_time_zone_new_offset (vectors[i]);
2642 g_assert_nonnull (tz);
2643 g_assert_cmpstr (g_time_zone_get_identifier (tz), !=, "UTC");
2644 g_assert_cmpint (g_time_zone_get_offset (tz, 0), ==, vectors[i]);
2645 g_time_zone_unref (tz);
2653 /* In glibc, LANGUAGE is used as highest priority guess for category value.
2654 * Unset it to avoid interference with tests using setlocale and translation. */
2655 g_unsetenv ("LANGUAGE");
2657 g_test_init (&argc, &argv, NULL);
2658 g_test_bug_base ("http://bugzilla.gnome.org/");
2660 /* GDateTime Tests */
2661 bind_textdomain_codeset ("glib20", "UTF-8");
2663 g_test_add_func ("/GDateTime/invalid", test_GDateTime_invalid);
2664 g_test_add_func ("/GDateTime/add_days", test_GDateTime_add_days);
2665 g_test_add_func ("/GDateTime/add_full", test_GDateTime_add_full);
2666 g_test_add_func ("/GDateTime/add_hours", test_GDateTime_add_hours);
2667 g_test_add_func ("/GDateTime/add_minutes", test_GDateTime_add_minutes);
2668 g_test_add_func ("/GDateTime/add_months", test_GDateTime_add_months);
2669 g_test_add_func ("/GDateTime/add_seconds", test_GDateTime_add_seconds);
2670 g_test_add_func ("/GDateTime/add_weeks", test_GDateTime_add_weeks);
2671 g_test_add_func ("/GDateTime/add_years", test_GDateTime_add_years);
2672 g_test_add_func ("/GDateTime/compare", test_GDateTime_compare);
2673 g_test_add_func ("/GDateTime/diff", test_GDateTime_diff);
2674 g_test_add_func ("/GDateTime/equal", test_GDateTime_equal);
2675 g_test_add_func ("/GDateTime/get_day_of_week", test_GDateTime_get_day_of_week);
2676 g_test_add_func ("/GDateTime/get_day_of_month", test_GDateTime_get_day_of_month);
2677 g_test_add_func ("/GDateTime/get_day_of_year", test_GDateTime_get_day_of_year);
2678 g_test_add_func ("/GDateTime/get_hour", test_GDateTime_get_hour);
2679 g_test_add_func ("/GDateTime/get_microsecond", test_GDateTime_get_microsecond);
2680 g_test_add_func ("/GDateTime/get_minute", test_GDateTime_get_minute);
2681 g_test_add_func ("/GDateTime/get_month", test_GDateTime_get_month);
2682 g_test_add_func ("/GDateTime/get_second", test_GDateTime_get_second);
2683 g_test_add_func ("/GDateTime/get_utc_offset", test_GDateTime_get_utc_offset);
2684 g_test_add_func ("/GDateTime/get_year", test_GDateTime_get_year);
2685 g_test_add_func ("/GDateTime/hash", test_GDateTime_hash);
2686 g_test_add_func ("/GDateTime/new_from_unix", test_GDateTime_new_from_unix);
2687 g_test_add_func ("/GDateTime/new_from_unix_utc", test_GDateTime_new_from_unix_utc);
2688 g_test_add_func ("/GDateTime/new_from_unix/overflow", test_GDateTime_new_from_unix_overflow);
2689 g_test_add_func ("/GDateTime/new_from_timeval", test_GDateTime_new_from_timeval);
2690 g_test_add_func ("/GDateTime/new_from_timeval_utc", test_GDateTime_new_from_timeval_utc);
2691 g_test_add_func ("/GDateTime/new_from_timeval/overflow", test_GDateTime_new_from_timeval_overflow);
2692 g_test_add_func ("/GDateTime/new_from_iso8601", test_GDateTime_new_from_iso8601);
2693 g_test_add_func ("/GDateTime/new_from_iso8601/2", test_GDateTime_new_from_iso8601_2);
2694 g_test_add_func ("/GDateTime/new_full", test_GDateTime_new_full);
2695 g_test_add_func ("/GDateTime/now", test_GDateTime_now);
2696 g_test_add_func ("/GDateTime/printf", test_GDateTime_printf);
2697 g_test_add_func ("/GDateTime/non_utf8_printf", test_non_utf8_printf);
2698 g_test_add_func ("/GDateTime/format_unrepresentable", test_format_unrepresentable);
2699 g_test_add_func ("/GDateTime/format_iso8601", test_format_iso8601);
2700 g_test_add_func ("/GDateTime/strftime", test_strftime);
2701 g_test_add_func ("/GDateTime/strftime/error_handling", test_GDateTime_strftime_error_handling);
2702 g_test_add_func ("/GDateTime/modifiers", test_modifiers);
2703 g_test_add_func ("/GDateTime/month_names", test_month_names);
2704 g_test_add_func ("/GDateTime/to_local", test_GDateTime_to_local);
2705 g_test_add_func ("/GDateTime/to_unix", test_GDateTime_to_unix);
2706 g_test_add_func ("/GDateTime/to_timeval", test_GDateTime_to_timeval);
2707 g_test_add_func ("/GDateTime/to_utc", test_GDateTime_to_utc);
2708 g_test_add_func ("/GDateTime/now_utc", test_GDateTime_now_utc);
2709 g_test_add_func ("/GDateTime/dst", test_GDateTime_dst);
2710 g_test_add_func ("/GDateTime/test_z", test_z);
2711 g_test_add_func ("/GDateTime/test-all-dates", test_all_dates);
2712 g_test_add_func ("/GTimeZone/find-interval", test_find_interval);
2713 g_test_add_func ("/GTimeZone/adjust-time", test_adjust_time);
2714 g_test_add_func ("/GTimeZone/no-header", test_no_header);
2715 g_test_add_func ("/GTimeZone/posix-parse", test_posix_parse);
2716 g_test_add_func ("/GTimeZone/floating-point", test_GDateTime_floating_point);
2717 g_test_add_func ("/GTimeZone/identifier", test_identifier);
2718 g_test_add_func ("/GTimeZone/new-offset", test_new_offset);
2720 return g_test_run ();