[tracker/wip/carlosg/lost-subseconds] libtracker-common: Do not miss subsecond info printing iso8601 dates
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/lost-subseconds] libtracker-common: Do not miss subsecond info printing iso8601 dates
- Date: Mon, 14 Mar 2022 15:46:41 +0000 (UTC)
commit 7b5ace74d80f3f6009782c7f0616f119d72df7c2
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Mar 14 16:38:28 2022 +0100
libtracker-common: Do not miss subsecond info printing iso8601 dates
We used %T as a shortcut to print times, but that translates to %H:%M:%S
and misses subsecond information. To avoid that, check whether the passed
GDateTime contains subsecond information and resort to %H:%M:%S.%f in that
case.
Since we prefer shorter iso8601 strings for storage purposes, combine
this handling with the existing paths for timezone information, so iso8601
strings that don't need either can cut down those extra chars.
Fixes subsecond information being lost on database inserts, and possibly
other date comparison/printing misbehaviors.
src/libtracker-common/tracker-date-time.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-common/tracker-date-time.c b/src/libtracker-common/tracker-date-time.c
index bfc05c782..494b9f5cc 100644
--- a/src/libtracker-common/tracker-date-time.c
+++ b/src/libtracker-common/tracker-date-time.c
@@ -54,8 +54,17 @@ tracker_date_new_from_iso8601 (const gchar *string,
gchar *
tracker_date_format_iso8601 (GDateTime *datetime)
{
- if (g_date_time_get_utc_offset (datetime) == 0)
- return g_date_time_format (datetime, "%C%y-%m-%dT%TZ");
- else
+ gboolean has_offset, has_subsecond;
+
+ has_offset = g_date_time_get_utc_offset (datetime) != 0;
+ has_subsecond = g_date_time_get_microsecond (datetime) != 0;
+
+ if (has_offset && has_subsecond)
+ return g_date_time_format (datetime, "%C%y-%m-%dT%H:%M:%S.%f%:z");
+ else if (has_offset)
return g_date_time_format (datetime, "%C%y-%m-%dT%T%:z");
+ else if (has_subsecond)
+ return g_date_time_format (datetime, "%C%y-%m-%dT%H:%M:%S.%fZ");
+ else
+ return g_date_time_format (datetime, "%C%y-%m-%dT%TZ");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]