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.
This commit is contained in:
Thiago Santos 2010-12-02 16:28:43 -03:00
parent 01039b1671
commit 2f94ad3d6c
2 changed files with 16 additions and 4 deletions

View file

@ -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);

View file

@ -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);
}