[geany/geany] 977928: Merge pull request #3037 from eht16/issue2968_windows_strftime

Enrico Tröger git-noreply at xxxxx
Sun Jan 30 21:40:24 UTC 2022


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   GitHub <noreply at github.com>
Date:        Sun, 30 Jan 2022 21:40:24 UTC
Commit:      977928a1bcc683c2896281421c9228140f6efe07
             https://github.com/geany/geany/commit/977928a1bcc683c2896281421c9228140f6efe07

Log Message:
-----------
Merge pull request #3037 from eht16/issue2968_windows_strftime

Use GDateTime for date and time formatting


Modified Paths:
--------------
    data/geany.glade
    doc/geany.txt
    plugins/saveactions.c
    src/printing.c
    src/ui_utils.c
    src/utils.c

Modified: data/geany.glade
8 lines changed, 4 insertions(+), 4 deletions(-)
===================================================================
@@ -5342,7 +5342,7 @@
                                   <object class="GtkEntry" id="entry_template_datetime">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="tooltip_text" translatable="yes">Specify a format for the {datetime} wildcard. You can use any conversion specifiers which can be used with the ANSI C strftime function.</property>
+                                    <property name="tooltip_text" translatable="yes">Specify a format for the {datetime} wildcard. For a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.</property>
                                     <property name="primary_icon_activatable">False</property>
                                     <property name="secondary_icon_activatable">False</property>
                                     <property name="primary_icon_sensitive">True</property>
@@ -5360,7 +5360,7 @@
                                   <object class="GtkEntry" id="entry_template_year">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="tooltip_text" translatable="yes">Specify a format for the {year} wildcard. You can use any conversion specifiers which can be used with the ANSI C strftime function.</property>
+                                    <property name="tooltip_text" translatable="yes">Specify a format for the {year} wildcard. For a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.</property>
                                     <property name="primary_icon_activatable">False</property>
                                     <property name="secondary_icon_activatable">False</property>
                                     <property name="primary_icon_sensitive">True</property>
@@ -5378,7 +5378,7 @@
                                   <object class="GtkEntry" id="entry_template_date">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="tooltip_text" translatable="yes">Specify a format for the {date} wildcard. You can use any conversion specifiers which can be used with the ANSI C strftime function.</property>
+                                    <property name="tooltip_text" translatable="yes">Specify a format for the {date} wildcard. For a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.</property>
                                     <property name="primary_icon_activatable">False</property>
                                     <property name="secondary_icon_activatable">False</property>
                                     <property name="primary_icon_sensitive">True</property>
@@ -5755,7 +5755,7 @@
                                                       <object class="GtkEntry" id="entry_print_dateformat">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">True</property>
-                                                        <property name="tooltip_text" translatable="yes">Specify a format for the date and time stamp which is added to the page header on each page. You can use any conversion specifiers which can be used with the ANSI C strftime function.</property>
+                                                        <property name="tooltip_text" translatable="yes">Specify a format for the date and time stamp which is added to the page header on each page. For a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.</property>
                                                         <property name="invisible_char">●</property>
                                                         <property name="primary_icon_activatable">False</property>
                                                         <property name="secondary_icon_activatable">False</property>


Modified: doc/geany.txt
29 lines changed, 12 insertions(+), 17 deletions(-)
===================================================================
@@ -2451,19 +2451,16 @@ Initial version
     The initial version of files you will be creating.
 
 Year
-    Specify a format for the {year} wildcard. You can use any conversion specifiers
-    which can be used with the ANSI C strftime function.  For details please see
-    http://man.cx/strftime.
+    Specify a format for the {year} wildcard. For a list of available conversion
+    specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.
 
 Date
-    Specify a format for the {date} wildcard. You can use any conversion specifiers
-    which can be used with the ANSI C strftime function.  For details please see
-    http://man.cx/strftime.
+    Specify a format for the {date} wildcard. For a list of available conversion
+    specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.
 
 Date & Time
-    Specify a format for the {datetime} wildcard. You can use any conversion specifiers
-    which can be used with the ANSI C strftime function.  For details please see
-    http://man.cx/strftime.
+    Specify a format for the {datetime} wildcard. For a list of available conversion
+    specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.
 
 
 Keybinding preferences
@@ -2502,9 +2499,8 @@ Use base name of the printed file
     Don't use the entire path for the header, only the filename.
 
 Date format
-    How the date should be printed. You can use the same format
-    specifiers as in the ANSI C function strftime(). For details please
-    see http://man.cx/strftime.
+    How the date should be printed. For a list of available conversion
+    specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.
 
 
 Various preferences
@@ -3230,8 +3226,8 @@ the date and time of printing. By default, the file name of the document
 with full path information is added to the header. If you prefer to add
 only the basename of the file(without any path information) you can set it
 in the preferences dialog. You can also adjust the format of the date and
-time added to the page header. The available conversion specifiers are the
-same as the ones which can be used with the ANSI C strftime function.
+time added to the page header. For a list of available conversion
+specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.
 
 All of these settings can also be changed in the print dialog just before
 actual printing is done.
@@ -4948,9 +4944,8 @@ version        The initial version of a new file.            file templates, fil
 **Date & time wildcards**
 
 The format for these wildcards can be changed in the preferences
