Fix %z in g_date_time_format()

https://bugzilla.gnome.org/show_bug.cgi?id=642935
This commit is contained in:
David Schleef 2011-02-21 18:58:09 -08:00 committed by Matthias Clasen
parent d3b80c49ea
commit 0dc5d45692
2 changed files with 21 additions and 3 deletions

View File

@ -2385,10 +2385,9 @@ g_date_time_format (GDateTime *datetime,
gint64 offset = g_date_time_get_utc_offset (datetime)
/ USEC_PER_SECOND;
g_string_append_printf (outstr, "%c%02d%02d",
offset >= 0 ? '+' : '-',
g_string_append_printf (outstr, "%+03d%02d",
(int) offset / 3600,
(int) offset / 60 % 60);
(int) abs(offset) / 60 % 60);
}
else
g_string_append (outstr, "+0000");

View File

@ -1023,11 +1023,29 @@ test_all_dates (void)
g_time_zone_unref (timezone);
}
static void
test_z (void)
{
GTimeZone *tz;
GDateTime *dt;
g_test_bug ("642935");
tz = g_time_zone_new ("-08:00");
dt = g_date_time_new (tz, 0, 0, 0, 0, 0, 0);
gchar *p = g_date_time_format (dt, "%z");
g_assert_cmpstr (p, ==, "-0800");
g_date_time_unref (dt);
g_free (p);
}
gint
main (gint argc,
gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.gnome.org/");
/* GDateTime Tests */
@ -1065,6 +1083,7 @@ main (gint argc,
g_test_add_func ("/GDateTime/to_utc", test_GDateTime_to_utc);
g_test_add_func ("/GDateTime/now_utc", test_GDateTime_now_utc);
g_test_add_func ("/GDateTime/dst", test_GDateTime_dst);
g_test_add_func ("/GDateTime/test_z", test_z);
g_test_add_func ("/GDateTime/test-all-dates", test_all_dates);
return g_test_run ();