From 2f94ad3d6c36d6299caa2af553a094544d4e7abf Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 2 Dec 2010 16:28:43 -0300 Subject: [PATCH] gstdatetime: Fix handling of timezones Fix returning of timezones on systems with gdatetime to use floats on the math expression to avoid truncating the fractional part. Also adds a test for covering this case. --- gst/gstdatetime.c | 7 ++++--- tests/check/gst/gstdatetime.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gst/gstdatetime.c b/gst/gstdatetime.c index e05d222..acb8209 100644 --- a/gst/gstdatetime.c +++ b/gst/gstdatetime.c @@ -494,7 +494,7 @@ gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour, + (guint64) (floor (seconds * GST_DATE_TIME_USEC_PER_SECOND + 0.5)); /* we store in minutes */ - dt->tzoffset = (gint) tzoffset *60.0; + dt->tzoffset = (gint) (tzoffset * 60.0); return dt; } @@ -684,8 +684,8 @@ gst_date_time_get_microsecond (const GstDateTime * datetime) gfloat gst_date_time_get_time_zone_offset (const GstDateTime * datetime) { - return g_date_time_get_utc_offset (datetime->datetime) / - (G_USEC_PER_SEC * G_GINT64_CONSTANT (3600)); + return (g_date_time_get_utc_offset (datetime->datetime) / + G_USEC_PER_SEC) / 3600.0; } GstDateTime * @@ -746,6 +746,7 @@ gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour, tzminute); tz = g_time_zone_new (buf); + dt = g_date_time_new (tz, year, month, day, hour, minute, seconds); g_time_zone_unref (tz); return gst_date_time_new_from_gdatetime (dt); diff --git a/tests/check/gst/gstdatetime.c b/tests/check/gst/gstdatetime.c index 06fc540..ccc692f 100644 --- a/tests/check/gst/gstdatetime.c +++ b/tests/check/gst/gstdatetime.c @@ -217,7 +217,18 @@ GST_START_TEST (test_GstDateTime_new_full) assert_equals_int (11, gst_date_time_get_minute (dt)); assert_equals_int (10, gst_date_time_get_second (dt)); assert_equals_int (1234, gst_date_time_get_microsecond (dt)); - assert_equals_int (0, gst_date_time_get_time_zone_offset (dt)); + assert_equals_float (0, gst_date_time_get_time_zone_offset (dt)); + gst_date_time_unref (dt); + + dt = gst_date_time_new (2.5, 2010, 3, 29, 12, 13, 16.5); + assert_equals_int (2010, gst_date_time_get_year (dt)); + assert_equals_int (3, gst_date_time_get_month (dt)); + assert_equals_int (29, gst_date_time_get_day (dt)); + assert_equals_int (12, gst_date_time_get_hour (dt)); + assert_equals_int (13, gst_date_time_get_minute (dt)); + assert_equals_int (16, gst_date_time_get_second (dt)); + assert_equals_int (500000, gst_date_time_get_microsecond (dt)); + assert_equals_float (2.5, gst_date_time_get_time_zone_offset (dt)); gst_date_time_unref (dt); } -- 2.7.4