Skip to content

Commit

Permalink
Fix GncDateEntry date parsing oddities.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jralls committed Oct 12, 2023
1 parent 55ab2a1 commit 44c278a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 5 additions & 7 deletions gnucash/gnome-utils/gnc-date-edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion libgnucash/engine/gnc-date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 44c278a

Please sign in to comment.