mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 13:06:14 +01:00
gbookmarkfile: Use GDateTime instead of GTimeVal internally
Avoid using a deprecated type. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #1438
This commit is contained in:
parent
aa261ca24a
commit
a3f22f0c2c
@ -245,8 +245,10 @@ static void g_bookmark_file_add_item (GBookmarkFile *bookmark,
|
||||
BookmarkItem *item,
|
||||
GError **error);
|
||||
|
||||
static time_t timestamp_from_iso8601 (const gchar *iso_date);
|
||||
static gchar * timestamp_to_iso8601 (time_t timestamp);
|
||||
static gboolean timestamp_from_iso8601 (const gchar *iso_date,
|
||||
time_t *out_timestamp,
|
||||
GError **error);
|
||||
static gchar *timestamp_to_iso8601 (time_t timestamp);
|
||||
|
||||
/********************************
|
||||
* BookmarkAppInfo *
|
||||
@ -772,14 +774,14 @@ parse_bookmark_element (GMarkupParseContext *context,
|
||||
|
||||
item = bookmark_item_new (uri);
|
||||
|
||||
if (added)
|
||||
item->added = timestamp_from_iso8601 (added);
|
||||
if (added != NULL && !timestamp_from_iso8601 (added, &item->added, error))
|
||||
return;
|
||||
|
||||
if (modified)
|
||||
item->modified = timestamp_from_iso8601 (modified);
|
||||
if (modified != NULL && !timestamp_from_iso8601 (modified, &item->modified, error))
|
||||
return;
|
||||
|
||||
if (visited)
|
||||
item->visited = timestamp_from_iso8601 (visited);
|
||||
if (visited != NULL && !timestamp_from_iso8601 (visited, &item->visited, error))
|
||||
return;
|
||||
|
||||
add_error = NULL;
|
||||
g_bookmark_file_add_item (parse_data->bookmark_file,
|
||||
@ -872,8 +874,11 @@ parse_application_element (GMarkupParseContext *context,
|
||||
else
|
||||
ai->count = 1;
|
||||
|
||||
if (modified)
|
||||
ai->stamp = timestamp_from_iso8601 (modified);
|
||||
if (modified != NULL)
|
||||
{
|
||||
if (!timestamp_from_iso8601 (modified, &ai->stamp, error))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the timestamp attribute has been deprecated but we still parse
|
||||
@ -1591,28 +1596,32 @@ out:
|
||||
static gchar *
|
||||
timestamp_to_iso8601 (time_t timestamp)
|
||||
{
|
||||
GTimeVal stamp;
|
||||
GDateTime *dt = g_date_time_new_from_unix_utc (timestamp);
|
||||
gchar *iso8601_string = g_date_time_format_iso8601 (dt);
|
||||
g_date_time_unref (dt);
|
||||
|
||||
if (timestamp == (time_t) -1)
|
||||
g_get_current_time (&stamp);
|
||||
else
|
||||
{
|
||||
stamp.tv_sec = timestamp;
|
||||
stamp.tv_usec = 0;
|
||||
}
|
||||
|
||||
return g_time_val_to_iso8601 (&stamp);
|
||||
return g_steal_pointer (&iso8601_string);
|
||||
}
|
||||
|
||||
static time_t
|
||||
timestamp_from_iso8601 (const gchar *iso_date)
|
||||
static gboolean
|
||||
timestamp_from_iso8601 (const gchar *iso_date,
|
||||
time_t *out_timestamp,
|
||||
GError **error)
|
||||
{
|
||||
GTimeVal stamp;
|
||||
gint64 time_val;
|
||||
GDateTime *dt = g_date_time_new_from_iso8601 (iso_date, NULL);
|
||||
if (dt == NULL)
|
||||
{
|
||||
g_set_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_READ,
|
||||
_("Invalid date/time ‘%s’ in bookmark file"), iso_date);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_time_val_from_iso8601 (iso_date, &stamp))
|
||||
return (time_t) -1;
|
||||
time_val = g_date_time_to_unix (dt);
|
||||
g_date_time_unref (dt);
|
||||
|
||||
return (time_t) stamp.tv_sec;
|
||||
*out_timestamp = time_val;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
G_DEFINE_QUARK (g-bookmark-file-error-quark, g_bookmark_file_error)
|
||||
|
Loading…
Reference in New Issue
Block a user