mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
datetime: add conversion to/from GDateTime
Exposes existing constructor. API: gst_date_time_to_g_date_time() API: gst_date_time_new_from_g_date_time() https://bugzilla.gnome.org/show_bug.cgi?id=679080
This commit is contained in:
parent
291403bbb9
commit
ba6fad9302
5 changed files with 97 additions and 12 deletions
|
@ -2962,6 +2962,9 @@ gst_date_time_new
|
|||
|
||||
gst_date_time_new_from_iso8601_string
|
||||
gst_date_time_to_iso8601_string
|
||||
|
||||
gst_date_time_new_from_g_date_time
|
||||
gst_date_time_to_g_date_time
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
|
|
|
@ -64,8 +64,18 @@ struct _GstDateTime
|
|||
volatile gint ref_count;
|
||||
};
|
||||
|
||||
static GstDateTime *
|
||||
gst_date_time_new_from_gdatetime (GDateTime * dt)
|
||||
/**
|
||||
* gst_date_time_new_from_g_date_time:
|
||||
* @dt: (transfer full): the #GDateTime. The new #GstDateTime takes ownership.
|
||||
*
|
||||
* Creates a new #GstDateTime from a #GDateTime object.
|
||||
*
|
||||
* Free-function: gst_date_time_unref
|
||||
*
|
||||
* Returns: (transfer full): a newly created #GstDateTime, or NULL on error
|
||||
*/
|
||||
GstDateTime *
|
||||
gst_date_time_new_from_g_date_time (GDateTime * dt)
|
||||
{
|
||||
GstDateTime *gst_dt;
|
||||
|
||||
|
@ -79,6 +89,27 @@ gst_date_time_new_from_gdatetime (GDateTime * dt)
|
|||
return gst_dt;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_date_time_to_g_date_time:
|
||||
* @datetime: GstDateTime.
|
||||
*
|
||||
* Creates a new #GDateTime from a fully defined #GstDateTime object.
|
||||
*
|
||||
* Free-function: g_date_time_unref
|
||||
*
|
||||
* Returns: (transfer full): a newly created #GDateTime, or NULL on error
|
||||
*/
|
||||
GDateTime *
|
||||
gst_date_time_to_g_date_time (GstDateTime * datetime)
|
||||
{
|
||||
g_return_val_if_fail (datetime != NULL, NULL);
|
||||
|
||||
if (datetime->fields != GST_DATE_TIME_FIELDS_YMD_HMS)
|
||||
return NULL;
|
||||
|
||||
return g_date_time_add (datetime->datetime, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_date_time_has_year:
|
||||
* @datetime: a #GstDateTime
|
||||
|
@ -192,7 +223,7 @@ gst_date_time_get_month (const GstDateTime * datetime)
|
|||
* gst_date_time_get_day:
|
||||
* @datetime: a #GstDateTime
|
||||
*
|
||||
* Returns the day of this #GstDateTime.
|
||||
* Returns the day of the month of this #GstDateTime.
|
||||
* Call gst_date_time_has_day before, to avoid warnings.
|
||||
*
|
||||
* Return value: The day of this #GstDateTime
|
||||
|
@ -403,10 +434,10 @@ gst_date_time_new_ymd (gint year, gint month, gint day)
|
|||
GstDateTime *
|
||||
gst_date_time_new_from_unix_epoch_local_time (gint64 secs)
|
||||
{
|
||||
GstDateTime *datetime;
|
||||
datetime =
|
||||
gst_date_time_new_from_gdatetime (g_date_time_new_from_unix_local (secs));
|
||||
return datetime;
|
||||
GDateTime *datetime;
|
||||
|
||||
datetime = g_date_time_new_from_unix_local (secs);
|
||||
return gst_date_time_new_from_g_date_time (datetime);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -427,7 +458,7 @@ gst_date_time_new_from_unix_epoch_utc (gint64 secs)
|
|||
{
|
||||
GstDateTime *datetime;
|
||||
datetime =
|
||||
gst_date_time_new_from_gdatetime (g_date_time_new_from_unix_utc (secs));
|
||||
gst_date_time_new_from_g_date_time (g_date_time_new_from_unix_utc (secs));
|
||||
return datetime;
|
||||
}
|
||||
|
||||
|
@ -501,7 +532,7 @@ gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
|
|||
fields = gst_date_time_check_fields (&year, &month, &day,
|
||||
&hour, &minute, &seconds);
|
||||
|
||||
datetime = gst_date_time_new_from_gdatetime (g_date_time_new_local (year,
|
||||
datetime = gst_date_time_new_from_g_date_time (g_date_time_new_local (year,
|
||||
month, day, hour, minute, seconds));
|
||||
|
||||
datetime->fields = fields;
|
||||
|
@ -523,7 +554,7 @@ gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
|
|||
GstDateTime *
|
||||
gst_date_time_new_now_local_time (void)
|
||||
{
|
||||
return gst_date_time_new_from_gdatetime (g_date_time_new_now_local ());
|
||||
return gst_date_time_new_from_g_date_time (g_date_time_new_now_local ());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,7 +573,7 @@ gst_date_time_new_now_local_time (void)
|
|||
GstDateTime *
|
||||
gst_date_time_new_now_utc (void)
|
||||
{
|
||||
return gst_date_time_new_from_gdatetime (g_date_time_new_now_utc ());
|
||||
return gst_date_time_new_from_g_date_time (g_date_time_new_now_utc ());
|
||||
}
|
||||
|
||||
gint
|
||||
|
@ -634,7 +665,7 @@ gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour,
|
|||
dt = g_date_time_new (tz, year, month, day, hour, minute, seconds);
|
||||
g_time_zone_unref (tz);
|
||||
|
||||
datetime = gst_date_time_new_from_gdatetime (dt);
|
||||
datetime = gst_date_time_new_from_g_date_time (dt);
|
||||
datetime->fields = fields;
|
||||
|
||||
return datetime;
|
||||
|
|
|
@ -91,6 +91,10 @@ GstDateTime * gst_date_time_new_now_utc (void) G_GNUC_MALLOC;
|
|||
gchar * gst_date_time_to_iso8601_string (GstDateTime * datetime) G_GNUC_MALLOC;
|
||||
GstDateTime * gst_date_time_new_from_iso8601_string (const gchar * string) G_GNUC_MALLOC;
|
||||
|
||||
GDateTime * gst_date_time_to_g_date_time (GstDateTime * datetime);
|
||||
|
||||
GstDateTime * gst_date_time_new_from_g_date_time (GDateTime * dt);
|
||||
|
||||
/* refcounting */
|
||||
|
||||
GstDateTime * gst_date_time_ref (GstDateTime * datetime);
|
||||
|
|
|
@ -636,6 +636,49 @@ GST_START_TEST (test_GstDateTime_iso8601)
|
|||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_GstDateTime_to_g_date_time)
|
||||
{
|
||||
GDateTime *gdt1;
|
||||
GDateTime *gdt2;
|
||||
GstDateTime *dt;
|
||||
|
||||
gdt1 = g_date_time_new_now_utc ();
|
||||
dt = gst_date_time_new_from_g_date_time (gdt1);
|
||||
gdt2 = gst_date_time_to_g_date_time (dt);
|
||||
|
||||
fail_unless (g_date_time_compare (gdt1, gdt2) == 0);
|
||||
|
||||
g_date_time_unref (gdt1);
|
||||
g_date_time_unref (gdt2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_GstDateTime_new_from_g_date_time)
|
||||
{
|
||||
GDateTime *gdt;
|
||||
GstDateTime *dt;
|
||||
|
||||
gdt = g_date_time_new_now_utc ();
|
||||
dt = gst_date_time_new_from_g_date_time (gdt);
|
||||
|
||||
assert_equals_int (gst_date_time_get_year (dt), g_date_time_get_year (gdt));
|
||||
assert_equals_int (gst_date_time_get_month (dt), g_date_time_get_month (gdt));
|
||||
assert_equals_int (gst_date_time_get_day (dt),
|
||||
g_date_time_get_day_of_month (gdt));
|
||||
assert_equals_int (gst_date_time_get_hour (dt), g_date_time_get_hour (gdt));
|
||||
assert_equals_int (gst_date_time_get_minute (dt),
|
||||
g_date_time_get_minute (gdt));
|
||||
assert_equals_int (gst_date_time_get_second (dt),
|
||||
g_date_time_get_second (gdt));
|
||||
assert_equals_int (gst_date_time_get_microsecond (dt),
|
||||
g_date_time_get_microsecond (gdt));
|
||||
|
||||
g_date_time_unref (gdt);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static Suite *
|
||||
gst_date_time_suite (void)
|
||||
{
|
||||
|
@ -656,6 +699,8 @@ gst_date_time_suite (void)
|
|||
tcase_add_test (tc_chain, test_GstDateTime_utc_now);
|
||||
tcase_add_test (tc_chain, test_GstDateTime_partial_fields);
|
||||
tcase_add_test (tc_chain, test_GstDateTime_iso8601);
|
||||
tcase_add_test (tc_chain, test_GstDateTime_to_g_date_time);
|
||||
tcase_add_test (tc_chain, test_GstDateTime_new_from_g_date_time);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -279,6 +279,7 @@ EXPORTS
|
|||
gst_date_time_has_time
|
||||
gst_date_time_has_year
|
||||
gst_date_time_new
|
||||
gst_date_time_new_from_g_date_time
|
||||
gst_date_time_new_from_iso8601_string
|
||||
gst_date_time_new_from_unix_epoch_local_time
|
||||
gst_date_time_new_from_unix_epoch_utc
|
||||
|
@ -289,6 +290,7 @@ EXPORTS
|
|||
gst_date_time_new_ym
|
||||
gst_date_time_new_ymd
|
||||
gst_date_time_ref
|
||||
gst_date_time_to_g_date_time
|
||||
gst_date_time_to_iso8601_string
|
||||
gst_date_time_unref
|
||||
gst_debug_add_log_function
|
||||
|
|
Loading…
Reference in a new issue