datetime: Update modifiers for DST changes
[platform/upstream/glib.git] / glib / tests / gdatetime.c
1 /* gdatetime-tests.c
2  *
3  * Copyright (C) 2009-2010 Christian Hergert <chris@dronelabs.com>
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <time.h>
24 #include <glib.h>
25 #include <glib/gstdio.h>
26
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))); \
31 } G_STMT_END
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))); \
36 } G_STMT_END
37
38 static void
39 get_localtime_tm (time_t     time_,
40                   struct tm *retval)
41 {
42 #ifdef HAVE_LOCALTIME_R
43   localtime_r (&time_, retval);
44 #else
45   {
46     struct tm *ptm = localtime (&time_);
47
48     if (ptm == NULL)
49       {
50         /* Happens at least in Microsoft's C library if you pass a
51          * negative time_t. Use 2000-01-01 as default date.
52          */
53 #ifndef G_DISABLE_CHECKS
54         g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, "ptm != NULL");
55 #endif
56
57         retval->tm_mon = 0;
58         retval->tm_mday = 1;
59         retval->tm_year = 100;
60       }
61     else
62       memcpy ((void *) retval, (void *) ptm, sizeof (struct tm));
63   }
64 #endif /* HAVE_LOCALTIME_R */
65 }
66
67 static void
68 test_GDateTime_now (void)
69 {
70   GDateTime *dt;
71   struct tm tm;
72
73   memset (&tm, 0, sizeof (tm));
74   get_localtime_tm (time (NULL), &tm);
75
76   dt = g_date_time_new_now ();
77
78   g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
79   g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
80   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
81   g_assert_cmpint (g_date_time_get_hour (dt), ==, tm.tm_hour);
82   g_assert_cmpint (g_date_time_get_minute (dt), ==, tm.tm_min);
83   /* XXX we need some fuzzyness here */
84   g_assert_cmpint (g_date_time_get_second (dt), >=, tm.tm_sec);
85
86   g_date_time_unref (dt);
87 }
88
89 static void
90 test_GDateTime_today (void)
91 {
92   GDateTime *dt;
93   struct tm tm;
94
95   memset (&tm, 0, sizeof (tm));
96   get_localtime_tm (time (NULL), &tm);
97
98   dt = g_date_time_new_today ();
99   g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
100   g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
101   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
102   g_assert_cmpint (g_date_time_get_hour (dt), ==, 0);
103   g_assert_cmpint (g_date_time_get_minute (dt), ==, 0);
104   g_assert_cmpint (g_date_time_get_second (dt), ==, 0);
105   g_assert_cmpint (g_date_time_get_millisecond (dt), ==, 0);
106   g_date_time_unref (dt);
107 }
108
109 static void
110 test_GDateTime_new_from_epoch (void)
111 {
112   GDateTime *dt;
113   struct tm  tm;
114   time_t     t;
115
116   memset (&tm, 0, sizeof (tm));
117   t = time (NULL);
118   get_localtime_tm (t, &tm);
119
120   dt = g_date_time_new_from_epoch (t);
121   g_assert_cmpint (g_date_time_get_year (dt), ==, 1900 + tm.tm_year);
122   g_assert_cmpint (g_date_time_get_month (dt), ==, 1 + tm.tm_mon);
123   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, tm.tm_mday);
124   g_assert_cmpint (g_date_time_get_hour (dt), ==, tm.tm_hour);
125   g_assert_cmpint (g_date_time_get_minute (dt), ==, tm.tm_min);
126   g_assert_cmpint (g_date_time_get_second (dt), ==, tm.tm_sec);
127   g_date_time_unref (dt);
128
129   memset (&tm, 0, sizeof (tm));
130   tm.tm_year = 70;
131   tm.tm_mday = 1;
132   tm.tm_mon = 0;
133   tm.tm_hour = 0;
134   tm.tm_min = 0;
135   tm.tm_sec = 0;
136   t = mktime (&tm);
137
138   dt = g_date_time_new_from_epoch (t);
139   g_assert_cmpint (g_date_time_get_year (dt), ==, 1970);
140   g_assert_cmpint (g_date_time_get_month (dt), ==, 1);
141   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 1);
142   g_assert_cmpint (g_date_time_get_hour (dt), ==, 0);
143   g_assert_cmpint (g_date_time_get_minute (dt), ==, 0);
144   g_assert_cmpint (g_date_time_get_second (dt), ==, 0);
145   g_date_time_unref (dt);
146 }
147
148 static void
149 test_GDateTime_is_leap_year (void)
150 {
151   GDateTime *dt;
152   gint       i;
153
154   for (i = 1; i <= 3000; i++)
155     {
156       dt = g_date_time_new_from_date (i, 1, 1);
157       if ((((i % 4) == 0) && ((i % 100) != 0)) || ((i % 400) == 0))
158         g_assert (g_date_time_is_leap_year (dt));
159       else
160         g_assert (!g_date_time_is_leap_year (dt));
161       g_date_time_unref (dt);
162     }
163 }
164
165 static void
166 test_GDateTime_compare (void)
167 {
168   GDateTime *dt1, *dt2;
169   gint       i;
170
171   dt1 = g_date_time_new_from_date (2000, 1, 1);
172
173   for (i = 1; i < 2000; i++)
174     {
175       dt2 = g_date_time_new_from_date (i, 12, 31);
176       g_assert_cmpint (1, ==, g_date_time_compare (dt1, dt2));
177       g_date_time_unref (dt2);
178     }
179
180   dt2 = g_date_time_new_full (1999, 12, 31, 23, 59, 59, NULL);
181   g_assert_cmpint (1, ==, g_date_time_compare (dt1, dt2));
182   g_date_time_unref (dt2);
183
184   dt2 = g_date_time_new_full (2000, 1, 1, 0, 0, 1, NULL);
185   g_assert_cmpint (-1, ==, g_date_time_compare (dt1, dt2));
186   g_date_time_unref (dt2);
187
188   dt2 = g_date_time_new_full (2000, 1, 1, 0, 0, 0, NULL);
189   g_assert_cmpint (0, ==, g_date_time_compare (dt1, dt2));
190   g_date_time_unref (dt2);
191   g_date_time_unref (dt1);
192 }
193
194 static void
195 test_GDateTime_date (void)
196 {
197   GDateTime *dt1, *dt2;
198
199   dt1 = g_date_time_new_full (2009, 10, 19, 13, 0, 55, NULL);
200   dt2 = g_date_time_day (dt1);
201   g_assert (dt1 != NULL);
202   g_assert (dt2 != NULL);
203   g_assert_cmpint (2009, ==, g_date_time_get_year (dt2));
204   g_assert_cmpint (10, ==, g_date_time_get_month (dt2));
205   g_assert_cmpint (19, ==, g_date_time_get_day_of_month (dt2));
206   g_assert_cmpint (0, ==, g_date_time_get_hour (dt2));
207   g_assert_cmpint (0, ==, g_date_time_get_minute (dt2));
208   g_assert_cmpint (0, ==, g_date_time_get_second (dt2));
209   g_date_time_unref (dt1);
210   g_date_time_unref (dt2);
211 }
212
213 static void
214 test_GDateTime_equal (void)
215 {
216   GDateTime *dt1, *dt2;
217   GTimeZone *time_zone;
218
219   dt1 = g_date_time_new_from_date (2009, 10, 19);
220   dt2 = g_date_time_new_from_date (2009, 10, 19);
221   g_assert (g_date_time_equal (dt1, dt2));
222   g_date_time_unref (dt1);
223   g_date_time_unref (dt2);
224
225   dt1 = g_date_time_new_from_date (2009, 10, 18);
226   dt2 = g_date_time_new_from_date (2009, 10, 19);
227   g_assert (!g_date_time_equal (dt1, dt2));
228   g_date_time_unref (dt1);
229   g_date_time_unref (dt2);
230
231   /* UTC-0300 and not in DST */
232   time_zone = g_time_zone_new (-3 * 3600, FALSE);
233   dt1 = g_date_time_new_full (2010, 5, 24,  8, 0, 0, time_zone);
234   g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, (-3 * 3600));
235   /* UTC */
236   dt2 = g_date_time_new_full (2010, 5, 24, 11, 0, 0, NULL);
237   g_assert_cmpint (g_date_time_get_utc_offset (dt2), ==, 0);
238
239   g_assert (g_date_time_equal (dt1, dt2));
240   g_date_time_unref (dt1);
241   g_time_zone_free (time_zone);
242
243   /* America/Recife is in UTC-0300 */
244   time_zone = g_time_zone_new_for_name ("America/Recife");
245   dt1 = g_date_time_new_full (2010, 5, 24,  8, 0, 0, time_zone);
246   g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, (-3 * 3600));
247   g_assert (g_date_time_equal (dt1, dt2));
248   g_date_time_unref (dt1);
249   g_date_time_unref (dt2);
250   g_time_zone_free (time_zone);
251 }
252
253 static void
254 test_GDateTime_get_day_of_week (void)
255 {
256   GDateTime *dt;
257
258   dt = g_date_time_new_from_date (2009, 10, 19);
259   g_assert_cmpint (1, ==, g_date_time_get_day_of_week (dt));
260   g_date_time_unref (dt);
261
262   dt = g_date_time_new_from_date (2000, 10, 1);
263   g_assert_cmpint (7, ==, g_date_time_get_day_of_week (dt));
264   g_date_time_unref (dt);
265 }
266
267 static void
268 test_GDateTime_get_day_of_month (void)
269 {
270   GDateTime *dt;
271
272   dt = g_date_time_new_from_date (2009, 10, 19);
273   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 19);
274   g_date_time_unref (dt);
275
276   dt = g_date_time_new_from_date (1400, 3, 12);
277   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 12);
278   g_date_time_unref (dt);
279
280   dt = g_date_time_new_from_date (1800, 12, 31);
281   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 31);
282   g_date_time_unref (dt);
283
284   dt = g_date_time_new_from_date (1000, 1, 1);
285   g_assert_cmpint (g_date_time_get_day_of_month (dt), ==, 1);
286   g_date_time_unref (dt);
287 }
288
289 static void
290 test_GDateTime_get_dmy (void)
291 {
292    GDateTime *dt;
293    struct tm tm;
294    time_t t;
295    gint d, m, y;
296    gint d2, m2, y2;
297    gint days[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
298                        {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
299
300    t = time (NULL);
301    memset (&tm, 0, sizeof (struct tm));
302    get_localtime_tm (t, &tm);
303
304    dt = g_date_time_new_from_epoch (t);
305    g_date_time_get_dmy(dt, &d, &m, &y);
306    g_assert_cmpint(y, ==, tm.tm_year + 1900);
307    g_assert_cmpint(m, ==, tm.tm_mon + 1);
308    g_assert_cmpint(d, ==, tm.tm_mday);
309
310    /* exaustive test */
311    for (y = 1750; y < 2250; y++)
312      {
313        gint leap = ((y % 4) == 0) && (!(((y % 100) == 0) && ((y % 400) != 0)))
314                  ? 1
315                  : 0;
316
317        for (m = 1; m <= 12; m++)
318          {
319            for (d = 1; d <= days[leap][m]; d++)
320              {
321                GDateTime *dt1 = g_date_time_new_from_date (y, m, d);
322
323                g_date_time_get_dmy (dt1, &d2, &m2, &y2);
324                g_assert_cmpint (y, ==, y2);
325                g_assert_cmpint (m, ==, m2);
326                g_assert_cmpint (d, ==, d2);
327                g_date_time_unref (dt1);
328              }
329          }
330      }
331 }
332
333 static void
334 test_GDateTime_get_hour (void)
335 {
336   GDateTime *dt;
337
338   dt = g_date_time_new_full (2009, 10, 19, 15, 13, 11, NULL);
339   g_assert_cmpint (15, ==, g_date_time_get_hour (dt));
340   g_date_time_unref (dt);
341
342   dt = g_date_time_new_full (100, 10, 19, 1, 0, 0, NULL);
343   g_assert_cmpint (1, ==, g_date_time_get_hour (dt));
344   g_date_time_unref (dt);
345
346   dt = g_date_time_new_full (100, 10, 19, 0, 0, 0, NULL);
347   g_assert_cmpint (0, ==, g_date_time_get_hour (dt));
348   g_date_time_unref (dt);
349
350   dt = g_date_time_new_full (100, 10, 1, 23, 59, 59, NULL);
351   g_assert_cmpint (23, ==, g_date_time_get_hour (dt));
352   g_date_time_unref (dt);
353 }
354
355 static void
356 test_GDateTime_get_julian (void)
357 {
358   GDateTime *dt;
359   gint period, julian, hour = 1, min = 1, sec = 1;
360
361   dt = g_date_time_new_from_date (1984, 8, 16);
362   g_date_time_get_julian (dt, &period, &julian, &hour, &min, &sec);
363   g_assert_cmpint (period, ==, 0);
364   g_assert_cmpint (julian, ==, 2445929);
365   g_assert_cmpint (hour, ==, 0);
366   g_assert_cmpint (min, ==, 0);
367   g_assert_cmpint (sec, ==, 0);
368   g_date_time_unref (dt);
369 }
370
371 static void
372 test_GDateTime_get_microsecond (void)
373 {
374   GTimeVal   tv;
375   GDateTime *dt;
376
377   g_get_current_time (&tv);
378   dt = g_date_time_new_from_timeval (&tv);
379   g_assert_cmpint (tv.tv_usec, ==, g_date_time_get_microsecond (dt));
380   g_date_time_unref (dt);
381 }
382
383 static void
384 test_GDateTime_get_millisecond (void)
385 {
386   GTimeVal   tv;
387   GDateTime *dt;
388
389   g_get_current_time (&tv);
390   dt = g_date_time_new_from_timeval (&tv);
391   g_assert_cmpint ((tv.tv_usec / 1000), ==, g_date_time_get_millisecond (dt));
392   g_date_time_unref (dt);
393
394   dt = g_date_time_new_full (2010, 9, 15, 12, 0, 0.1234, NULL);
395   g_assert_cmpint (123, ==, g_date_time_get_millisecond (dt));
396   g_assert_cmpint (123400, ==, g_date_time_get_microsecond (dt));
397   g_date_time_unref (dt);
398 }
399
400 static void
401 test_GDateTime_get_year (void)
402 {
403   GDateTime *dt;
404
405   dt = g_date_time_new_from_date (2009, 1, 1);
406   g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
407   g_date_time_unref (dt);
408
409   dt = g_date_time_new_from_date (1, 1, 1);
410   g_assert_cmpint (1, ==, g_date_time_get_year (dt));
411   g_date_time_unref (dt);
412
413   dt = g_date_time_new_from_date (13, 1, 1);
414   g_assert_cmpint (13, ==, g_date_time_get_year (dt));
415   g_date_time_unref (dt);
416
417   dt = g_date_time_new_from_date (3000, 1, 1);
418   g_assert_cmpint (3000, ==, g_date_time_get_year (dt));
419   g_date_time_unref (dt);
420 }
421
422 static void
423 test_GDateTime_hash (void)
424 {
425   GHashTable *h;
426
427   h = g_hash_table_new_full (g_date_time_hash, g_date_time_equal,
428                              (GDestroyNotify)g_date_time_unref,
429                              NULL);
430   g_hash_table_insert (h, g_date_time_new_now (), NULL);
431   g_hash_table_remove_all (h);
432   g_hash_table_destroy (h);
433 }
434
435 static void
436 test_GDateTime_new_from_timeval (void)
437 {
438   GDateTime *dt;
439   GTimeVal   tv, tv2;
440
441   g_get_current_time (&tv);
442   dt = g_date_time_new_from_timeval (&tv);
443
444   if (g_test_verbose ())
445     g_print ("\nDT%04d-%02d-%02dT%02d:%02d:%02d%s\n",
446              g_date_time_get_year (dt),
447              g_date_time_get_month (dt),
448              g_date_time_get_day_of_month (dt),
449              g_date_time_get_hour (dt),
450              g_date_time_get_minute (dt),
451              g_date_time_get_second (dt),
452              g_date_time_get_timezone_name (dt));
453
454   g_date_time_to_timeval (dt, &tv2);
455   g_assert_cmpint (tv.tv_sec, ==, tv2.tv_sec);
456   g_assert_cmpint (tv.tv_usec, ==, tv2.tv_usec);
457   g_date_time_unref (dt);
458 }
459
460 static void
461 test_GDateTime_to_epoch (void)
462 {
463   GDateTime *dt;
464   time_t     t;
465
466   t = time (NULL);
467   dt = g_date_time_new_from_epoch (t);
468   g_assert_cmpint (g_date_time_to_epoch (dt), ==, t);
469   g_date_time_unref (dt);
470 }
471
472 static void
473 test_GDateTime_add_years (void)
474 {
475   GDateTime *dt, *dt2;
476
477   dt = g_date_time_new_from_date (2009, 10, 19);
478   dt2 = g_date_time_add_years (dt, 1);
479   g_assert_cmpint (2010, ==, g_date_time_get_year (dt2));
480   g_date_time_unref (dt);
481   g_date_time_unref (dt2);
482 }
483
484 static void
485 test_GDateTime_add_months (void)
486 {
487   GTimeZone *utc_tz = g_time_zone_new_utc ();
488
489 #define TEST_ADD_MONTHS(y,m,d,a,ny,nm,nd) G_STMT_START { \
490   GDateTime *dt, *dt2; \
491   dt = g_date_time_new_full (y, m, d, 0, 0, 0, utc_tz); \
492   dt2 = g_date_time_add_months (dt, a); \
493   ASSERT_DATE (dt2, ny, nm, nd); \
494   g_date_time_unref (dt); \
495   g_date_time_unref (dt2); \
496 } G_STMT_END
497
498   TEST_ADD_MONTHS (2009, 12, 31,    1, 2010, 1, 31);
499   TEST_ADD_MONTHS (2009, 12, 31,    1, 2010, 1, 31);
500   TEST_ADD_MONTHS (2009,  6, 15,    1, 2009, 7, 15);
501   TEST_ADD_MONTHS (1400,  3,  1,    1, 1400, 4,  1);
502   TEST_ADD_MONTHS (1400,  1, 31,    1, 1400, 2, 28);
503   TEST_ADD_MONTHS (1400,  1, 31, 7200, 2000, 1, 31);
504   TEST_ADD_MONTHS (2008,  2, 29,   12, 2009, 2, 28);
505   TEST_ADD_MONTHS (2000,  8, 16,   -5, 2000, 3, 16);
506   TEST_ADD_MONTHS (2000,  8, 16,  -12, 1999, 8, 16);
507   TEST_ADD_MONTHS (2011,  2,  1,  -13, 2010, 1,  1);
508   TEST_ADD_MONTHS (1776,  7,  4, 1200, 1876, 7,  4);
509
510   g_time_zone_free (utc_tz);
511 }
512
513 static void
514 test_GDateTime_add_days (void)
515 {
516 #define TEST_ADD_DAYS(y,m,d,a,ny,nm,nd) G_STMT_START { \
517   GDateTime *dt, *dt2; \
518   dt = g_date_time_new_from_date (y, m, d); \
519   dt2 = g_date_time_add_days (dt, a); \
520   g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
521   g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
522   g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
523   g_date_time_unref (dt); \
524   g_date_time_unref (dt2); \
525 } G_STMT_END
526
527   TEST_ADD_DAYS (2009, 1, 31, 1, 2009, 2, 1);
528   TEST_ADD_DAYS (2009, 2, 1, -1, 2009, 1, 31);
529   TEST_ADD_DAYS (2008, 2, 28, 1, 2008, 2, 29);
530   TEST_ADD_DAYS (2008, 12, 31, 1, 2009, 1, 1);
531   TEST_ADD_DAYS (1, 1, 1, 1, 1, 1, 2);
532   TEST_ADD_DAYS (1955, 5, 24, 10, 1955, 6, 3);
533   TEST_ADD_DAYS (1955, 5, 24, -10, 1955, 5, 14);
534 }
535
536 static void
537 test_GDateTime_add_weeks (void)
538 {
539 #define TEST_ADD_WEEKS(y,m,d,a,ny,nm,nd) G_STMT_START { \
540   GDateTime *dt, *dt2; \
541   dt = g_date_time_new_from_date (y, m, d); \
542   dt2 = g_date_time_add_weeks (dt, a); \
543   g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
544   g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
545   g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
546   g_date_time_unref (dt); \
547   g_date_time_unref (dt2); \
548 } G_STMT_END
549
550   TEST_ADD_WEEKS (2009, 1, 1, 1, 2009, 1, 8);
551   TEST_ADD_WEEKS (2009, 8, 30, 1, 2009, 9, 6);
552   TEST_ADD_WEEKS (2009, 12, 31, 1, 2010, 1, 7);
553   TEST_ADD_WEEKS (2009, 1, 1, -1, 2008, 12, 25);
554 }
555
556 static void
557 test_GDateTime_add_hours (void)
558 {
559 #define TEST_ADD_HOURS(y,m,d,h,mi,s,a,ny,nm,nd,nh,nmi,ns) G_STMT_START { \
560   GDateTime *dt, *dt2; \
561   dt = g_date_time_new_full (y, m, d, h, mi, s, NULL); \
562   dt2 = g_date_time_add_hours (dt, a); \
563   g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
564   g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
565   g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
566   g_assert_cmpint (nh, ==, g_date_time_get_hour (dt2)); \
567   g_assert_cmpint (nmi, ==, g_date_time_get_minute (dt2)); \
568   g_assert_cmpint (ns, ==, g_date_time_get_second (dt2)); \
569   g_date_time_unref (dt); \
570   g_date_time_unref (dt2); \
571 } G_STMT_END
572
573   TEST_ADD_HOURS (2009,  1,  1,  0, 0, 0, 1, 2009, 1, 1, 1, 0, 0);
574   TEST_ADD_HOURS (2008, 12, 31, 23, 0, 0, 1, 2009, 1, 1, 0, 0, 0);
575 }
576
577 static void
578 test_GDateTime_add_full (void)
579 {
580 #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 { \
581   GDateTime *dt, *dt2; \
582   dt = g_date_time_new_full (y, m, d, h, mi, s, NULL); \
583   dt2 = g_date_time_add_full (dt, ay, am, ad, ah, ami, as); \
584   g_assert_cmpint (ny, ==, g_date_time_get_year (dt2)); \
585   g_assert_cmpint (nm, ==, g_date_time_get_month (dt2)); \
586   g_assert_cmpint (nd, ==, g_date_time_get_day_of_month (dt2)); \
587   g_assert_cmpint (nh, ==, g_date_time_get_hour (dt2)); \
588   g_assert_cmpint (nmi, ==, g_date_time_get_minute (dt2)); \
589   g_assert_cmpint (ns, ==, g_date_time_get_second (dt2)); \
590   g_date_time_unref (dt); \
591   g_date_time_unref (dt2); \
592 } G_STMT_END
593
594   TEST_ADD_FULL (2009, 10, 21,  0,  0, 0,
595                     1,  1,  1,  1,  1, 1,
596                  2010, 11, 22,  1,  1, 1);
597   TEST_ADD_FULL (2000,  1,  1,  1,  1, 1,
598                     0,  1,  0,  0,  0, 0,
599                  2000,  2,  1,  1,  1, 1);
600   TEST_ADD_FULL (2000,  1,  1,  0,  0, 0,
601                    -1,  1,  0,  0,  0, 0,
602                  1999,  2,  1,  0,  0, 0);
603   TEST_ADD_FULL (2010, 10, 31,  0,  0, 0,
604                     0,  4,  0,  0,  0, 0,
605                  2011,  2, 28,  0,  0, 0);
606   TEST_ADD_FULL (2010,  8, 25, 22, 45, 0,
607                     0,  1,  6,  1, 25, 0,
608                  2010, 10,  2,  0, 10, 0);
609 }
610
611 static void
612 test_GDateTime_add_milliseconds (void)
613 {
614 #define TEST_ADD_MILLISECOND(i,o) G_STMT_START { \
615   GDateTime *dt, *dt2; \
616   dt = g_date_time_new_from_date (2000, 1, 1); \
617   dt2 = g_date_time_add_milliseconds (dt, i); \
618   g_assert_cmpint (o, ==, g_date_time_get_millisecond (dt2)); \
619   g_date_time_unref (dt); \
620   g_date_time_unref (dt2); \
621 } G_STMT_END
622
623   TEST_ADD_MILLISECOND (199, 199);
624   TEST_ADD_MILLISECOND (10001, 1);
625   TEST_ADD_MILLISECOND (22201, 201);
626   TEST_ADD_MILLISECOND (-1000, 0);
627 }
628
629 static void
630 test_GDateTime_add_minutes (void)
631 {
632 #define TEST_ADD_MINUTES(i,o) G_STMT_START { \
633   GDateTime *dt, *dt2; \
634   dt = g_date_time_new_from_date (2000, 1, 1); \
635   dt2 = g_date_time_add_minutes (dt, i); \
636   g_assert_cmpint (o, ==, g_date_time_get_minute (dt2)); \
637   g_date_time_unref (dt); \
638   g_date_time_unref (dt2); \
639 } G_STMT_END
640
641   TEST_ADD_MINUTES (60, 0);
642   TEST_ADD_MINUTES (100, 40);
643   TEST_ADD_MINUTES (5, 5);
644   TEST_ADD_MINUTES (86401, 1);
645   TEST_ADD_MINUTES (-86401, 59);
646 }
647
648 static void
649 test_GDateTime_add_seconds (void)
650 {
651 #define TEST_ADD_SECONDS(i,o) G_STMT_START { \
652   GDateTime *dt, *dt2; \
653   dt = g_date_time_new_from_date (2000, 1, 1); \
654   dt2 = g_date_time_add_seconds (dt, i); \
655   g_assert_cmpint (o, ==, g_date_time_get_second (dt2)); \
656   g_date_time_unref (dt); \
657   g_date_time_unref (dt2); \
658 } G_STMT_END
659
660   TEST_ADD_SECONDS (1, 1);
661   TEST_ADD_SECONDS (60, 0);
662   TEST_ADD_SECONDS (61, 1);
663   TEST_ADD_SECONDS (120, 0);
664   TEST_ADD_SECONDS (-61, 59);
665   TEST_ADD_SECONDS (86401, 1);
666   TEST_ADD_SECONDS (-86401, 59);
667   TEST_ADD_SECONDS (-31, 29);
668   TEST_ADD_SECONDS (13, 13);
669 }
670
671 static void
672 test_GDateTime_diff (void)
673 {
674 #define TEST_DIFF(y,m,d,y2,m2,d2,u) G_STMT_START { \
675   GDateTime *dt1, *dt2; \
676   GTimeSpan  ts = 0; \
677   dt1 = g_date_time_new_from_date (y, m, d); \
678   dt2 = g_date_time_new_from_date (y2, m2, d2); \
679   ts = g_date_time_difference (dt1, dt2); \
680   g_assert_cmpint (ts, ==, u); \
681   g_date_time_unref (dt1); \
682   g_date_time_unref (dt2); \
683 } G_STMT_END
684
685   TEST_DIFF (2009, 1, 1, 2009, 2, 1, G_TIME_SPAN_DAY * 31);
686   TEST_DIFF (2009, 1, 1, 2010, 1, 1, G_TIME_SPAN_DAY * 365);
687   TEST_DIFF (2008, 2, 28, 2008, 2, 29, G_TIME_SPAN_DAY);
688   TEST_DIFF (2008, 2, 29, 2008, 2, 28, -G_TIME_SPAN_DAY);
689
690   /* TODO: Add usec tests */
691 }
692
693 static void
694 test_GDateTime_get_minute (void)
695 {
696   GDateTime *dt;
697
698   dt = g_date_time_new_full (2009, 12, 1, 1, 31, 0, NULL);
699   g_assert_cmpint (31, ==, g_date_time_get_minute (dt));
700   g_date_time_unref (dt);
701 }
702
703 static void
704 test_GDateTime_get_month (void)
705 {
706   GDateTime *dt;
707
708   dt = g_date_time_new_full (2009, 12, 1, 1, 31, 0, NULL);
709   g_assert_cmpint (12, ==, g_date_time_get_month (dt));
710   g_date_time_unref (dt);
711 }
712
713 static void
714 test_GDateTime_get_second (void)
715 {
716   GDateTime *dt;
717
718   dt = g_date_time_new_full (2009, 12, 1, 1, 31, 44, NULL);
719   g_assert_cmpint (44, ==, g_date_time_get_second (dt));
720   g_date_time_unref (dt);
721 }
722
723 static void
724 test_GDateTime_new_from_date (void)
725 {
726   GDateTime *dt;
727
728   dt = g_date_time_new_from_date (2009, 12, 11);
729   g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
730   g_assert_cmpint (12, ==, g_date_time_get_month (dt));
731   g_assert_cmpint (11, ==, g_date_time_get_day_of_month (dt));
732   g_date_time_unref (dt);
733 }
734
735 static void
736 test_GDateTime_new_full (void)
737 {
738   GDateTime *dt;
739   GTimeZone *time_zone;
740
741   dt = g_date_time_new_full (2009, 12, 11, 12, 11, 10, NULL);
742   g_assert_cmpint (2009, ==, g_date_time_get_year (dt));
743   g_assert_cmpint (12, ==, g_date_time_get_month (dt));
744   g_assert_cmpint (11, ==, g_date_time_get_day_of_month (dt));
745   g_assert_cmpint (12, ==, g_date_time_get_hour (dt));
746   g_assert_cmpint (11, ==, g_date_time_get_minute (dt));
747   g_assert_cmpint (10, ==, g_date_time_get_second (dt));
748   g_date_time_unref (dt);
749
750   time_zone = g_time_zone_new_for_name ("America/Recife");
751   dt = g_date_time_new_full (2010, 5, 24, 8, 4, 0, time_zone);
752   g_assert_cmpint (2010, ==, g_date_time_get_year (dt));
753   g_assert_cmpint (5, ==, g_date_time_get_month (dt));
754   g_assert_cmpint (24, ==, g_date_time_get_day_of_month (dt));
755   g_assert_cmpint (8, ==, g_date_time_get_hour (dt));
756   g_assert_cmpint (4, ==, g_date_time_get_minute (dt));
757   g_assert_cmpint (0, ==, g_date_time_get_second (dt));
758   g_assert_cmpstr ("BRT", ==, g_date_time_get_timezone_name (dt));
759   g_assert (!g_date_time_is_daylight_savings (dt));
760   g_date_time_unref (dt);
761   g_time_zone_free (time_zone);
762 }
763
764 static void
765 test_GDateTime_utc_now (void)
766 {
767   GDateTime *dt;
768   time_t     t;
769   struct tm  tm;
770
771   t = time (NULL);
772 #ifdef HAVE_GMTIME_R
773   gmtime_r (&t, &tm);
774 #else
775   {
776     struct tm *tmp = gmtime (&t);
777     /* Assume gmtime() can't fail as we got t from time(NULL). (Note
778      * that on Windows, gmtime() *is* MT-safe, it uses a thread-local
779      * buffer.)
780      */
781     memcpy (&tm, tmp, sizeof (struct tm));
782   }
783 #endif
784   dt = g_date_time_new_utc_now ();
785   g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
786   g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
787   g_assert_cmpint (tm.tm_mday, ==, g_date_time_get_day_of_month (dt));
788   g_assert_cmpint (tm.tm_hour, ==, g_date_time_get_hour (dt));
789   g_assert_cmpint (tm.tm_min, ==, g_date_time_get_minute (dt));
790   g_assert_cmpint (tm.tm_sec, ==, g_date_time_get_second (dt));
791   g_date_time_unref (dt);
792 }
793
794 static void
795 test_GDateTime_get_utc_offset (void)
796 {
797   GDateTime *dt;
798   GTimeSpan ts;
799   struct tm tm;
800
801   memset (&tm, 0, sizeof (tm));
802   get_localtime_tm (time (NULL), &tm);
803
804   dt = g_date_time_new_now ();
805   ts = g_date_time_get_utc_offset (dt);
806 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
807   g_assert_cmpint (ts, ==, (tm.tm_gmtoff * G_TIME_SPAN_SECOND));
808 #endif
809   g_date_time_unref (dt);
810 }
811
812 static void
813 test_GDateTime_to_timeval (void)
814 {
815   GTimeVal tv1, tv2;
816   GDateTime *dt;
817
818   memset (&tv1, 0, sizeof (tv1));
819   memset (&tv2, 0, sizeof (tv2));
820
821   g_get_current_time (&tv1);
822   dt = g_date_time_new_from_timeval (&tv1);
823   g_date_time_to_timeval (dt, &tv2);
824   g_assert_cmpint (tv1.tv_sec, ==, tv2.tv_sec);
825   g_assert_cmpint (tv1.tv_usec, ==, tv2.tv_usec);
826   g_date_time_unref (dt);
827 }
828
829 static void
830 test_GDateTime_to_local (void)
831 {
832   GDateTime *utc, *now, *dt;
833
834   utc = g_date_time_new_utc_now ();
835   now = g_date_time_new_now ();
836   dt = g_date_time_to_local (utc);
837
838   g_assert_cmpint (g_date_time_get_year (now), ==, g_date_time_get_year (dt));
839   g_assert_cmpint (g_date_time_get_month (now), ==, g_date_time_get_month (dt));
840   g_assert_cmpint (g_date_time_get_day_of_month (now), ==, g_date_time_get_day_of_month (dt));
841   g_assert_cmpint (g_date_time_get_hour (now), ==, g_date_time_get_hour (dt));
842   g_assert_cmpint (g_date_time_get_minute (now), ==, g_date_time_get_minute (dt));
843   g_assert_cmpint (g_date_time_get_second (now), ==, g_date_time_get_second (dt));
844
845   g_date_time_unref (now);
846   g_date_time_unref (utc);
847   g_date_time_unref (dt);
848 }
849
850 static void
851 test_GDateTime_to_utc (void)
852 {
853   GDateTime *dt, *dt2;
854   time_t     t;
855   struct tm  tm;
856
857   t = time (NULL);
858 #ifdef HAVE_GMTIME_R
859   gmtime_r (&t, &tm);
860 #else
861   {
862     struct tm *tmp = gmtime (&t);
863     memcpy (&tm, tmp, sizeof (struct tm));
864   }
865 #endif
866   dt2 = g_date_time_new_now ();
867   dt = g_date_time_to_utc (dt2);
868   g_assert_cmpint (tm.tm_year + 1900, ==, g_date_time_get_year (dt));
869   g_assert_cmpint (tm.tm_mon + 1, ==, g_date_time_get_month (dt));
870   g_assert_cmpint (tm.tm_mday, ==, g_date_time_get_day_of_month (dt));
871   g_assert_cmpint (tm.tm_hour, ==, g_date_time_get_hour (dt));
872   g_assert_cmpint (tm.tm_min, ==, g_date_time_get_minute (dt));
873   g_assert_cmpint (tm.tm_sec, ==, g_date_time_get_second (dt));
874   g_date_time_unref (dt);
875   g_date_time_unref (dt2);
876 }
877
878 static void
879 test_GDateTime_get_day_of_year (void)
880 {
881 #define TEST_DAY_OF_YEAR(y,m,d,o)                       G_STMT_START {  \
882   GDateTime *__dt = g_date_time_new_from_date ((y), (m), (d));          \
883   g_assert_cmpint ((o), ==, g_date_time_get_day_of_year (__dt));        \
884   g_date_time_unref (__dt);                             } G_STMT_END
885
886   TEST_DAY_OF_YEAR (2009, 1, 1, 1);
887   TEST_DAY_OF_YEAR (2009, 2, 1, 32);
888   TEST_DAY_OF_YEAR (2009, 8, 16, 228);
889   TEST_DAY_OF_YEAR (2008, 8, 16, 229);
890 }
891
892 static void
893 test_GDateTime_printf (void)
894 {
895   gchar dst[16];
896   struct tm tt;
897   time_t t;
898   gchar t_str[16];
899
900 #define TEST_PRINTF(f,o)                        G_STMT_START {  \
901 GDateTime *__dt = g_date_time_new_from_date (2009, 10, 24);     \
902   gchar *__p = g_date_time_printf (__dt, (f));                  \
903   g_assert_cmpstr (__p, ==, (o));                               \
904   g_date_time_unref (__dt);                                     \
905   g_free (__p);                                 } G_STMT_END
906
907 #define TEST_PRINTF_DATE(y,m,d,f,o)             G_STMT_START {  \
908   GDateTime *dt = g_date_time_new_from_date ((y), (m), (d));    \
909   gchar *p = g_date_time_printf (dt, (f));                      \
910   g_assert_cmpstr (p, ==, (o));                                 \
911   g_date_time_unref (dt);                                       \
912   g_free (p);                                   } G_STMT_END
913
914 #define TEST_PRINTF_TIME(h,m,s,f,o)             G_STMT_START { \
915   GDateTime *dt = g_date_time_new_full (2009, 10, 24, (h), (m), (s), NULL); \
916   gchar *p = g_date_time_printf (dt, (f));                      \
917   g_assert_cmpstr (p, ==, (o));                                 \
918   g_date_time_unref (dt);                                       \
919   g_free (p);                                   } G_STMT_END
920
921   /*
922    * This is a little helper to make sure we can compare timezones to
923    * that of the generated timezone.
924    */
925   t = time (NULL);
926   memset (&tt, 0, sizeof(tt));
927   get_localtime_tm (t, &tt);
928   tt.tm_year = 2009 - 1900;
929   tt.tm_mon = 9; /* 0 indexed */
930   tt.tm_mday = 24;
931   t = mktime (&tt);
932   memset (&tt, 0, sizeof(tt));
933   get_localtime_tm (t, &tt);
934   strftime (dst, sizeof(dst), "%Z", &tt);
935
936   /* get current time_t for 20090924 in the local timezone */
937   tt.tm_sec = 0;
938   tt.tm_min = 0;
939   tt.tm_hour = 0;
940   t = mktime (&tt);
941   g_sprintf (t_str, "%ld", t);
942
943   TEST_PRINTF ("%a", "Sat");
944   TEST_PRINTF ("%A", "Saturday");
945   TEST_PRINTF ("%b", "Oct");
946   TEST_PRINTF ("%B", "October");
947   TEST_PRINTF ("%d", "24");
948   TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
949   TEST_PRINTF ("%e", "24"); // fixme
950   TEST_PRINTF ("%h", "Oct");
951   TEST_PRINTF ("%H", "00");
952   TEST_PRINTF_TIME (15, 0, 0, "%H", "15");
953   TEST_PRINTF ("%I", "12");
954   TEST_PRINTF_TIME (15, 0, 0, "%I", "03");
955   TEST_PRINTF ("%j", "297");
956   TEST_PRINTF ("%k", " 0");
957   TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
958   TEST_PRINTF ("%l", "12");
959   TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
960   TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
961   TEST_PRINTF ("%m", "10");
962   TEST_PRINTF ("%M", "00");
963   TEST_PRINTF ("%N", "0");
964   TEST_PRINTF ("%p", "AM");
965   TEST_PRINTF_TIME (13, 13, 13, "%p", "PM");
966   TEST_PRINTF ("%P", "am");
967   TEST_PRINTF_TIME (13, 13, 13, "%P", "pm");
968   TEST_PRINTF ("%r", "12:00:00 AM");
969   TEST_PRINTF_TIME (13, 13, 13, "%r", "01:13:13 PM");
970   TEST_PRINTF ("%R", "00:00");
971   TEST_PRINTF_TIME (13, 13, 31, "%R", "13:13");
972   TEST_PRINTF ("%s", t_str);
973   TEST_PRINTF ("%S", "00");
974   TEST_PRINTF ("%t", "  ");
975   TEST_PRINTF ("%W", "42");
976   TEST_PRINTF ("%u", "6");
977   TEST_PRINTF ("%x", "10/24/09");
978   TEST_PRINTF ("%X", "00:00:00");
979   TEST_PRINTF_TIME (13, 14, 15, "%X", "13:14:15");
980   TEST_PRINTF ("%y", "09");
981   TEST_PRINTF ("%Y", "2009");
982   TEST_PRINTF ("%%", "%");
983   TEST_PRINTF ("%", "");
984   TEST_PRINTF ("%9", NULL);
985   TEST_PRINTF ("%Z", dst);
986 }
987
988 static void
989 test_GDateTime_dst (void)
990 {
991   GDateTime *dt1, *dt2;
992   GTimeZone *tz;
993
994   tz = g_time_zone_new_for_name ("Europe/London");
995
996   /* this date has the DST state set for Europe/London */
997   dt1 = g_date_time_new_full (2009, 8, 15, 3, 0, 1, tz);
998   g_assert (g_date_time_is_daylight_savings (dt1));
999   g_assert_cmpint (g_date_time_get_utc_offset (dt1) / G_USEC_PER_SEC, ==, 3600);
1000   g_assert_cmpint (g_date_time_get_hour (dt1), ==, 3);
1001
1002   /* add 6 months to clear the DST flag and go back one hour */
1003   dt2 = g_date_time_add_months (dt1, 6);
1004   g_assert (!g_date_time_is_daylight_savings (dt2));
1005   g_assert_cmpint (g_date_time_get_utc_offset (dt2) / G_USEC_PER_SEC, ==, 0);
1006   g_assert_cmpint (g_date_time_get_hour (dt2), ==, 2);
1007
1008   g_date_time_unref (dt2);
1009   g_date_time_unref (dt1);
1010
1011   /* now do the reverse: start with a non-DST state and move to DST */
1012   dt1 = g_date_time_new_full (2009, 2, 15, 2, 0, 1, tz);
1013   g_assert (!g_date_time_is_daylight_savings (dt1));
1014   g_assert_cmpint (g_date_time_get_hour (dt1), ==, 2);
1015
1016   dt2 = g_date_time_add_months (dt1, 6);
1017   g_assert (g_date_time_is_daylight_savings (dt2));
1018   g_assert_cmpint (g_date_time_get_hour (dt2), ==, 3);
1019
1020   g_date_time_unref (dt2);
1021   g_date_time_unref (dt1);
1022
1023   g_time_zone_free (tz);
1024 }
1025
1026 gint
1027 main (gint   argc,
1028       gchar *argv[])
1029 {
1030   g_test_init (&argc, &argv, NULL);
1031
1032   /* GDateTime Tests */
1033
1034   g_test_add_func ("/GDateTime/add_days", test_GDateTime_add_days);
1035   g_test_add_func ("/GDateTime/add_full", test_GDateTime_add_full);
1036   g_test_add_func ("/GDateTime/add_hours", test_GDateTime_add_hours);
1037   g_test_add_func ("/GDateTime/add_milliseconds", test_GDateTime_add_milliseconds);
1038   g_test_add_func ("/GDateTime/add_minutes", test_GDateTime_add_minutes);
1039   g_test_add_func ("/GDateTime/add_months", test_GDateTime_add_months);
1040   g_test_add_func ("/GDateTime/add_seconds", test_GDateTime_add_seconds);
1041   g_test_add_func ("/GDateTime/add_weeks", test_GDateTime_add_weeks);
1042   g_test_add_func ("/GDateTime/add_years", test_GDateTime_add_years);
1043   g_test_add_func ("/GDateTime/compare", test_GDateTime_compare);
1044   g_test_add_func ("/GDateTime/date", test_GDateTime_date);
1045   g_test_add_func ("/GDateTime/diff", test_GDateTime_diff);
1046   g_test_add_func ("/GDateTime/equal", test_GDateTime_equal);
1047   g_test_add_func ("/GDateTime/get_day_of_week", test_GDateTime_get_day_of_week);
1048   g_test_add_func ("/GDateTime/get_day_of_month", test_GDateTime_get_day_of_month);
1049   g_test_add_func ("/GDateTime/get_day_of_year", test_GDateTime_get_day_of_year);
1050   g_test_add_func ("/GDateTime/get_dmy", test_GDateTime_get_dmy);
1051   g_test_add_func ("/GDateTime/get_hour", test_GDateTime_get_hour);
1052   g_test_add_func ("/GDateTime/get_julian", test_GDateTime_get_julian);
1053   g_test_add_func ("/GDateTime/get_microsecond", test_GDateTime_get_microsecond);
1054   g_test_add_func ("/GDateTime/get_millisecond", test_GDateTime_get_millisecond);
1055   g_test_add_func ("/GDateTime/get_minute", test_GDateTime_get_minute);
1056   g_test_add_func ("/GDateTime/get_month", test_GDateTime_get_month);
1057   g_test_add_func ("/GDateTime/get_second", test_GDateTime_get_second);
1058   g_test_add_func ("/GDateTime/get_utc_offset", test_GDateTime_get_utc_offset);
1059   g_test_add_func ("/GDateTime/get_year", test_GDateTime_get_year);
1060   g_test_add_func ("/GDateTime/hash", test_GDateTime_hash);
1061   g_test_add_func ("/GDateTime/is_leap_year", test_GDateTime_is_leap_year);
1062   g_test_add_func ("/GDateTime/new_from_date", test_GDateTime_new_from_date);
1063   g_test_add_func ("/GDateTime/new_from_epoch", test_GDateTime_new_from_epoch);
1064   g_test_add_func ("/GDateTime/new_from_timeval", test_GDateTime_new_from_timeval);
1065   g_test_add_func ("/GDateTime/new_full", test_GDateTime_new_full);
1066   g_test_add_func ("/GDateTime/now", test_GDateTime_now);
1067   g_test_add_func ("/GDateTime/printf", test_GDateTime_printf);
1068   g_test_add_func ("/GDateTime/to_local", test_GDateTime_to_local);
1069   g_test_add_func ("/GDateTime/to_epoch", test_GDateTime_to_epoch);
1070   g_test_add_func ("/GDateTime/to_timeval", test_GDateTime_to_timeval);
1071   g_test_add_func ("/GDateTime/to_utc", test_GDateTime_to_utc);
1072   g_test_add_func ("/GDateTime/today", test_GDateTime_today);
1073   g_test_add_func ("/GDateTime/utc_now", test_GDateTime_utc_now);
1074   g_test_add_func ("/GDateTime/dst", test_GDateTime_dst);
1075
1076   return g_test_run ();
1077 }