-dialog, see `Template preferences`_. You can use any conversion
-specifiers which can be used with the ANSI C strftime function.
-For details please see http://man.cx/strftime.
+dialog, see `Template preferences`_. For a list of available conversion
+specifiers see https://docs.gtk.org/glib/method.DateTime.format.html.
 
 ============== ============================================= =======================================
 Wildcard       Description                                   Available in


Modified: plugins/saveactions.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -814,7 +814,7 @@ GtkWidget *plugin_configure(GtkDialog *dialog)
 		gtk_box_pack_start(GTK_BOX(inner_vbox), hbox, FALSE, FALSE, 0);
 
 		label = gtk_label_new_with_mnemonic(
-			_("Date/_Time format for backup files (\"man strftime\" for details):"));
+			_("Date/_Time format for backup files (for a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html):"));
 		gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 		gtk_box_pack_start(GTK_BOX(inner_vbox), label, FALSE, FALSE, 7);
 


Modified: src/printing.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -276,7 +276,7 @@ static GtkWidget *create_custom_widget(GtkPrintOperation *operation, gpointer us
 	w->entry_print_dateformat = gtk_entry_new();
 	ui_entry_add_clear_icon(GTK_ENTRY(w->entry_print_dateformat));
 	gtk_box_pack_start(GTK_BOX(hbox10), w->entry_print_dateformat, TRUE, TRUE, 0);
-	gtk_widget_set_tooltip_text(w->entry_print_dateformat, _("Specify a format for the date and time stamp which is added to the page header on each page. You can use any conversion specifiers which can be used with the ANSI C strftime function."));
+	gtk_widget_set_tooltip_text(w->entry_print_dateformat, _("Specify a format for the date and time stamp which is added to the page header on each page. For a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html."));
 	gtk_entry_set_text(GTK_ENTRY(w->entry_print_dateformat), printing_prefs.page_header_datefmt);
 
 	on_page_header_toggled(GTK_TOGGLE_BUTTON(w->check_print_pageheader), w);


Modified: src/ui_utils.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -728,7 +728,7 @@ static void insert_date(GeanyDocument *doc, gint pos, const gchar *date_style)
 	{
 		gchar *str = dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets.window),
 				_("Enter here a custom date and time format. "
-				"You can use any conversion specifiers which can be used with the ANSI C strftime function."),
+				"For a list of available conversion specifiers see https://docs.gtk.org/glib/method.DateTime.format.html."),
 				ui_prefs.custom_date_format);
 		if (str)
 			SETPTR(ui_prefs.custom_date_format, str);


Modified: src/utils.c
44 lines changed, 13 insertions(+), 31 deletions(-)
===================================================================
@@ -720,12 +720,11 @@ gint utils_strpos(const gchar *haystack, const gchar *needle)
 
 
 /**
- *  Retrieves a formatted date/time string from strftime().
- *  This function should be preferred to directly calling strftime() since this function
- *  works on UTF-8 encoded strings.
+ *  Retrieves a formatted date/time string from GDateTime.
+ *  This function works on UTF-8 encoded strings.
  *
- *  @param format The format string to pass to strftime(3). See the strftime(3)
- *                documentation for details, in UTF-8 encoding.
+ *  @param format The format string to pass to g_date_time_format, in UTF-8 encoding.
+                  See https://docs.gtk.org/glib/method.DateTime.format.html for details.
  *  @param time_to_use @nullable The date/time to use, in time_t format or @c NULL to use the current time.
  *
  *  @return A newly-allocated string, should be freed when no longer needed.
@@ -735,39 +734,22 @@ gint utils_strpos(const gchar *haystack, const gchar *needle)
 GEANY_API_SYMBOL
 gchar *utils_get_date_time(const gchar *format, time_t *time_to_use)
 {
-	const struct tm *tm;
-	static gchar date[1024];
-	gchar *locale_format;
-	gsize len;
+	time_t unixtime;
+	gchar *datetime_formatted;
+	GDateTime *datetime;
 
 	g_return_val_if_fail(format != NULL, NULL);
 
-	if (! g_utf8_validate(format, -1, NULL))
-	{
-		locale_format = g_locale_from_utf8(format, -1, NULL, NULL, NULL);
-		if (locale_format == NULL)
-			return NULL;
-	}
-	else
-		locale_format = g_strdup(format);
-
 	if (time_to_use != NULL)
-		tm = localtime(time_to_use);
+		unixtime = *time_to_use;
 	else
-	{
-		time_t tp = time(NULL);
-		tm = localtime(&tp);
-	}
+		unixtime = time(NULL);
 
-	len = strftime(date, 1024, locale_format, tm);
-	g_free(locale_format);
-	if (len == 0)
-		return NULL;
+	datetime = g_date_time_new_from_unix_local(unixtime);
+	datetime_formatted = g_date_time_format(datetime, format);
 
-	if (! g_utf8_validate(date, len, NULL))
-		return g_locale_to_utf8(date, len, NULL, NULL, NULL);
-	else
-		return g_strdup(date);
+	g_date_time_unref(datetime);
+	return datetime_formatted;
 }
 
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list