Coverage Report

Created: 2026-05-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tinysparql/src/common/tracker-date-time.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2006, Jamie McCracken <jamiemcc@gnome.org>
3
 * Copyright (C) 2008-2010, Nokia <ivan.frade@nokia.com>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the
17
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA  02110-1301, USA.
19
 */
20
21
#include "config.h"
22
23
#include <glib.h>
24
25
#include "tracker-date-time.h"
26
27
0
GQuark tracker_date_error_quark (void) {
28
0
  return g_quark_from_static_string ("tracker_date_error-quark");
29
0
}
30
31
GDateTime *
32
tracker_date_new_from_iso8601 (GTimeZone    *tz,
33
                               const gchar  *string,
34
                               GError      **error)
35
0
{
36
0
  GDateTime *datetime;
37
38
0
  datetime = g_date_time_new_from_iso8601 (string, tz);
39
40
0
  if (!datetime) {
41
0
    g_set_error (error,
42
0
           TRACKER_DATE_ERROR,
43
0
           TRACKER_DATE_ERROR_INVALID_ISO8601,
44
0
                 "'%s' is not a ISO 8601 date string. "
45
0
           "Allowed form is CCYY-MM-DDThh:mm:ss[.ssssss][Z|(+|-)hh:mm]",
46
0
           string);
47
0
  }
48
49
0
  return datetime;
50
0
}
51
52
gchar *
53
tracker_date_format_iso8601 (GDateTime *datetime)
54
0
{
55
0
  gboolean has_offset, has_subsecond;
56
57
0
  has_offset = g_date_time_get_utc_offset (datetime) != 0;
58
0
  has_subsecond = g_date_time_get_microsecond (datetime) != 0;
59
60
0
  if (has_offset && has_subsecond)
61
0
    return g_date_time_format (datetime, "%C%y-%m-%dT%H:%M:%S.%f%:z");
62
0
  else if (has_offset)
63
0
    return g_date_time_format (datetime, "%C%y-%m-%dT%T%:z");
64
0
  else if (has_subsecond)
65
0
    return g_date_time_format (datetime, "%C%y-%m-%dT%H:%M:%S.%fZ");
66
0
  else
67
0
    return g_date_time_format (datetime, "%C%y-%m-%dT%TZ");
68
0
}