gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Thu Aug 15 04:09:08 EDT 2019
Updated via https://github.com/Gnucash/gnucash/commit/f64dd086 (commit)
via https://github.com/Gnucash/gnucash/commit/ec6602ad (commit)
via https://github.com/Gnucash/gnucash/commit/bdbb06b7 (commit)
from https://github.com/Gnucash/gnucash/commit/11265541 (commit)
commit f64dd0860fde4a04d9298b7c37430996fcc73efb
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Aug 14 13:32:20 2019 +0800
Bug 752395 - Start Day of weekly report doesn't respond to change in locale
Redefines some functions to ensure weekly grouping in transaction
report obeys locale's start-of-week.
diff --git a/libgnucash/app-utils/date-utilities.scm b/libgnucash/app-utils/date-utilities.scm
index e2e8216ac..4ecdb9311 100644
--- a/libgnucash/app-utils/date-utilities.scm
+++ b/libgnucash/app-utils/date-utilities.scm
@@ -84,11 +84,9 @@
(gnc-print-time64 (gnc-mktime datevec) "%B %Y"))
(define (gnc:date-get-week-year-string datevec)
- (let* ((beginweekt64 (* (gnc:time64-get-week
- (gnc-mktime datevec))
- 604800))
- (begin-string (qof-print-date (+ beginweekt64 345600)))
- (end-string (qof-print-date (+ beginweekt64 864000))))
+ (let* ((beginweekt64 (* (gnc:time64-get-week (gnc-mktime datevec)) 7 86400))
+ (begin-string (qof-print-date (+ beginweekt64 (* 3 86400))))
+ (end-string (qof-print-date (+ beginweekt64 (* 9 86400)))))
(format #f (_ "~a to ~a") begin-string end-string)))
;; is leap year?
@@ -156,18 +154,21 @@
(gnc:date-get-month lt)
(gnc:date-get-year lt))))))
-;; convert a date in seconds since 1970 into # of two-week periods since
-;; Jan 4, 1970 ignoring leap-seconds (just halfing date-to-week-fraction)
(define (gnc:date-to-twoweek-fraction caltime)
(/ (gnc:date-to-week-fraction caltime) 2))
-;; convert a date in seconds since 1970 into # of weeks since Jan 4, 1970
-;; ignoring leap-seconds
+;; which dow does the week start? 1=Sunday, 2=Monday etc
+(define weekstart
+ (let ((dow (gnc-start-of-week)))
+ (cond
+ ((zero? dow) (gnc:warn "cannot determine start of week. using Sunday") 1)
+ (else dow))))
+
(define (gnc:date-to-week-fraction caltime)
- (/ (- (/ (/ caltime 3600.0) 24) 3) 7))
+ (/ (- (/ caltime 86400) 1 weekstart) 7))
(define (gnc:date-to-week caltime)
- (floor (/ (- (/ caltime 86400) 3) 7)))
+ (floor (gnc:date-to-week-fraction caltime)))
;; convert a date in seconds since 1970 into # of days since Feb 28, 1970
;; ignoring leap-seconds
commit ec6602adf97629ad3f731b20fcbf23a3ef9d0042
Author: Geert Janssens <geert at kobaltwit.be>
Date: Wed Aug 14 22:35:58 2019 +0800
[gnc-date][API] find locale's start of week using ICU.
gnc_start_of_week
* ICU has a mature C++ api, so prefer that one in our C++ code
* Use PERR instead of fprintf for consistent reporting
* Add the ICU specific linker flags to the test case
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 1e3236d5f..48b3c062d 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -48,6 +48,7 @@ extern "C"
}
#include <cinttypes>
+#include <unicode/calendar.h>
#include "gnc-date.h"
#include "gnc-date-p.h"
@@ -201,6 +202,30 @@ gnc_gmtime (const time64 *secs)
}
+gint
+gnc_start_of_week (void)
+{
+ /* icu's day of week is 1 based. Using 0 here to mean unset or error while setting */
+ static int cached_result = 0;
+
+ if (!cached_result)
+ {
+ UErrorCode err = U_ZERO_ERROR;
+ auto cal = icu::Calendar::createInstance (err);
+ if (!cal)
+ {
+ PERR("ICU error: %s\n", u_errorName (err));
+ return 0;
+ }
+
+ /* 1 for sunday, 2 for monday, etc. */
+ cached_result = cal->getFirstDayOfWeek (err);
+ delete cal;
+ }
+
+ return cached_result;
+}
+
time64
gnc_mktime (struct tm* time)
{
diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index aed8d0a2d..b911fa58b 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -185,6 +185,11 @@ struct tm* gnc_localtime_r (const time64 *secs, struct tm* time);
*/
struct tm* gnc_gmtime (const time64 *secs);
+/** \brief returns an integer corresponding to locale start of week
+ * \return An integer 1=Sunday, 2=Monday etc. If error, return 0.
+ */
+gint gnc_start_of_week (void);
+
/** \brief calculate seconds from the epoch given a time struct
* \param time: A struct tm* containing the date-time information.
* The time is understood to be in the current local time zone.
diff --git a/libgnucash/engine/test/CMakeLists.txt b/libgnucash/engine/test/CMakeLists.txt
index 1f84c4d6c..d9eb581d2 100644
--- a/libgnucash/engine/test/CMakeLists.txt
+++ b/libgnucash/engine/test/CMakeLists.txt
@@ -99,6 +99,7 @@ set(gtest_qof_LIBS
${GOBJECT_LDFLAGS}
${GMODULE_LDFLAGS}
${GTHREAD_LDFLAGS}
+ ${ICU4C_I18N_LDFLAGS}
${Boost_LIBRARIES}
${GTEST_LIB})
commit bdbb06b7226248458b62fd5fc972d959d9d34088
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Aug 14 12:35:31 2019 +0800
[price-quotes] remove no F::Q message
diff --git a/libgnucash/scm/price-quotes.scm b/libgnucash/scm/price-quotes.scm
index c8ec2cbdb..5969ae86a 100644
--- a/libgnucash/scm/price-quotes.scm
+++ b/libgnucash/scm/price-quotes.scm
@@ -527,7 +527,4 @@ Run 'gnc-fq-update' as root to install them.")))
(format #t (_ "Found Finance::Quote version ~A.") (car sources))
(newline)
(gnc:msg "Found Finance::Quote version " (car sources))
- (gnc-quote-source-set-fq-installed (car sources) (cdr sources)))
- (else
- (display "No Finance::Quote found\n")
- (gnc:msg "No Finance::Quote found")))))
+ (gnc-quote-source-set-fq-installed (car sources) (cdr sources))))))
Summary of changes:
libgnucash/app-utils/date-utilities.scm | 23 ++++++++++++-----------
libgnucash/engine/gnc-date.cpp | 25 +++++++++++++++++++++++++
libgnucash/engine/gnc-date.h | 5 +++++
libgnucash/engine/test/CMakeLists.txt | 1 +
libgnucash/scm/price-quotes.scm | 5 +----
5 files changed, 44 insertions(+), 15 deletions(-)
More information about the gnucash-changes
mailing list