mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-13 04:46:15 +01:00
Fix %z in g_date_time_format()
https://bugzilla.gnome.org/show_bug.cgi?id=642935
This commit is contained in:
parent
d3b80c49ea
commit
0dc5d45692
@ -2385,10 +2385,9 @@ g_date_time_format (GDateTime *datetime,
|
|||||||
gint64 offset = g_date_time_get_utc_offset (datetime)
|
gint64 offset = g_date_time_get_utc_offset (datetime)
|
||||||
/ USEC_PER_SECOND;
|
/ USEC_PER_SECOND;
|
||||||
|
|
||||||
g_string_append_printf (outstr, "%c%02d%02d",
|
g_string_append_printf (outstr, "%+03d%02d",
|
||||||
offset >= 0 ? '+' : '-',
|
|
||||||
(int) offset / 3600,
|
(int) offset / 3600,
|
||||||
(int) offset / 60 % 60);
|
(int) abs(offset) / 60 % 60);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_string_append (outstr, "+0000");
|
g_string_append (outstr, "+0000");
|
||||||
|
@ -1023,11 +1023,29 @@ test_all_dates (void)
|
|||||||
g_time_zone_unref (timezone);
|
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
|
gint
|
||||||
main (gint argc,
|
main (gint argc,
|
||||||
gchar *argv[])
|
gchar *argv[])
|
||||||
{
|
{
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
g_test_bug_base ("http://bugzilla.gnome.org/");
|
||||||
|
|
||||||
/* GDateTime Tests */
|
/* 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/to_utc", test_GDateTime_to_utc);
|
||||||
g_test_add_func ("/GDateTime/now_utc", test_GDateTime_now_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/dst", test_GDateTime_dst);
|
||||||
|
g_test_add_func ("/GDateTime/test_z", test_z);
|
||||||
g_test_add_func ("/GDateTime/test-all-dates", test_all_dates);
|
g_test_add_func ("/GDateTime/test-all-dates", test_all_dates);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
|
Loading…
Reference in New Issue
Block a user