gnucash stable: Fix GncDateEntry date parsing oddities.
John Ralls
jralls at code.gnucash.org
Thu Oct 12 18:57:56 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/44c278a8 (commit)
from https://github.com/Gnucash/gnucash/commit/55ab2a1c (commit)
commit 44c278a82c692b5b591eccaf052952b3cd248084
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Oct 12 15:51:35 2023 -0700
Fix GncDateEntry date parsing oddities.
The intent was always to default to today if the input string isn't
parsable, but two problems prevented that: First,
qof_scan_date_internal didn't check the return value of strptime and
return FALSE if it failed and second gnc_date_edit_get_date_internal
would unnecessarily munge a valid struct tm from gnc_tm_get_today_neutral.
diff --git a/gnucash/gnome-utils/gnc-date-edit.c b/gnucash/gnome-utils/gnc-date-edit.c
index ed716131f7..c31f31d11e 100644
--- a/gnucash/gnome-utils/gnc-date-edit.c
+++ b/gnucash/gnome-utils/gnc-date-edit.c
@@ -800,9 +800,6 @@ date_focus_out_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
tm = gnc_date_edit_get_date_internal (gde);
gnc_date_edit_set_time (gde, gnc_mktime (&tm));
- /* Get the date again in case it was invalid the first time. */
- tm = gnc_date_edit_get_date_internal (gde);
-
g_signal_emit (gde, date_edit_signals [DATE_CHANGED], 0);
g_signal_emit (gde, date_edit_signals [TIME_CHANGED], 0);
@@ -1020,10 +1017,11 @@ gnc_date_edit_get_date_internal (GNCDateEdit *gde)
function will have to check this. Alas, I'm too lazy to do this here. */
gnc_tm_get_today_neutral(&tm);
}
-
- tm.tm_mon--;
-
- tm.tm_year -= 1900;
+ else
+ {
+ tm.tm_mon--;
+ tm.tm_year -= 1900;
+ }
if (gde->flags & GNC_DATE_EDIT_SHOW_TIME)
{
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index c44912efa7..3dc541313d 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -752,7 +752,11 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
struct tm thetime;
/* Parse time string. */
memset(&thetime, -1, sizeof(struct tm));
- strptime (buff, normalize_format(GNC_D_FMT).c_str(), &thetime);
+ char *strv = strptime (buff, normalize_format(GNC_D_FMT).c_str(),
+ &thetime);
+
+ if (!strv) // Parse failed, continuing gives the wrong result.
+ return FALSE;
if (third_field)
{
Summary of changes:
gnucash/gnome-utils/gnc-date-edit.c | 12 +++++-------
libgnucash/engine/gnc-date.cpp | 6 +++++-
2 files changed, 10 insertions(+), 8 deletions(-)
More information about the gnucash-changes
mailing list