mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 05:59:10 +00:00
gstdatetime: Fix string serialization
Correctly serialize tzoffset as a gstvalue
This commit is contained in:
parent
29e23e9142
commit
dd53349ad2
2 changed files with 14 additions and 12 deletions
|
@ -4375,21 +4375,24 @@ gst_value_compare_date_time (const GValue * value1, const GValue * value2)
|
||||||
static gchar *
|
static gchar *
|
||||||
gst_value_serialize_date_time (const GValue * val)
|
gst_value_serialize_date_time (const GValue * val)
|
||||||
{
|
{
|
||||||
const GstDateTime *date = (const GstDateTime *) g_value_get_boxed (val);
|
GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
|
||||||
gint offset;
|
gint offset;
|
||||||
|
gint tzhour, tzminute;
|
||||||
|
|
||||||
if (date == NULL)
|
if (date == NULL)
|
||||||
return g_strdup ("null");
|
return g_strdup ("null");
|
||||||
|
|
||||||
offset = gst_date_time_get_time_zone_offset (date);
|
offset = gst_date_time_get_time_zone_offset (date);
|
||||||
|
|
||||||
|
tzhour = (gint) ABS (offset);
|
||||||
|
tzminute = (gint) ((ABS (offset) - tzhour) * 60);
|
||||||
|
|
||||||
return g_strdup_printf ("\"%04d-%02d-%02dT%02d:%02d:%02d.%06d"
|
return g_strdup_printf ("\"%04d-%02d-%02dT%02d:%02d:%02d.%06d"
|
||||||
"%c%02d%02d\"", gst_date_time_get_year (date),
|
"%c%02d%02d\"", gst_date_time_get_year (date),
|
||||||
gst_date_time_get_month (date), gst_date_time_get_day (date),
|
gst_date_time_get_month (date), gst_date_time_get_day (date),
|
||||||
gst_date_time_get_hour (date), gst_date_time_get_minute (date),
|
gst_date_time_get_hour (date), gst_date_time_get_minute (date),
|
||||||
gst_date_time_get_second (date), gst_date_time_get_microsecond (date),
|
gst_date_time_get_second (date), gst_date_time_get_microsecond (date),
|
||||||
offset >= 0 ? '+' : '-', (gint) ABS (offset) / 60,
|
offset >= 0 ? '+' : '-', tzhour, tzminute);
|
||||||
(gint) ABS (offset) % 60);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -4398,6 +4401,7 @@ gst_value_deserialize_date_time (GValue * dest, const gchar * s)
|
||||||
gint year, month, day, hour, minute, second, usecond;
|
gint year, month, day, hour, minute, second, usecond;
|
||||||
gchar signal;
|
gchar signal;
|
||||||
gint offset = 0;
|
gint offset = 0;
|
||||||
|
gfloat tzoffset = 0;
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
if (!s || strcmp (s, "null") == 0) {
|
if (!s || strcmp (s, "null") == 0) {
|
||||||
|
@ -4407,14 +4411,14 @@ gst_value_deserialize_date_time (GValue * dest, const gchar * s)
|
||||||
ret = sscanf (s, "%04d-%02d-%02dT%02d:%02d:%02d.%06d%c%04d",
|
ret = sscanf (s, "%04d-%02d-%02dT%02d:%02d:%02d.%06d%c%04d",
|
||||||
&year, &month, &day, &hour, &minute, &second, &usecond, &signal, &offset);
|
&year, &month, &day, &hour, &minute, &second, &usecond, &signal, &offset);
|
||||||
if (ret >= 9) {
|
if (ret >= 9) {
|
||||||
offset = (offset / 100) * 60 + (offset % 100);
|
tzoffset = (offset / 100) + ((offset % 100) / 60.0);
|
||||||
if (signal == '-')
|
if (signal == '-')
|
||||||
offset = -offset;
|
tzoffset = -tzoffset;
|
||||||
} else
|
} else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
g_value_take_boxed (dest, gst_date_time_new (year, month, day, hour,
|
g_value_take_boxed (dest, gst_date_time_new (year, month, day, hour,
|
||||||
minute, second, usecond, offset));
|
minute, second, usecond, tzoffset));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2066,7 +2066,7 @@ GST_START_TEST (test_date_time)
|
||||||
str = NULL;
|
str = NULL;
|
||||||
|
|
||||||
/* with timezone */
|
/* with timezone */
|
||||||
datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 1, -3 * 60);
|
datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 1, -3.0);
|
||||||
|
|
||||||
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
|
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
|
||||||
GST_TYPE_DATE_TIME, datetime, NULL);
|
GST_TYPE_DATE_TIME, datetime, NULL);
|
||||||
|
@ -2108,8 +2108,7 @@ GST_START_TEST (test_date_time)
|
||||||
fail_unless (gst_date_time_get_minute (datetime) == 40);
|
fail_unless (gst_date_time_get_minute (datetime) == 40);
|
||||||
fail_unless (gst_date_time_get_second (datetime) == 10);
|
fail_unless (gst_date_time_get_second (datetime) == 10);
|
||||||
fail_unless (gst_date_time_get_microsecond (datetime) == 1);
|
fail_unless (gst_date_time_get_microsecond (datetime) == 1);
|
||||||
fail_unless (gst_date_time_get_time_zone_offset (datetime) ==
|
fail_unless (gst_date_time_get_time_zone_offset (datetime) == -3);
|
||||||
((gint64) - 3 * 60));
|
|
||||||
gst_date_time_unref (datetime);
|
gst_date_time_unref (datetime);
|
||||||
datetime = NULL;
|
datetime = NULL;
|
||||||
|
|
||||||
|
@ -2123,7 +2122,7 @@ GST_START_TEST (test_date_time)
|
||||||
str = NULL;
|
str = NULL;
|
||||||
|
|
||||||
/* with positive timezone */
|
/* with positive timezone */
|
||||||
datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 1, 2 * 60);
|
datetime = gst_date_time_new (2010, 6, 23, 7, 40, 10, 1, 2);
|
||||||
|
|
||||||
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
|
s = gst_structure_new ("media/x-type", "SOME_DATE_TIME_TAG",
|
||||||
GST_TYPE_DATE_TIME, datetime, NULL);
|
GST_TYPE_DATE_TIME, datetime, NULL);
|
||||||
|
@ -2165,8 +2164,7 @@ GST_START_TEST (test_date_time)
|
||||||
fail_unless (gst_date_time_get_minute (datetime) == 40);
|
fail_unless (gst_date_time_get_minute (datetime) == 40);
|
||||||
fail_unless (gst_date_time_get_second (datetime) == 10);
|
fail_unless (gst_date_time_get_second (datetime) == 10);
|
||||||
fail_unless (gst_date_time_get_microsecond (datetime) == 1);
|
fail_unless (gst_date_time_get_microsecond (datetime) == 1);
|
||||||
fail_unless (gst_date_time_get_time_zone_offset (datetime) ==
|
fail_unless (gst_date_time_get_time_zone_offset (datetime) == 2);
|
||||||
((gint64) 2 * 60));
|
|
||||||
gst_date_time_unref (datetime);
|
gst_date_time_unref (datetime);
|
||||||
datetime = NULL;
|
datetime = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue