gnucash stable: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Thu Dec 7 20:40:32 EST 2023
Updated via https://github.com/Gnucash/gnucash/commit/5005c3ca (commit)
via https://github.com/Gnucash/gnucash/commit/ae8492d7 (commit)
via https://github.com/Gnucash/gnucash/commit/5a7b6e98 (commit)
from https://github.com/Gnucash/gnucash/commit/c473ae0e (commit)
commit 5005c3cac8419a5513559e6ef2c808551218f9ce
Merge: c473ae0e38 ae8492d73a
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Dec 7 17:31:33 2023 -0800
Merge Sherlock's 'bug799151' into stable.
commit ae8492d73a769fe315a2839dc865e82b0cf1e89a
Author: Sherlock <119709043+agwekixj at users.noreply.github.com>
Date: Tue Dec 5 13:18:51 2023 -0800
Update test-gnc-date.c
diff --git a/libgnucash/engine/test/test-gnc-date.c b/libgnucash/engine/test/test-gnc-date.c
index a83252f3b3..fe68f0196e 100644
--- a/libgnucash/engine/test/test-gnc-date.c
+++ b/libgnucash/engine/test/test-gnc-date.c
@@ -544,7 +544,8 @@ test_gnc_date_get_last_mday (void)
g_assert_cmpint (gnc_date_get_last_mday (11, 1975), ==, 31);
g_assert_cmpint (gnc_date_get_last_mday (11, 1980), ==, 31);
g_assert_cmpint (gnc_date_get_last_mday (1, 2000), ==, 29);
- g_assert_cmpint (gnc_date_get_last_mday (1, 2400), ==, 28);
+ g_assert_cmpint (gnc_date_get_last_mday (1, 2100), ==, 28);
+ g_assert_cmpint (gnc_date_get_last_mday (1, 2400), ==, 29);
}
/* Getter, no testing needed.
QofDateFormat qof_date_format_get (void)// C: 5 in 3 Local: 0:0:0
commit 5a7b6e9814be2a9639b8229ac877ad68eb27090a
Author: Sherlock <119709043+agwekixj at users.noreply.github.com>
Date: Tue Dec 5 12:40:43 2023 -0800
Bug 799151 - gnc_date_get_last_mday () does not account for,,,
leap years correctly.
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 8c202e40e4..b5f2acb948 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -419,17 +419,17 @@ time64CanonicalDayTime (time64 t)
/* NB: month is 1-12, year is 0001 - 9999. */
int gnc_date_get_last_mday (int month, int year)
{
- static int last_day_of_month[2][12] =
- {
- /* non leap */ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- /* leap */ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
- };
+ static int last_day_of_month[12] =
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+ g_assert(month >= 0 && month < 12);
+
+ // To be a leap year, the year number must be divisible by four,
+ // except for end-of-century years, which must be divisible by 400.
- /* Is this a leap year? */
- if (year % 2000 == 0) return last_day_of_month[1][month];
- if (year % 400 == 0 ) return last_day_of_month[0][month];
- if (year % 4 == 0 ) return last_day_of_month[1][month];
- return last_day_of_month[0][month];
+ return last_day_of_month[month] +
+ (month == 1 && year % 4 == 0 && !(year % 100 == 0 && year % 400 != 0) ?
+ 1 : 0);
}
QofDateFormat qof_date_format_get (void)
Summary of changes:
libgnucash/engine/gnc-date.cpp | 20 ++++++++++----------
libgnucash/engine/test/test-gnc-date.c | 3 ++-
2 files changed, 12 insertions(+), 11 deletions(-)
More information about the gnucash-changes
mailing list