static GDateTime* item_cursor_to_time (TrackerSparqlCursor *cursor) { const gchar *date; GTimeVal val; date = tracker_sparql_cursor_get_string (cursor, 6, NULL); g_time_val_from_iso8601 (date, &val); return g_date_time_new_from_timeval_local (&val); }
static GDateTime* gnc_g_date_time_new_from_timeval_local (const GTimeVal* tv) { #ifndef G_OS_WIN32 return g_date_time_new_from_timeval_local (tv); #else GTimeZone *tz = gnc_g_time_zone_new_local (); GDateTime *gdt = g_date_time_new_from_timeval_utc (tv); if (!gdt) return gdt; return gnc_g_date_time_adjust_for_dst (gdt, tz); #endif }
static void pkg_window_connection_subscription_get_created_at_cb (GObject *object, /* IN */ GAsyncResult *result, /* IN */ gpointer user_data) /* IN */ { PkgWindowSubscriptionCall *call = user_data; PkConnection *connection; PkgWindowPrivate *priv; gchar *subtitle = NULL; GError *error = NULL; GtkTreeIter iter; GtkTreeIter child; GDateTime *dt; GTimeVal tv; g_return_if_fail(user_data != NULL); ENTRY; priv = call->window->priv; connection = PK_CONNECTION(object); if (!pk_connection_subscription_get_created_at_finish(connection, result, &tv, &error)) { WARNING(Connection, "Error retrieving subscription created-at: %s", error->message); g_error_free(error); EXIT; } if (!pkg_window_get_subscriptions_iter(call->window, connection, &iter)) { GOTO(iter_not_found); } if (!pkg_window_get_child_iter_with_id(call->window, connection, &iter, &child, call->subscription)) { GOTO(iter_not_found); } dt = g_date_time_new_from_timeval_local(&tv); subtitle = g_date_time_format(dt, _("Created on %x at %X")); g_date_time_unref(dt); gtk_tree_store_set(priv->model, &child, COLUMN_SUBTITLE, subtitle, -1); iter_not_found: pkg_window_subscription_call_free(call); g_free(subtitle); EXIT; }
/** * shell_util_format_date: * @format: a strftime-style string format, as parsed by * g_date_time_format() * @time_ms: milliseconds since 1970-01-01 00:00:00 UTC; the * value returned by Date.getTime() * * Formats a date for the current locale. This should be * used instead of the Spidermonkey Date.toLocaleFormat() * extension because Date.toLocaleFormat() is buggy for * Unicode format strings: * https://bugzilla.mozilla.org/show_bug.cgi?id=508783 * * Return value: the formatted date. If the date is * outside of the range of a GDateTime (which contains * any plausible dates we actually care about), will * return an empty string. */ char * shell_util_format_date (const char *format, gint64 time_ms) { GDateTime *datetime; GTimeVal tv; char *result; tv.tv_sec = time_ms / 1000; tv.tv_usec = (time_ms % 1000) * 1000; datetime = g_date_time_new_from_timeval_local (&tv); if (!datetime) /* time_ms is out of range of GDateTime */ return g_strdup (""); result = g_date_time_format (datetime, format); g_date_time_unref (datetime); return result; }
static void gs_screenshot_soup_msg_set_modified_request (SoupMessage *msg, GFile *file) { GTimeVal time_val; g_autoptr(GDateTime) date_time = NULL; g_autoptr(GFileInfo) info = NULL; g_autofree gchar *mod_date = NULL; info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info == NULL) return; g_file_info_get_modification_time (info, &time_val); date_time = g_date_time_new_from_timeval_local (&time_val); mod_date = g_date_time_format (date_time, "%a, %d %b %Y %H:%M:%S %Z"); soup_message_headers_append (msg->request_headers, "If-Modified-Since", mod_date); }
static void get_folder_content_done_cb (GError *error, gpointer user_data) { LoadData *load_data = user_data; FrFileSelectorDialog *self = load_data->dialog; GtkListStore *list_store; GList *scan; GtkTreeIter iter; GDateTime *today; int sort_column_id; GtkSortType sort_order; GHashTable *selected_files; if (error != NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) { GMountOperation *operation; operation = gtk_mount_operation_new (GTK_WINDOW (self)); g_file_mount_enclosing_volume (load_data->folder, G_MOUNT_MOUNT_NONE, operation, load_data->cancellable, folder_mount_enclosing_volume_ready_cb, load_data); g_object_unref (operation); return; } if (! g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) _gtk_error_dialog_run (GTK_WINDOW (self), _("Could not load the location"), "%s", error->message); if (load_data->dialog->priv->current_operation == load_data) load_data->dialog->priv->current_operation = NULL; load_data_free (load_data); return; } load_data->files = g_list_reverse (load_data->files); today = g_date_time_new_now_local (); gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("files_liststore")), &sort_column_id, &sort_order); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("files_liststore")), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, 0); selected_files = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal); for (scan = load_data->files_to_select; scan; scan = scan->next) g_hash_table_insert(selected_files, scan->data, GINT_TO_POINTER (1)); list_store = GTK_LIST_STORE (GET_WIDGET ("files_liststore")); gtk_list_store_clear (list_store); for (scan = load_data->files; scan; scan = scan->next) { FileInfo *file_info = scan->data; GdkPixbuf *icon_pixbuf; char *size; GTimeVal timeval; GDateTime *datetime; char *modified; char *collate_key; gboolean is_folder; if (! self->priv->show_hidden && g_file_info_get_is_hidden (file_info->info)) continue; gtk_list_store_append (list_store, &iter); icon_pixbuf = gth_icon_cache_get_pixbuf (self->priv->icon_cache, g_file_info_get_icon (file_info->info)); size = g_format_size (g_file_info_get_size (file_info->info)); g_file_info_get_modification_time (file_info->info, &timeval); datetime = g_date_time_new_from_timeval_local (&timeval); modified = g_date_time_format (datetime, _g_date_time_same_day (datetime, today) ? "%X" : "%x"); collate_key = g_utf8_collate_key_for_filename (g_file_info_get_display_name (file_info->info), -1); is_folder = (g_file_info_get_file_type (file_info->info) == G_FILE_TYPE_DIRECTORY); gtk_list_store_set (list_store, &iter, FILE_LIST_COLUMN_ICON, icon_pixbuf, FILE_LIST_COLUMN_NAME, g_file_info_get_display_name (file_info->info), FILE_LIST_COLUMN_SIZE, (is_folder ? "" : size), FILE_LIST_COLUMN_MODIFIED, modified, FILE_LIST_COLUMN_FILE, file_info->file, FILE_LIST_COLUMN_NAME_ORDER, collate_key, FILE_LIST_COLUMN_SIZE_ORDER, g_file_info_get_size (file_info->info), FILE_LIST_COLUMN_MODIFIED_ORDER, timeval.tv_sec, FILE_LIST_COLUMN_IS_FOLDER, is_folder, FILE_LIST_COLUMN_IS_SELECTED, (g_hash_table_lookup (selected_files, file_info->file) != NULL), -1); g_free (collate_key); g_free (modified); g_date_time_unref (datetime); g_free (size); _g_object_unref (icon_pixbuf); } gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("files_liststore")), sort_column_id, sort_order); set_current_folder (self, load_data->folder); if (load_data->dialog->priv->current_operation == load_data) load_data->dialog->priv->current_operation = NULL; g_hash_table_unref (selected_files); g_date_time_unref (today); load_data_free (load_data); }