From c000a890ad1ec8ba14e83726f4ddca58c036ce34 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Fri, 29 Apr 2022 11:20:36 +0100 Subject: [PATCH] Bug 798501 - Balance wrong date end of account period With the accounting period preference settings set to 'Start/End of previous quarter' and balance sheet report using 'End of accounting period' the date is wrong, currently is 30/03/2022 when it should be 31/03/2022. Simplify gnc_gdate_set_quarter_end to get correct last day and subtract the 3 months befor calling said function. --- libgnucash/engine/gnc-date.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp index 3a969a46dc..e7686463ee 100644 --- a/libgnucash/engine/gnc-date.cpp +++ b/libgnucash/engine/gnc-date.cpp @@ -1532,17 +1532,13 @@ gnc_gdate_set_quarter_start (GDate *date) void gnc_gdate_set_quarter_end (GDate *date) { - gint months; + const GDateMonth months[] = {G_DATE_MARCH, G_DATE_JUNE, + G_DATE_SEPTEMBER, G_DATE_DECEMBER}; + const GDateDay days[] = {31, 30, 30, 31}; + int quarter = (g_date_get_month (date) - 1) / 3; - /* Set the date to the first day of the specified month. */ - g_date_set_day(date, 1); - - /* Add 1-3 months to get the first day of the next quarter.*/ - months = (g_date_get_month(date) - G_DATE_JANUARY) % 3; - g_date_add_months(date, 3 - months); - - /* Now back up one day */ - g_date_subtract_days(date, 1); + g_date_set_month (date, months[quarter]); + g_date_set_day (date, days[quarter]); } void @@ -1555,8 +1551,8 @@ gnc_gdate_set_prev_quarter_start (GDate *date) void gnc_gdate_set_prev_quarter_end (GDate *date) { - gnc_gdate_set_quarter_end(date); g_date_subtract_months(date, 3); + gnc_gdate_set_quarter_end(date); } /* ================================================= */