*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new_y (gint year)
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new_ym (gint year, gint month)
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new_ymd (gint year, gint month, gint day)
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new_from_unix_epoch_local_time (gint64 secs)
GDateTime *datetime;
datetime = g_date_time_new_from_unix_local (secs);
+ if (!datetime)
+ return NULL;
+
return gst_date_time_new_from_g_date_time (datetime);
}
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new_from_unix_epoch_utc (gint64 secs)
{
- GstDateTime *datetime;
- datetime =
- gst_date_time_new_from_g_date_time (g_date_time_new_from_unix_utc (secs));
- return datetime;
+ GDateTime *datetime;
+
+ datetime = g_date_time_new_from_unix_utc (secs);
+ if (!datetime)
+ return NULL;
+
+ return gst_date_time_new_from_g_date_time (datetime);
}
/**
* Creates a new #GstDateTime using the time since Jan 1, 1970 specified by
* @usecs. The #GstDateTime is in the local timezone.
*
- * Returns: (transfer full) (nullable): a newly created #GstDateTime
+ * Returns: (transfer full) (nullable): a newly created #GstDateTime, or %NULL
+ * on error.
*
* Since: 1.18
*/
gint64 usec_part = usecs % G_USEC_PER_SEC;
dt = g_date_time_new_from_unix_local (secs);
+ if (!dt)
+ return NULL;
datetime = g_date_time_add_seconds (dt, (gdouble) usec_part / G_USEC_PER_SEC);
g_date_time_unref (dt);
+ if (!datetime)
+ return NULL;
+
return gst_date_time_new_from_g_date_time (datetime);
}
* Creates a new #GstDateTime using the time since Jan 1, 1970 specified by
* @usecs. The #GstDateTime is in UTC.
*
- * Returns: (transfer full) (nullable): a newly created #GstDateTime
+ * Returns: (transfer full) (nullable): a newly created #GstDateTime, or %NULL
+ * on error.
*
* Since: 1.18
*/
gint64 usec_part = usecs % G_USEC_PER_SEC;
dt = g_date_time_new_from_unix_utc (secs);
+ if (!dt)
+ return NULL;
datetime = g_date_time_add_seconds (dt, (gdouble) usec_part / G_USEC_PER_SEC);
g_date_time_unref (dt);
+ if (!datetime)
+ return NULL;
+
return gst_date_time_new_from_g_date_time (datetime);
}
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
gint minute, gdouble seconds)
{
GstDateTimeFields fields;
+ GDateTime *dt;
GstDateTime *datetime;
- g_return_val_if_fail (year > 0 && year <= 9999, NULL);
- g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL);
- g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL);
- g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL);
- g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL);
- g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
+ if (year <= 0 || year > 9999)
+ return NULL;
+
+ if ((month <= 0 || month > 12) && month != -1)
+ return NULL;
+
+ if ((day <= 0 || day > 31) && day != -1)
+ return NULL;
+
+ if ((hour < 0 || hour >= 24) && hour != -1)
+ return NULL;
+
+ if ((minute < 0 || minute >= 60) && minute != -1)
+ return NULL;
+
+ if ((seconds < 0 || seconds >= 60) && seconds != -1)
+ return NULL;
fields = gst_date_time_check_fields (&year, &month, &day,
&hour, &minute, &seconds);
- datetime = gst_date_time_new_from_g_date_time (g_date_time_new_local (year,
- month, day, hour, minute, seconds));
+ dt = g_date_time_new_local (year, month, day, hour, minute, seconds);
+ if (dt == NULL)
+ return NULL;
+ datetime = gst_date_time_new_from_g_date_time (dt);
if (datetime == NULL)
return NULL;
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full): the newly created #GstDateTime which should
- * be freed with gst_date_time_unref().
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime which should
+ * be freed with gst_date_time_unref(), or %NULL on error.
*/
GstDateTime *
gst_date_time_new_now_local_time (void)
{
- return gst_date_time_new_from_g_date_time (g_date_time_new_now_local ());
+ GDateTime *dt;
+
+ dt = g_date_time_new_now_local ();
+ if (!dt)
+ return NULL;
+
+ return gst_date_time_new_from_g_date_time (dt);
}
/**
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full): the newly created #GstDateTime which should
- * be freed with gst_date_time_unref().
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime which should
+ * be freed with gst_date_time_unref(), or %NULL on error.
*/
GstDateTime *
gst_date_time_new_now_utc (void)
{
- return gst_date_time_new_from_g_date_time (g_date_time_new_now_utc ());
+ GDateTime *dt;
+
+ dt = g_date_time_new_now_utc ();
+ if (!dt)
+ return NULL;
+
+ return gst_date_time_new_from_g_date_time (dt);
}
gint
*
* Free-function: gst_date_time_unref
*
- * Return value: (transfer full) (nullable): the newly created #GstDateTime
+ * Return value: (transfer full) (nullable): the newly created #GstDateTime,
+ * or %NULL on error.
*/
GstDateTime *
gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour,
GstDateTime *datetime;
gint tzhour, tzminute;
- g_return_val_if_fail (year > 0 && year <= 9999, NULL);
- g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL);
- g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL);
- g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL);
- g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL);
- g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
- g_return_val_if_fail (tzoffset >= -12.0 && tzoffset <= 12.0, NULL);
- g_return_val_if_fail ((hour >= 0 && minute >= 0) ||
- (hour == -1 && minute == -1 && seconds == -1 && tzoffset == 0.0), NULL);
+ if (year <= 0 || year > 9999)
+ return NULL;
+
+ if ((month <= 0 || month > 12) && month != -1)
+ return NULL;
+
+ if ((day <= 0 || day > 31) && day != -1)
+ return NULL;
+
+ if ((hour < 0 || hour >= 24) && hour != -1)
+ return NULL;
+
+ if ((minute < 0 || minute >= 60) && minute != -1)
+ return NULL;
+
+ if ((seconds < 0 || seconds >= 60) && seconds != -1)
+ return NULL;
+
+ if (tzoffset < -12.0 || tzoffset > 12.0)
+ return NULL;
+
+ if ((hour < 0 || minute < 0) &&
+ (hour != -1 || minute != -1 || seconds != -1 || tzoffset != 0.0))
+ return NULL;
tzhour = (gint) ABS (tzoffset);
tzminute = (gint) ((ABS (tzoffset) - tzhour) * 60);
/* No date was supplied: make it today */
now_utc = g_date_time_new_now_utc ();
+ if (!now_utc)
+ return NULL;
+
if (tzoffset != 0.0) {
/* If a timezone offset was supplied, get the date of that timezone */
g_assert (gmt_offset_min != -99);
g_date_time_add_minutes (now_utc,
(60 * gmt_offset_hour) + gmt_offset_min);
g_date_time_unref (now_utc);
+ if (!now_in_given_tz)
+ return NULL;
} else {
now_in_given_tz = now_utc;
}