2 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
24 #include "gst_private.h"
25 #include "glib-compat-private.h"
26 #include "gstdatetime.h"
35 * @short_description: A date, time and timezone structure
37 * Struct to store date, time and timezone information altogether.
38 * #GstDateTime is refcounted and immutable.
40 * Date information is handled using the proleptic Gregorian calendar.
42 * Provides basic creation functions and accessor functions to its fields.
47 GST_DATE_TIME_FIELDS_INVALID = 0,
48 GST_DATE_TIME_FIELDS_Y, /* have year */
49 GST_DATE_TIME_FIELDS_YM, /* have year and month */
50 GST_DATE_TIME_FIELDS_YMD, /* have year, month and day */
51 GST_DATE_TIME_FIELDS_YMD_HM,
52 GST_DATE_TIME_FIELDS_YMD_HMS
53 /* Note: if we ever add more granularity here, e.g. for microsecs,
54 * the compare function will need updating */
59 GstMiniObject mini_object;
63 GstDateTimeFields fields;
66 GST_DEFINE_MINI_OBJECT_TYPE (GstDateTime, gst_date_time);
68 static void gst_date_time_free (GstDateTime * datetime);
71 * gst_date_time_new_from_g_date_time:
72 * @dt: (transfer full): the #GDateTime. The new #GstDateTime takes ownership.
74 * Creates a new #GstDateTime from a #GDateTime object.
76 * Free-function: gst_date_time_unref
78 * Returns: (transfer full): a newly created #GstDateTime, or %NULL on error
81 gst_date_time_new_from_g_date_time (GDateTime * dt)
88 gst_dt = g_slice_new (GstDateTime);
90 gst_mini_object_init (GST_MINI_OBJECT_CAST (gst_dt), 0, GST_TYPE_DATE_TIME,
91 NULL, NULL, (GstMiniObjectFreeFunction) gst_date_time_free);
93 gst_dt->datetime = dt;
94 gst_dt->fields = GST_DATE_TIME_FIELDS_YMD_HMS;
99 * gst_date_time_to_g_date_time:
100 * @datetime: GstDateTime.
102 * Creates a new #GDateTime from a fully defined #GstDateTime object.
104 * Free-function: g_date_time_unref
106 * Returns: (transfer full): a newly created #GDateTime, or %NULL on error
109 gst_date_time_to_g_date_time (GstDateTime * datetime)
111 g_return_val_if_fail (datetime != NULL, NULL);
113 if (datetime->fields != GST_DATE_TIME_FIELDS_YMD_HMS)
116 return g_date_time_add (datetime->datetime, 0);
120 * gst_date_time_has_year:
121 * @datetime: a #GstDateTime
123 * Returns: %TRUE if @datetime<!-- -->'s year field is set (which should always
124 * be the case), otherwise %FALSE
127 gst_date_time_has_year (const GstDateTime * datetime)
129 g_return_val_if_fail (datetime != NULL, FALSE);
131 return (datetime->fields >= GST_DATE_TIME_FIELDS_Y);
135 * gst_date_time_has_month:
136 * @datetime: a #GstDateTime
138 * Returns: %TRUE if @datetime<!-- -->'s month field is set, otherwise %FALSE
141 gst_date_time_has_month (const GstDateTime * datetime)
143 g_return_val_if_fail (datetime != NULL, FALSE);
145 return (datetime->fields >= GST_DATE_TIME_FIELDS_YM);
149 * gst_date_time_has_day:
150 * @datetime: a #GstDateTime
152 * Returns: %TRUE if @datetime<!-- -->'s day field is set, otherwise %FALSE
155 gst_date_time_has_day (const GstDateTime * datetime)
157 g_return_val_if_fail (datetime != NULL, FALSE);
159 return (datetime->fields >= GST_DATE_TIME_FIELDS_YMD);
163 * gst_date_time_has_time:
164 * @datetime: a #GstDateTime
166 * Returns: %TRUE if @datetime<!-- -->'s hour and minute fields are set,
170 gst_date_time_has_time (const GstDateTime * datetime)
172 g_return_val_if_fail (datetime != NULL, FALSE);
174 return (datetime->fields >= GST_DATE_TIME_FIELDS_YMD_HM);
178 * gst_date_time_has_second:
179 * @datetime: a #GstDateTime
181 * Returns: %TRUE if @datetime<!-- -->'s second field is set, otherwise %FALSE
184 gst_date_time_has_second (const GstDateTime * datetime)
186 g_return_val_if_fail (datetime != NULL, FALSE);
188 return (datetime->fields >= GST_DATE_TIME_FIELDS_YMD_HMS);
192 * gst_date_time_get_year:
193 * @datetime: a #GstDateTime
195 * Returns the year of this #GstDateTime
196 * Call gst_date_time_has_year before, to avoid warnings.
198 * Return value: The year of this #GstDateTime
201 gst_date_time_get_year (const GstDateTime * datetime)
203 g_return_val_if_fail (datetime != NULL, 0);
205 return g_date_time_get_year (datetime->datetime);
209 * gst_date_time_get_month:
210 * @datetime: a #GstDateTime
212 * Returns the month of this #GstDateTime. January is 1, February is 2, etc..
213 * Call gst_date_time_has_month before, to avoid warnings.
215 * Return value: The month of this #GstDateTime
218 gst_date_time_get_month (const GstDateTime * datetime)
220 g_return_val_if_fail (datetime != NULL, 0);
221 g_return_val_if_fail (gst_date_time_has_month (datetime), 0);
223 return g_date_time_get_month (datetime->datetime);
227 * gst_date_time_get_day:
228 * @datetime: a #GstDateTime
230 * Returns the day of the month of this #GstDateTime.
231 * Call gst_date_time_has_day before, to avoid warnings.
233 * Return value: The day of this #GstDateTime
236 gst_date_time_get_day (const GstDateTime * datetime)
238 g_return_val_if_fail (datetime != NULL, 0);
239 g_return_val_if_fail (gst_date_time_has_day (datetime), 0);
241 return g_date_time_get_day_of_month (datetime->datetime);
245 * gst_date_time_get_hour:
246 * @datetime: a #GstDateTime
248 * Retrieves the hour of the day represented by @datetime in the gregorian
249 * calendar. The return is in the range of 0 to 23.
250 * Call gst_date_time_has_haur before, to avoid warnings.
252 * Return value: the hour of the day
255 gst_date_time_get_hour (const GstDateTime * datetime)
257 g_return_val_if_fail (datetime != NULL, 0);
258 g_return_val_if_fail (gst_date_time_has_time (datetime), 0);
260 return g_date_time_get_hour (datetime->datetime);
264 * gst_date_time_get_minute:
265 * @datetime: a #GstDateTime
267 * Retrieves the minute of the hour represented by @datetime in the gregorian
269 * Call gst_date_time_has_minute before, to avoid warnings.
271 * Return value: the minute of the hour
274 gst_date_time_get_minute (const GstDateTime * datetime)
276 g_return_val_if_fail (datetime != NULL, 0);
277 g_return_val_if_fail (gst_date_time_has_time (datetime), 0);
279 return g_date_time_get_minute (datetime->datetime);
283 * gst_date_time_get_second:
284 * @datetime: a #GstDateTime
286 * Retrieves the second of the minute represented by @datetime in the gregorian
288 * Call gst_date_time_has_second before, to avoid warnings.
290 * Return value: the second represented by @datetime
293 gst_date_time_get_second (const GstDateTime * datetime)
295 g_return_val_if_fail (datetime != NULL, 0);
296 g_return_val_if_fail (gst_date_time_has_second (datetime), 0);
298 return g_date_time_get_second (datetime->datetime);
302 * gst_date_time_get_microsecond:
303 * @datetime: a #GstDateTime
305 * Retrieves the fractional part of the seconds in microseconds represented by
306 * @datetime in the gregorian calendar.
308 * Return value: the microsecond of the second
311 gst_date_time_get_microsecond (const GstDateTime * datetime)
313 g_return_val_if_fail (datetime != NULL, 0);
314 g_return_val_if_fail (gst_date_time_has_second (datetime), 0);
316 return g_date_time_get_microsecond (datetime->datetime);
320 * gst_date_time_get_time_zone_offset:
321 * @datetime: a #GstDateTime
323 * Retrieves the offset from UTC in hours that the timezone specified
324 * by @datetime represents. Timezones ahead (to the east) of UTC have positive
325 * values, timezones before (to the west) of UTC have negative values.
326 * If @datetime represents UTC time, then the offset is zero.
328 * Return value: the offset from UTC in hours
331 gst_date_time_get_time_zone_offset (const GstDateTime * datetime)
333 g_return_val_if_fail (datetime != NULL, 0.0);
334 g_return_val_if_fail (gst_date_time_has_time (datetime), 0.0);
336 return (g_date_time_get_utc_offset (datetime->datetime) /
337 G_USEC_PER_SEC) / 3600.0;
341 * gst_date_time_new_y:
342 * @year: the gregorian year
344 * Creates a new #GstDateTime using the date and times in the gregorian calendar
345 * in the local timezone.
347 * @year should be from 1 to 9999.
349 * Free-function: gst_date_time_unref
351 * Return value: (transfer full): the newly created #GstDateTime
354 gst_date_time_new_y (gint year)
356 return gst_date_time_new (0.0, year, -1, -1, -1, -1, -1);
360 * gst_date_time_new_ym:
361 * @year: the gregorian year
362 * @month: the gregorian month
364 * Creates a new #GstDateTime using the date and times in the gregorian calendar
365 * in the local timezone.
367 * @year should be from 1 to 9999, @month should be from 1 to 12.
369 * If value is -1 then all over value will be ignored. For example
370 * if @month == -1, then #GstDateTime will created only for @year.
372 * Free-function: gst_date_time_unref
374 * Return value: (transfer full): the newly created #GstDateTime
377 gst_date_time_new_ym (gint year, gint month)
379 return gst_date_time_new (0.0, year, month, -1, -1, -1, -1);
383 * gst_date_time_new_ymd:
384 * @year: the gregorian year
385 * @month: the gregorian month
386 * @day: the day of the gregorian month
388 * Creates a new #GstDateTime using the date and times in the gregorian calendar
389 * in the local timezone.
391 * @year should be from 1 to 9999, @month should be from 1 to 12, @day from
394 * If value is -1 then all over value will be ignored. For example
395 * if @month == -1, then #GstDateTime will created only for @year. If
396 * @day == -1, then #GstDateTime will created for @year and @month and
399 * Free-function: gst_date_time_unref
401 * Return value: (transfer full): the newly created #GstDateTime
404 gst_date_time_new_ymd (gint year, gint month, gint day)
406 return gst_date_time_new (0.0, year, month, day, -1, -1, -1);
410 * gst_date_time_new_from_unix_epoch_local_time:
411 * @secs: seconds from the Unix epoch
413 * Creates a new #GstDateTime using the time since Jan 1, 1970 specified by
414 * @secs. The #GstDateTime is in the local timezone.
416 * Free-function: gst_date_time_unref
418 * Return value: (transfer full): the newly created #GstDateTime
421 gst_date_time_new_from_unix_epoch_local_time (gint64 secs)
425 datetime = g_date_time_new_from_unix_local (secs);
426 return gst_date_time_new_from_g_date_time (datetime);
430 * gst_date_time_new_from_unix_epoch_utc:
431 * @secs: seconds from the Unix epoch
433 * Creates a new #GstDateTime using the time since Jan 1, 1970 specified by
434 * @secs. The #GstDateTime is in the UTC timezone.
436 * Free-function: gst_date_time_unref
438 * Return value: (transfer full): the newly created #GstDateTime
441 gst_date_time_new_from_unix_epoch_utc (gint64 secs)
443 GstDateTime *datetime;
445 gst_date_time_new_from_g_date_time (g_date_time_new_from_unix_utc (secs));
449 static GstDateTimeFields
450 gst_date_time_check_fields (gint * year, gint * month, gint * day,
451 gint * hour, gint * minute, gdouble * seconds)
455 *hour = *minute = *seconds = 0;
456 return GST_DATE_TIME_FIELDS_Y;
457 } else if (*day == -1) {
459 *hour = *minute = *seconds = 0;
460 return GST_DATE_TIME_FIELDS_YM;
461 } else if (*hour == -1) {
462 *hour = *minute = *seconds = 0;
463 return GST_DATE_TIME_FIELDS_YMD;
464 } else if (*seconds == -1) {
466 return GST_DATE_TIME_FIELDS_YMD_HM;
468 return GST_DATE_TIME_FIELDS_YMD_HMS;
472 * gst_date_time_new_local_time:
473 * @year: the gregorian year
474 * @month: the gregorian month, or -1
475 * @day: the day of the gregorian month, or -1
476 * @hour: the hour of the day, or -1
477 * @minute: the minute of the hour, or -1
478 * @seconds: the second of the minute, or -1
480 * Creates a new #GstDateTime using the date and times in the gregorian calendar
481 * in the local timezone.
483 * @year should be from 1 to 9999, @month should be from 1 to 12, @day from
484 * 1 to 31, @hour from 0 to 23, @minutes and @seconds from 0 to 59.
486 * If @month is -1, then the #GstDateTime created will only contain @year,
487 * and all other fields will be considered not set.
489 * If @day is -1, then the #GstDateTime created will only contain @year and
490 * @month and all other fields will be considered not set.
492 * If @hour is -1, then the #GstDateTime created will only contain @year and
493 * @month and @day, and the time fields will be considered not set. In this
494 * case @minute and @seconds should also be -1.
496 * Free-function: gst_date_time_unref
498 * Return value: (transfer full): the newly created #GstDateTime
501 gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
502 gint minute, gdouble seconds)
504 GstDateTimeFields fields;
505 GstDateTime *datetime;
507 g_return_val_if_fail (year > 0 && year <= 9999, NULL);
508 g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL);
509 g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL);
510 g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL);
511 g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL);
512 g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
514 fields = gst_date_time_check_fields (&year, &month, &day,
515 &hour, &minute, &seconds);
517 datetime = gst_date_time_new_from_g_date_time (g_date_time_new_local (year,
518 month, day, hour, minute, seconds));
520 datetime->fields = fields;
525 * gst_date_time_new_now_local_time:
527 * Creates a new #GstDateTime representing the current date and time.
529 * Free-function: gst_date_time_unref
531 * Return value: (transfer full): the newly created #GstDateTime which should
532 * be freed with gst_date_time_unref().
535 gst_date_time_new_now_local_time (void)
537 return gst_date_time_new_from_g_date_time (g_date_time_new_now_local ());
541 * gst_date_time_new_now_utc:
543 * Creates a new #GstDateTime that represents the current instant at Universal
546 * Free-function: gst_date_time_unref
548 * Return value: (transfer full): the newly created #GstDateTime which should
549 * be freed with gst_date_time_unref().
552 gst_date_time_new_now_utc (void)
554 return gst_date_time_new_from_g_date_time (g_date_time_new_now_utc ());
558 __gst_date_time_compare (const GstDateTime * dt1, const GstDateTime * dt2)
562 /* we assume here that GST_DATE_TIME_FIELDS_YMD_HMS is the highest
563 * resolution, and ignore microsecond differences on purpose for now */
564 if (dt1->fields != dt2->fields)
565 return GST_VALUE_UNORDERED;
567 /* This will round down to nearest second, which is what we want. We're
568 * not comparing microseconds on purpose here, since we're not
569 * serialising them when doing new_utc_now() + to_string() */
571 g_date_time_to_unix (dt1->datetime) - g_date_time_to_unix (dt2->datetime);
573 return GST_VALUE_LESS_THAN;
575 return GST_VALUE_GREATER_THAN;
577 return GST_VALUE_EQUAL;
582 * @tzoffset: Offset from UTC in hours.
583 * @year: the gregorian year
584 * @month: the gregorian month
585 * @day: the day of the gregorian month
586 * @hour: the hour of the day
587 * @minute: the minute of the hour
588 * @seconds: the second of the minute
590 * Creates a new #GstDateTime using the date and times in the gregorian calendar
591 * in the supplied timezone.
593 * @year should be from 1 to 9999, @month should be from 1 to 12, @day from
594 * 1 to 31, @hour from 0 to 23, @minutes and @seconds from 0 to 59.
596 * Note that @tzoffset is a float and was chosen so for being able to handle
597 * some fractional timezones, while it still keeps the readability of
598 * representing it in hours for most timezones.
600 * If value is -1 then all over value will be ignored. For example
601 * if @month == -1, then #GstDateTime will created only for @year. If
602 * @day == -1, then #GstDateTime will created for @year and @month and
605 * Free-function: gst_date_time_unref
607 * Return value: (transfer full): the newly created #GstDateTime
610 gst_date_time_new (gfloat tzoffset, gint year, gint month, gint day, gint hour,
611 gint minute, gdouble seconds)
613 GstDateTimeFields fields;
617 GstDateTime *datetime;
618 gint tzhour, tzminute;
620 g_return_val_if_fail (year > 0 && year <= 9999, NULL);
621 g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL);
622 g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL);
623 g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL);
624 g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL);
625 g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
626 g_return_val_if_fail (tzoffset >= -12.0 && tzoffset <= 12.0, NULL);
627 g_return_val_if_fail ((hour >= 0 && minute >= 0) ||
628 (hour == -1 && minute == -1 && seconds == -1 && tzoffset == 0.0), NULL);
630 tzhour = (gint) ABS (tzoffset);
631 tzminute = (gint) ((ABS (tzoffset) - tzhour) * 60);
633 g_snprintf (buf, 6, "%c%02d%02d", tzoffset >= 0 ? '+' : '-', tzhour,
636 tz = g_time_zone_new (buf);
638 fields = gst_date_time_check_fields (&year, &month, &day,
639 &hour, &minute, &seconds);
641 dt = g_date_time_new (tz, year, month, day, hour, minute, seconds);
642 g_time_zone_unref (tz);
644 datetime = gst_date_time_new_from_g_date_time (dt);
645 datetime->fields = fields;
651 __gst_date_time_serialize (GstDateTime * datetime, gboolean serialize_usecs)
657 /* we always have at least the year */
658 s = g_string_new (NULL);
659 g_string_append_printf (s, "%04u", gst_date_time_get_year (datetime));
661 if (datetime->fields == GST_DATE_TIME_FIELDS_Y)
665 g_string_append_printf (s, "-%02u", gst_date_time_get_month (datetime));
667 if (datetime->fields == GST_DATE_TIME_FIELDS_YM)
670 /* add day of month */
671 g_string_append_printf (s, "-%02u", gst_date_time_get_day (datetime));
673 if (datetime->fields == GST_DATE_TIME_FIELDS_YMD)
677 g_string_append_printf (s, "T%02u:%02u", gst_date_time_get_hour (datetime),
678 gst_date_time_get_minute (datetime));
680 if (datetime->fields == GST_DATE_TIME_FIELDS_YMD_HM)
684 g_string_append_printf (s, ":%02u", gst_date_time_get_second (datetime));
686 /* add microseconds */
687 if (serialize_usecs) {
688 msecs = gst_date_time_get_microsecond (datetime);
690 g_string_append_printf (s, ".%06u", msecs);
691 /* trim trailing 0s */
692 while (s->str[s->len - 1] == '0')
693 g_string_truncate (s, s->len - 1);
701 gmt_offset = gst_date_time_get_time_zone_offset (datetime);
702 if (gmt_offset == 0) {
703 g_string_append_c (s, 'Z');
705 guint tzhour, tzminute;
707 tzhour = (guint) ABS (gmt_offset);
708 tzminute = (guint) ((ABS (gmt_offset) - tzhour) * 60);
710 g_string_append_c (s, (gmt_offset >= 0) ? '+' : '-');
711 g_string_append_printf (s, "%02u%02u", tzhour, tzminute);
716 return g_string_free (s, FALSE);
720 * gst_date_time_to_iso8601_string:
721 * @datetime: GstDateTime.
723 * Create a minimal string compatible with ISO-8601. Possible output formats
724 * are (for example): 2012, 2012-06, 2012-06-23, 2012-06-23T23:30Z,
725 * 2012-06-23T23:30+0100, 2012-06-23T23:30:59Z, 2012-06-23T23:30:59+0100
727 * Returns: a newly allocated string formatted according to ISO 8601 and
728 * only including the datetime fields that are valid, or %NULL in case
729 * there was an error. The string should be freed with g_free().
732 gst_date_time_to_iso8601_string (GstDateTime * datetime)
734 g_return_val_if_fail (datetime != NULL, NULL);
736 if (datetime->fields == GST_DATE_TIME_FIELDS_INVALID)
739 return __gst_date_time_serialize (datetime, FALSE);
743 * gst_date_time_new_from_iso8601_string:
744 * @string: ISO 8601-formatted datetime string.
746 * Tries to parse common variants of ISO-8601 datetime strings into a
749 * Free-function: gst_date_time_unref
751 * Returns: (transfer full): a newly created #GstDateTime, or %NULL on error
754 gst_date_time_new_from_iso8601_string (const gchar * string)
756 gint year = -1, month = -1, day = -1, hour = -1, minute = -1;
757 gdouble second = -1.0;
758 gfloat tzoffset = 0.0;
762 g_return_val_if_fail (string != NULL, NULL);
764 GST_DEBUG ("Parsing '%s' into a datetime", string);
766 len = strlen (string);
768 if (len < 4 || !g_ascii_isdigit (string[0]) || !g_ascii_isdigit (string[1])
769 || !g_ascii_isdigit (string[2]) || !g_ascii_isdigit (string[3]))
772 ret = sscanf (string, "%04d-%02d-%02d", &year, &month, &day);
777 if (ret == 3 && day <= 0) {
782 if (ret >= 2 && month <= 0) {
787 if (ret >= 1 && year <= 0)
790 else if (ret >= 1 && len < 16)
791 /* YMD is 10 chars. XMD + HM will be 16 chars. if it is less,
792 * it make no sense to continue. We will stay with YMD. */
796 /* Exit if there is no expeceted value on this stage */
797 if (!(*string == 'T' || *string == '-' || *string == ' '))
800 /* if hour or minute fails, then we will use onlly ymd. */
801 hour = g_ascii_strtoull (string + 1, (gchar **) & string, 10);
802 if (hour > 24 || *string != ':')
806 minute = g_ascii_strtoull (string + 1, (gchar **) & string, 10);
811 if (*string == ':') {
812 second = g_ascii_strtoull (string + 1, (gchar **) & string, 10);
813 /* if we fail here, we still can reuse hour and minute. We
814 * will still attempt to parse any timezone information */
819 if (*string == '.' || *string == ',') {
820 const gchar *usec_start = string + 1;
823 usecs = g_ascii_strtoull (string + 1, (gchar **) & string, 10);
824 if (usecs != G_MAXUINT64 && string > usec_start) {
825 digits = (guint) (string - usec_start);
826 second += (gdouble) usecs / pow (10.0, digits);
835 /* reuse some code from gst-plugins-base/gst-libs/gst/tag/gstxmptag.c */
836 gint gmt_offset_hour = -1, gmt_offset_min = -1, gmt_offset = -1;
837 gchar *plus_pos = NULL;
838 gchar *neg_pos = NULL;
841 GST_LOG ("Checking for timezone information");
843 /* check if there is timezone info */
844 plus_pos = strrchr (string, '+');
845 neg_pos = strrchr (string, '-');
854 ret_tz = sscanf (pos, "%d:%d", &gmt_offset_hour, &gmt_offset_min);
856 ret_tz = sscanf (pos, "%02d%02d", &gmt_offset_hour, &gmt_offset_min);
858 GST_DEBUG ("Parsing timezone: %s", pos);
861 gmt_offset = gmt_offset_hour * 60 + gmt_offset_min;
862 if (neg_pos != NULL && neg_pos + 1 == pos)
865 tzoffset = gmt_offset / 60.0;
867 GST_LOG ("Timezone offset: %f (%d minutes)", tzoffset, gmt_offset);
869 GST_WARNING ("Failed to parse timezone information");
874 return gst_date_time_new (tzoffset, year, month, day, hour, minute, second);
876 return gst_date_time_new_ymd (year, month, day);
880 gst_date_time_free (GstDateTime * datetime)
882 g_date_time_unref (datetime->datetime);
883 g_slice_free (GstDateTime, datetime);
888 * @datetime: a #GstDateTime
890 * Atomically increments the reference count of @datetime by one.
892 * Return value: (transfer full): the reference @datetime
895 gst_date_time_ref (GstDateTime * datetime)
897 return (GstDateTime *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (datetime));
901 * gst_date_time_unref:
902 * @datetime: (transfer full): a #GstDateTime
904 * Atomically decrements the reference count of @datetime by one. When the
905 * reference count reaches zero, the structure is freed.
908 gst_date_time_unref (GstDateTime * datetime)
910 gst_mini_object_unref (GST_MINI_OBJECT_CAST (datetime));