502 */
503 GstDateTime *
504 gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
505 gint minute, gdouble seconds)
506 {
507 GstDateTimeFields fields;
508 GstDateTime *datetime;
509
510 g_return_val_if_fail (year > 0 && year <= 9999, NULL);
511 g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL);
512 g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL);
513 g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL);
514 g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL);
515 g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
516
517 fields = gst_date_time_check_fields (&year, &month, &day,
518 &hour, &minute, &seconds);
519
520 datetime = gst_date_time_new_from_g_date_time (g_date_time_new_local (year,
521 month, day, hour, minute, seconds));
522
523 datetime->fields = fields;
524 return datetime;
525 }
526
527 /**
528 * gst_date_time_new_now_local_time:
529 *
530 * Creates a new #GstDateTime representing the current date and time.
531 *
532 * Free-function: gst_date_time_unref
533 *
534 * Return value: (transfer full): the newly created #GstDateTime which should
535 * be freed with gst_date_time_unref().
536 */
537 GstDateTime *
538 gst_date_time_new_now_local_time (void)
539 {
540 return gst_date_time_new_from_g_date_time (g_date_time_new_now_local ());
541 }
628 g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
629 g_return_val_if_fail (tzoffset >= -12.0 && tzoffset <= 12.0, NULL);
630 g_return_val_if_fail ((hour >= 0 && minute >= 0) ||
631 (hour == -1 && minute == -1 && seconds == -1 && tzoffset == 0.0), NULL);
632
633 tzhour = (gint) ABS (tzoffset);
634 tzminute = (gint) ((ABS (tzoffset) - tzhour) * 60);
635
636 g_snprintf (buf, 6, "%c%02d%02d", tzoffset >= 0 ? '+' : '-', tzhour,
637 tzminute);
638
639 tz = g_time_zone_new (buf);
640
641 fields = gst_date_time_check_fields (&year, &month, &day,
642 &hour, &minute, &seconds);
643
644 dt = g_date_time_new (tz, year, month, day, hour, minute, seconds);
645 g_time_zone_unref (tz);
646
647 datetime = gst_date_time_new_from_g_date_time (dt);
648 datetime->fields = fields;
649
650 return datetime;
651 }
652
653 gchar *
654 __gst_date_time_serialize (GstDateTime * datetime, gboolean serialize_usecs)
655 {
656 GString *s;
657 gfloat gmt_offset;
658 guint msecs;
659
660 /* we always have at least the year */
661 s = g_string_new (NULL);
662 g_string_append_printf (s, "%04u", gst_date_time_get_year (datetime));
663
664 if (datetime->fields == GST_DATE_TIME_FIELDS_Y)
665 goto done;
666
667 /* add month */
|
502 */
503 GstDateTime *
504 gst_date_time_new_local_time (gint year, gint month, gint day, gint hour,
505 gint minute, gdouble seconds)
506 {
507 GstDateTimeFields fields;
508 GstDateTime *datetime;
509
510 g_return_val_if_fail (year > 0 && year <= 9999, NULL);
511 g_return_val_if_fail ((month > 0 && month <= 12) || month == -1, NULL);
512 g_return_val_if_fail ((day > 0 && day <= 31) || day == -1, NULL);
513 g_return_val_if_fail ((hour >= 0 && hour < 24) || hour == -1, NULL);
514 g_return_val_if_fail ((minute >= 0 && minute < 60) || minute == -1, NULL);
515 g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
516
517 fields = gst_date_time_check_fields (&year, &month, &day,
518 &hour, &minute, &seconds);
519
520 datetime = gst_date_time_new_from_g_date_time (g_date_time_new_local (year,
521 month, day, hour, minute, seconds));
522 #ifdef GSTREAMER_LITE
523 if (datetime == NULL)
524 return NULL;
525 #endif // GSTREAMER_LITE
526
527 datetime->fields = fields;
528 return datetime;
529 }
530
531 /**
532 * gst_date_time_new_now_local_time:
533 *
534 * Creates a new #GstDateTime representing the current date and time.
535 *
536 * Free-function: gst_date_time_unref
537 *
538 * Return value: (transfer full): the newly created #GstDateTime which should
539 * be freed with gst_date_time_unref().
540 */
541 GstDateTime *
542 gst_date_time_new_now_local_time (void)
543 {
544 return gst_date_time_new_from_g_date_time (g_date_time_new_now_local ());
545 }
632 g_return_val_if_fail ((seconds >= 0 && seconds < 60) || seconds == -1, NULL);
633 g_return_val_if_fail (tzoffset >= -12.0 && tzoffset <= 12.0, NULL);
634 g_return_val_if_fail ((hour >= 0 && minute >= 0) ||
635 (hour == -1 && minute == -1 && seconds == -1 && tzoffset == 0.0), NULL);
636
637 tzhour = (gint) ABS (tzoffset);
638 tzminute = (gint) ((ABS (tzoffset) - tzhour) * 60);
639
640 g_snprintf (buf, 6, "%c%02d%02d", tzoffset >= 0 ? '+' : '-', tzhour,
641 tzminute);
642
643 tz = g_time_zone_new (buf);
644
645 fields = gst_date_time_check_fields (&year, &month, &day,
646 &hour, &minute, &seconds);
647
648 dt = g_date_time_new (tz, year, month, day, hour, minute, seconds);
649 g_time_zone_unref (tz);
650
651 datetime = gst_date_time_new_from_g_date_time (dt);
652 #ifdef GSTREAMER_LITE
653 if (datetime == NULL)
654 return NULL;
655 #endif // GSTREAMER_LITE
656 datetime->fields = fields;
657
658 return datetime;
659 }
660
661 gchar *
662 __gst_date_time_serialize (GstDateTime * datetime, gboolean serialize_usecs)
663 {
664 GString *s;
665 gfloat gmt_offset;
666 guint msecs;
667
668 /* we always have at least the year */
669 s = g_string_new (NULL);
670 g_string_append_printf (s, "%04u", gst_date_time_get_year (datetime));
671
672 if (datetime->fields == GST_DATE_TIME_FIELDS_Y)
673 goto done;
674
675 /* add month */
|