gnucash maint: Fix wrong date of beginning of epoch.

John Ralls jralls at code.gnucash.org
Thu Apr 7 12:35:21 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/7b1c0509 (commit)
	from  https://github.com/Gnucash/gnucash/commit/7147e8a6 (commit)



commit 7b1c0509f75f27ebd2a971fae7fd64fa34588589
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Apr 7 09:34:59 2022 -0700

    Fix wrong date of beginning of epoch.

diff --git a/gnucash/gnome-utils/gnc-date-edit.c b/gnucash/gnome-utils/gnc-date-edit.c
index 7f4181fbb..567a2cd99 100644
--- a/gnucash/gnome-utils/gnc-date-edit.c
+++ b/gnucash/gnome-utils/gnc-date-edit.c
@@ -655,7 +655,7 @@ gnc_date_edit_class_init (GNCDateEditClass *klass)
                                     PROP_TIME,
                                     g_param_spec_int64("time",
                                             "Date/time (seconds)",
-                                            "Date/time represented in seconds since Januari 31st, 1970",
+                                            "Date/time represented in seconds since midnight UTC, 1 January 1970",
                                             G_MININT64,
                                             G_MAXINT64,
                                             0,
diff --git a/gnucash/import-export/aqb/gnc-ab-utils.c b/gnucash/import-export/aqb/gnc-ab-utils.c
index be5905797..d0804cffc 100644
--- a/gnucash/import-export/aqb/gnc-ab-utils.c
+++ b/gnucash/import-export/aqb/gnc-ab-utils.c
@@ -93,13 +93,27 @@ struct _GncABImExContextImport
     GData *tmp_job_list;
 };
 
+static inline is_leap_year (int year)
+{
+    return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0 ));
+}
+
 static inline time64
 gnc_gwen_date_to_time64 (const GNC_GWEN_DATE* date)
 {
 #if AQBANKING_VERSION_INT >= 59900
-    return gnc_dmy2time64_neutral(GWEN_Date_GetDay(date),
-                                  GWEN_Date_GetMonth(date),
-                                  GWEN_Date_GetYear(date));
+    int day = GWEN_Date_GetDay(date);
+    int month = GWEN_Date_GetMonth(date);
+    int year = GWEN_Date_GetYear(date);
+    /* Some banks use nominal 30-day months and set the value date as
+     * the day after the posted date. In February this can appear to
+     * be an invalid date because February has fewer than 30 days. If
+     * that's the case then back up a day to get a real date for
+     * posting.
+     */
+    if (month == 2 && day <= 30 && day > is_leap_year(year) ? 29 : 28)
+        --day;
+    return gnc_dmy2time64_neutral(day, month, year);
 #else
     int month, day, year;
     GWEN_Time_GetBrokenDownDate(date, &day, &month, &year);



Summary of changes:
 gnucash/gnome-utils/gnc-date-edit.c      |  2 +-
 gnucash/import-export/aqb/gnc-ab-utils.c | 20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)



More information about the gnucash-changes mailing list