2644 | 2644 |
|
2645 | 2645 |
return ret;
|
2646 | 2646 |
}
|
|
2647 |
|
|
2648 |
/**
|
|
2649 |
* gupnp_format_date_time_for_didl_lite:
|
|
2650 |
* @date_time: DateTime to format
|
|
2651 |
*
|
|
2652 |
* Get the representation of DateTime as an ISO8601 string.
|
|
2653 |
*
|
|
2654 |
* DLNA requires a specific subset of ISO8601
|
|
2655 |
* Returns: (transfer full): @date_time formatted as an ISO8601 string
|
|
2656 |
*/
|
|
2657 |
char *
|
|
2658 |
gupnp_format_date_time_for_didl_lite (GDateTime *date_time, gboolean date_only)
|
|
2659 |
{
|
|
2660 |
g_return_val_if_fail (date_time != NULL, NULL);
|
|
2661 |
|
|
2662 |
if (date_only) {
|
|
2663 |
return g_date_time_format (date_time, "%F");
|
|
2664 |
}
|
|
2665 |
|
|
2666 |
const char *format = "%FT%H:%M:%S";
|
|
2667 |
char *base_string = g_date_time_format (date_time, format);
|
|
2668 |
GString *iso_string = g_string_new (base_string);
|
|
2669 |
|
|
2670 |
// Check if we have sub-second precision. If so, we use that as well,
|
|
2671 |
// but cannot use %f since that will use microsecond precision, but DLNA
|
|
2672 |
// only allows for millisecond so we append the milliseconds manually
|
|
2673 |
if (g_date_time_get_microsecond (date_time) % G_TIME_SPAN_SECOND != 0) {
|
|
2674 |
g_string_append_printf (
|
|
2675 |
iso_string,
|
|
2676 |
".%03d",
|
|
2677 |
g_date_time_get_microsecond (date_time) / 1000);
|
|
2678 |
}
|
|
2679 |
|
|
2680 |
GTimeSpan utc_offset = g_date_time_get_utc_offset (date_time);
|
|
2681 |
if (utc_offset == 0) {
|
|
2682 |
g_string_append (iso_string, "Z");
|
|
2683 |
} else {
|
|
2684 |
char *time_zone = g_date_time_format (date_time, "%:z");
|
|
2685 |
g_string_append (iso_string, time_zone);
|
|
2686 |
g_free (time_zone);
|
|
2687 |
}
|
|
2688 |
|
|
2689 |
g_free (base_string);
|
|
2690 |
|
|
2691 |
return g_string_free (iso_string, FALSE);
|
|
2692 |
}
|