mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 17:56:17 +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,
|
BookmarkItem *item,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
static time_t timestamp_from_iso8601 (const gchar *iso_date);
|
static gboolean timestamp_from_iso8601 (const gchar *iso_date,
|
||||||
static gchar * timestamp_to_iso8601 (time_t timestamp);
|
time_t *out_timestamp,
|
||||||
|
GError **error);
|
||||||
|
static gchar *timestamp_to_iso8601 (time_t timestamp);
|
||||||
|
|
||||||
/********************************
|
/********************************
|
||||||
* BookmarkAppInfo *
|
* BookmarkAppInfo *
|
||||||
@ -772,14 +774,14 @@ parse_bookmark_element (GMarkupParseContext *context,
|
|||||||
|
|
||||||
item = bookmark_item_new (uri);
|
item = bookmark_item_new (uri);
|
||||||
|
|
||||||
if (added)
|
if (added != NULL && !timestamp_from_iso8601 (added, &item->added, error))
|
||||||
item->added = timestamp_from_iso8601 (added);
|
return;
|
||||||
|
|
||||||
if (modified)
|
if (modified != NULL && !timestamp_from_iso8601 (modified, &item->modified, error))
|
||||||
item->modified = timestamp_from_iso8601 (modified);
|
return;
|
||||||
|
|
||||||
if (visited)
|
if (visited != NULL && !timestamp_from_iso8601 (visited, &item->visited, error))
|
||||||
item->visited = timestamp_from_iso8601 (visited);
|
return;
|
||||||
|
|
||||||
add_error = NULL;
|
add_error = NULL;
|
||||||
g_bookmark_file_add_item (parse_data->bookmark_file,
|
g_bookmark_file_add_item (parse_data->bookmark_file,
|
||||||
@ -872,8 +874,11 @@ parse_application_element (GMarkupParseContext *context,
|
|||||||
else
|
else
|
||||||
ai->count = 1;
|
ai->count = 1;
|
||||||
|
|
||||||
if (modified)
|
if (modified != NULL)
|
||||||
ai->stamp = timestamp_from_iso8601 (modified);
|
{
|
||||||
|
if (!timestamp_from_iso8601 (modified, &ai->stamp, error))
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* the timestamp attribute has been deprecated but we still parse
|
/* the timestamp attribute has been deprecated but we still parse
|
||||||
@ -1591,28 +1596,32 @@ out:
|
|||||||
static gchar *
|
static gchar *
|
||||||
timestamp_to_iso8601 (time_t timestamp)
|
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)
|
return g_steal_pointer (&iso8601_string);
|
||||||
g_get_current_time (&stamp);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stamp.tv_sec = timestamp;
|
|
||||||
stamp.tv_usec = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_time_val_to_iso8601 (&stamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static time_t
|
static gboolean
|
||||||
timestamp_from_iso8601 (const gchar *iso_date)
|
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))
|
time_val = g_date_time_to_unix (dt);
|
||||||
return (time_t) -1;
|
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)
|
G_DEFINE_QUARK (g-bookmark-file-error-quark, g_bookmark_file_error)
|
||||||
|
Loading…
Reference in New Issue
Block a user