gnucash maint: Multiple changes pushed

Robert Fewell bobit at code.gnucash.org
Sun May 8 05:16:08 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/27cab58b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c000a890 (commit)
	from  https://github.com/Gnucash/gnucash/commit/2b198dbc (commit)



commit 27cab58bf236fc362ab2d07b1299ed29727cf8f6
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Fri May 6 12:15:39 2022 +0100

    Correct some text describing some date functions.

diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index 8f445530a..d2ec8298e 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -702,7 +702,7 @@ void gnc_gdate_set_prev_month_end (GDate *date);
 
 /** This function modifies a GDate to set it to the first day of the
  *  quarter in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-09-01.
+ *  with a date of 2003-09-24 the date will be modified to 2003-07-01.
  *
  *  @param date The GDate to modify. */
 void gnc_gdate_set_quarter_start (GDate *date);
@@ -710,7 +710,7 @@ void gnc_gdate_set_quarter_start (GDate *date);
 
 /** This function modifies a GDate to set it to the last day of the
  *  quarter in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-12-31.
+ *  with a date of 2003-09-24 the date will be modified to 2003-09-30.
  *
  *  @param date The GDate to modify. */
 void gnc_gdate_set_quarter_end (GDate *date);
@@ -719,7 +719,7 @@ void gnc_gdate_set_quarter_end (GDate *date);
 /** This function modifies a GDate to set it to the first day of the
  *  quarter prior to the one in which it falls.  For example, if this
  *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2003-06-01.
+ *  modified to 2003-04-01.
  *
  *  @param date The GDate to modify. */
 void gnc_gdate_set_prev_quarter_start (GDate *date);
@@ -728,7 +728,7 @@ void gnc_gdate_set_prev_quarter_start (GDate *date);
 /** This function modifies a GDate to set it to the last day of the
  *  quarter prior to the one in which it falls.  For example, if this
  *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2003-07-31.
+ *  modified to 2003-06-30.
  *
  *  @param date The GDate to modify. */
 void gnc_gdate_set_prev_quarter_end (GDate *date);

commit c000a890ad1ec8ba14e83726f4ddca58c036ce34
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Fri Apr 29 11:20:36 2022 +0100

    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.

diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 3a969a46d..e7686463e 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);
 }
 
 /* ================================================= */



Summary of changes:
 libgnucash/engine/gnc-date.cpp | 18 +++++++-----------
 libgnucash/engine/gnc-date.h   |  8 ++++----
 2 files changed, 11 insertions(+), 15 deletions(-)



More information about the gnucash-changes mailing list