gnucash master: Multiple changes pushed
Geert Janssens
gjanssens at code.gnucash.org
Mon Oct 10 05:58:44 EDT 2016
Updated via https://github.com/Gnucash/gnucash/commit/c5414e33 (commit)
via https://github.com/Gnucash/gnucash/commit/6bdac283 (commit)
via https://github.com/Gnucash/gnucash/commit/901c89df (commit)
via https://github.com/Gnucash/gnucash/commit/5a7c791c (commit)
from https://github.com/Gnucash/gnucash/commit/20c0271e (commit)
commit c5414e336ace0a11e3bd5275661fddc566884409
Merge: 20c0271 6bdac28
Author: Geert Janssens <janssens-geert at telenet.be>
Date: Mon Oct 10 11:57:03 2016 +0200
Merge branch 'maint'
commit 6bdac283fa6b1f5b67a3d228e1f16cc2d498519e
Author: Geert Janssens <janssens-geert at telenet.be>
Date: Mon Oct 10 11:49:10 2016 +0200
Bug 771617 - Build fails because test test-report-utilities is sensitive to time of day/timezone
Use the date-time functions in gnc-date instead of the guile ones for more consistent behaviour.
Do the same for test test-cash-flow, which was also time-of-day sensitive
diff --git a/src/engine/engine.i b/src/engine/engine.i
index f11d309..14c1214 100644
--- a/src/engine/engine.i
+++ b/src/engine/engine.i
@@ -167,8 +167,9 @@ void qof_book_kvp_changed (QofBook *book);
// TODO: Unroll/remove
const char *qof_session_get_url (QofSession *session);
+%ignore qof_print_date_time_buff;
+%include <gnc-date.h>
extern const char *gnc_default_strftime_date_format;
-const char *gnc_print_date (Timespec ts);
GncGUID guid_new_return(void);
diff --git a/src/report/report-system/test/test-report-utilities.scm b/src/report/report-system/test/test-report-utilities.scm
index 959c8b9..dd06172 100644
--- a/src/report/report-system/test/test-report-utilities.scm
+++ b/src/report/report-system/test/test-report-utilities.scm
@@ -11,38 +11,32 @@
(define (run-test)
(test-account-get-trans-type-splits-interval))
-(define (NDayDelta n)
- (let ((ddt (make-zdate)))
- (set-tm:mday ddt n)
- ddt))
+(define (NDayDelta tp n)
+ (let* ((day-secs (* 60 60 24 n)) ; n days in seconds is n times 60 sec/min * 60 min/h * 24 h/day
+ (new-secs (- (car tp) day-secs))
+ (new-tp (cons new-secs 0)))
+ new-tp))
(define (test-account-get-trans-type-splits-interval)
- (let ((env (create-test-env))
- (end-date-tp (gnc:date->timepair (localtime (current-time)))))
+ (let* ((env (create-test-env))
+ (ts-now (localtime (current-time)))
+ (end-date-tp (gnc-dmy2timespec-neutral (tm:mday ts-now) (tm:mon ts-now) (tm:year ts-now)))
+ (start-date-tp (NDayDelta end-date-tp 10))
+ (q-end-date-tp (gnc-dmy2timespec-end (tm:mday ts-now) (tm:mon ts-now) (tm:year ts-now)))
+ (q-start-date-tp (gnc-dmy2timespec (tm:mday ts-now) (tm:mon ts-now) (tm:year ts-now)))
+ (q-start-date-tp (NDayDelta q-start-date-tp 5)))
+
(let* ((accounts (env-create-account-structure-alist env (list "Assets"
(list (cons 'type ACCT-TYPE-ASSET))
(list "Bank Account")
(list "Wallet"))))
(bank-account (cdr (assoc "Bank Account" accounts)))
- (wallet (cdr (assoc "Wallet" accounts)))
- (start-date-tp (decdate end-date-tp (NDayDelta 10)))
- (q-start-date-tp (decdate end-date-tp (NDayDelta 5)))
- (q-start-date (gnc:timepair->date q-start-date-tp))
- (q-end-date (gnc:timepair->date end-date-tp)))
+ (wallet (cdr (assoc "Wallet" accounts))))
(env-create-daily-transactions env start-date-tp end-date-tp bank-account wallet)
- ; Ensure the query interval is as inclusive as possible to deal with timezone differences
- (set-tm:hour q-end-date 23)
- (set-tm:min q-end-date 59)
- (set-tm:sec q-end-date 59)
- (set-tm:hour q-start-date 00)
- (set-tm:min q-start-date 00)
- (set-tm:sec q-start-date 01)
-
(let ((splits (gnc:account-get-trans-type-splits-interval (list bank-account wallet)
ACCT-TYPE-ASSET
- (gnc:date->timepair q-start-date)
- (gnc:date->timepair q-end-date))))
+ q-start-date-tp q-end-date-tp)))
;; 10 is the right number (5 days, two splits per tx)
(and (equal? 10 (length splits)))))))
diff --git a/src/report/standard-reports/test/test-cash-flow.scm b/src/report/standard-reports/test/test-cash-flow.scm
index 871fd15..74031ad 100644
--- a/src/report/standard-reports/test/test-cash-flow.scm
+++ b/src/report/standard-reports/test/test-cash-flow.scm
@@ -18,10 +18,11 @@
(list "Wallet"))
(list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE)))))
-(define (NDayDelta n)
- (let ((ddt (make-zdate)))
- (set-tm:year ddt n)
- ddt))
+(define (NDayDelta tp n)
+ (let* ((day-secs (* 60 60 24 n)) ; n days in seconds is n times 60 sec/min * 60 min/h * 24 h/day
+ (new-secs (- (car tp) day-secs))
+ (new-tp (cons new-secs 0)))
+ new-tp))
(define (test-one-tx-in-cash-flow)
(let* ((env (create-test-env))
@@ -29,14 +30,16 @@
(bank-account (cdr (assoc "Bank" account-alist)))
(wallet-account (cdr (assoc "Wallet" account-alist)))
(expense-account (cdr (assoc "Expenses" account-alist)))
- (today (gnc:date->timepair (localtime (current-time))))
+ (today (localtime (current-time)))
+ (to-date-tp (gnc-dmy2timespec-end (tm:mday today) (tm:mon today) (tm:year today)))
+ (from-date-tp (NDayDelta to-date-tp 1))
(exchange-fn (lambda (currency amount date) amount))
(report-currency (gnc-default-report-currency))
)
- (env-create-transaction env today bank-account expense-account (gnc:make-gnc-numeric 100 1))
+ (env-create-transaction env to-date-tp bank-account expense-account (gnc:make-gnc-numeric 100 1))
(let ((result (cash-flow-calc-money-in-out (list (cons 'accounts (list bank-account))
- (cons 'to-date-tp today)
- (cons 'from-date-tp (decdate today (NDayDelta 1)))
+ (cons 'to-date-tp to-date-tp)
+ (cons 'from-date-tp from-date-tp)
(cons 'report-currency report-currency)
(cons 'include-trading-accounts #f)
(cons 'to-report-currency exchange-fn)))))
@@ -63,14 +66,16 @@
(bank-account (cdr (assoc "Bank" account-alist)))
(wallet-account (cdr (assoc "Wallet" account-alist)))
(expense-account (cdr (assoc "Expenses" account-alist)))
- (today (gnc:date->timepair (localtime (current-time))))
+ (today (localtime (current-time)))
+ (to-date-tp (gnc-dmy2timespec-end (tm:mday today) (tm:mon today) (tm:year today)))
+ (from-date-tp (NDayDelta to-date-tp 1))
(exchange-fn (lambda (currency amount date) amount))
(report-currency (gnc-default-report-currency))
)
- (env-create-transaction env today bank-account wallet-account (gnc:make-gnc-numeric 100 1))
+ (env-create-transaction env to-date-tp bank-account wallet-account (gnc:make-gnc-numeric 100 1))
(let ((result (cash-flow-calc-money-in-out (list (cons 'accounts (list wallet-account bank-account))
- (cons 'to-date-tp today)
- (cons 'from-date-tp (decdate today (NDayDelta 1)))
+ (cons 'to-date-tp to-date-tp)
+ (cons 'from-date-tp from-date-tp)
(cons 'report-currency report-currency)
(cons 'include-trading-accounts #f)
(cons 'to-report-currency exchange-fn)))))
@@ -93,15 +98,17 @@
(bank-account (cdr (assoc "Bank" account-alist)))
(wallet-account (cdr (assoc "Wallet" account-alist)))
(expense-account (cdr (assoc "Expenses" account-alist)))
- (today (gnc:date->timepair (localtime (current-time))))
+ (today (localtime (current-time)))
+ (to-date-tp (gnc-dmy2timespec-end (tm:mday today) (tm:mon today) (tm:year today)))
+ (from-date-tp (NDayDelta to-date-tp 1))
(exchange-fn (lambda (currency amount date) amount))
(report-currency (gnc-default-report-currency))
)
- (env-create-transaction env today bank-account expense-account (gnc:make-gnc-numeric 100 1))
- (env-create-transaction env today expense-account bank-account (gnc:make-gnc-numeric 50 1))
+ (env-create-transaction env to-date-tp bank-account expense-account (gnc:make-gnc-numeric 100 1))
+ (env-create-transaction env to-date-tp expense-account bank-account (gnc:make-gnc-numeric 50 1))
(let ((result (cash-flow-calc-money-in-out (list (cons 'accounts (list wallet-account bank-account))
- (cons 'to-date-tp today)
- (cons 'from-date-tp (decdate today (NDayDelta 1)))
+ (cons 'to-date-tp to-date-tp)
+ (cons 'from-date-tp from-date-tp)
(cons 'report-currency report-currency)
(cons 'include-trading-accounts #f)
(cons 'to-report-currency exchange-fn)))))
commit 901c89dffad9fa9ee19960b91a585fc90a67e29e
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Oct 4 20:00:48 2016 +0200
Fix CSV importer to handle GMT + 13 Timezone (New Zealand Daylight Time).
Also remove special time calculations and use gnc_dmy2timespec_neutral()
for consistency with rest of GnuCash.
diff --git a/src/import-export/csv-imp/gnc-csv-model.c b/src/import-export/csv-imp/gnc-csv-model.c
index 1fe14e7..0636924 100644
--- a/src/import-export/csv-imp/gnc-csv-model.c
+++ b/src/import-export/csv-imp/gnc-csv-model.c
@@ -98,11 +98,9 @@ static StfParseOptions_t* default_parse_options (void)
*/
static time64 parse_date_with_year (const char* date_str, int format)
{
- time64 rawtime; /* The integer time */
- struct tm retvalue, test_retvalue; /* The time in a broken-down structure */
-
- int i, j, mem_length, orig_year = -1, orig_month = -1, orig_day = -1;
+ int i, j, mem_length, year = -1, month = -1, day = -1;
+ Timespec ts;
/* Buffer for containing individual parts (e.g. year, month, day) of a date */
char date_segment[5];
@@ -155,15 +153,6 @@ static time64 parse_date_with_year (const char* date_str, int format)
}
}
- /* Put some sane values in retvalue by using a fixed time for
- * the non-year-month-day parts of the date. */
- gnc_time (&rawtime);
- gnc_localtime_r (&rawtime, &retvalue);
- retvalue.tm_hour = 11;
- retvalue.tm_min = 0;
- retvalue.tm_sec = 0;
- retvalue.tm_isdst = -1;
-
/* j traverses pmatch (index 0 contains the entire string, so we
* start at index 1 for the first meaningful match). */
j = 1;
@@ -187,51 +176,32 @@ static time64 parse_date_with_year (const char* date_str, int format)
switch (segment_type)
{
case 'y':
- retvalue.tm_year = atoi (date_segment);
+ year = atoi (date_segment);
/* Handle two-digit years. */
- if (retvalue.tm_year < 100)
+ if (year < 100)
{
/* We allow two-digit years in the range 1969 - 2068. */
- if (retvalue.tm_year < 69)
- retvalue.tm_year += 100;
+ if (year < 69)
+ year += 2000;
+ else
+ year += 1900;
}
- else
- retvalue.tm_year -= 1900;
- orig_year = retvalue.tm_year;
break;
case 'm':
- orig_month = retvalue.tm_mon = atoi (date_segment) - 1;
+ month =atoi (date_segment);
break;
case 'd':
- orig_day = retvalue.tm_mday = atoi (date_segment);
+ day = atoi (date_segment);
break;
}
j++;
}
}
- /* Convert back to an integer. If gnc_mktime leaves retvalue unchanged,
- * everything is okay; otherwise, an error has occurred. */
- /* We have to use a "test" date value to account for changes in
- * daylight savings time, which can cause a date change with gnc_mktime
- * near midnight, causing the code to incorrectly think a date is
- * incorrect. */
- test_retvalue = retvalue;
- gnc_mktime (&test_retvalue);
- retvalue.tm_isdst = test_retvalue.tm_isdst;
- rawtime = gnc_mktime (&retvalue);
- if (retvalue.tm_mday == orig_day &&
- retvalue.tm_mon == orig_month &&
- retvalue.tm_year == orig_year)
- {
- return rawtime;
- }
- else
- {
- return -1;
- }
+ ts = gnc_dmy2timespec_neutral(day, month, year);
+ return ts.tv_sec;
}
/** Parses a string into a date, given a format. The format cannot
@@ -243,10 +213,8 @@ static time64 parse_date_with_year (const char* date_str, int format)
*/
static time64 parse_date_without_year (const char* date_str, int format)
{
- time64 rawtime; /* The integer time */
- struct tm retvalue, test_retvalue; /* The time in a broken-down structure */
-
- int i, j, mem_length, orig_year = -1, orig_month = -1, orig_day = -1;
+ Timespec ts;
+ int i, j, mem_length, year = -1, month = -1, day = -1;
/* Buffer for containing individual parts (e.g. year, month, day) of a date */
gchar* date_segment;
@@ -264,21 +232,14 @@ static time64 parse_date_without_year (const char* date_str, int format)
regcomp (&preg, regex, REG_EXTENDED);
regexec (&preg, date_str, 3, pmatch, 0);
regfree (&preg);
-
+ /* Set day, month, and year to today. We'll replace day & month with the
+ * values from the string.
+ */
+ gnc_timespec2dmy(timespec_now(), &day, &month, &year);
/* If there wasn't a match, there was an error. */
if (pmatch[0].rm_eo == 0)
return -1;
- /* Put some sane values in retvalue by using a fixed time for
- * the non-year-month-day parts of the date. */
- gnc_time (&rawtime);
- gnc_localtime_r (&rawtime, &retvalue);
- retvalue.tm_hour = 11;
- retvalue.tm_min = 0;
- retvalue.tm_sec = 0;
- retvalue.tm_isdst = -1;
- orig_year = retvalue.tm_year;
-
/* j traverses pmatch (index 0 contains the entire string, so we
* start at index 1 for the first meaningful match). */
j = 1;
@@ -303,37 +264,21 @@ static time64 parse_date_without_year (const char* date_str, int format)
switch (segment_type)
{
case 'm':
- orig_month = retvalue.tm_mon = atoi (date_segment) - 1;
+ month = atoi (date_segment);
break;
case 'd':
- orig_day = retvalue.tm_mday = atoi (date_segment);
+ day = atoi (date_segment);
break;
}
g_free (date_segment);
j++;
}
}
- /* Convert back to an integer. If gnc_mktime leaves retvalue unchanged,
- * everything is okay; otherwise, an error has occurred. */
- /* We have to use a "test" date value to account for changes in
- * daylight savings time, which can cause a date change with gnc_mktime
- * near midnight, causing the code to incorrectly think a date is
- * incorrect. */
- test_retvalue = retvalue;
- gnc_mktime (&test_retvalue);
- retvalue.tm_isdst = test_retvalue.tm_isdst;
- rawtime = gnc_mktime (&retvalue);
- if (retvalue.tm_mday == orig_day &&
- retvalue.tm_mon == orig_month &&
- retvalue.tm_year == orig_year)
- {
- return rawtime;
- }
- else
- {
+ if (month > 12 || day > 31)
return -1;
- }
+ ts = gnc_dmy2timespec_neutral(day, month, year);
+ return ts.tv_sec;
}
/** Parses a string into a date, given a format. This function
commit 5a7c791c96cc7bf84002f6894d44a2ef12dd46d4
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Oct 4 19:59:00 2016 +0200
Bug 772382 - Date off-by-one after DST change
The time needs to be 10:59, not 11:00: 13 hours after 11:00 is 24:00,
which is really 00:00 the next day.
diff --git a/src/libqof/qof/gnc-date.c b/src/libqof/qof/gnc-date.c
index 3da2eca..5f4133c 100644
--- a/src/libqof/qof/gnc-date.c
+++ b/src/libqof/qof/gnc-date.c
@@ -1576,15 +1576,14 @@ gnc_dmy2timespec_neutral (int day, int month, int year)
GDateTime *gdt = gnc_g_date_time_new_local (year, month, day, 12, 0, 0.0);
int interval = g_time_zone_find_interval (zone, G_TIME_TYPE_STANDARD,
g_date_time_to_unix(gdt));
- int offset = g_time_zone_get_offset(gnc_g_time_zone_new_local(),
- interval) / 3600;
+ int offset = g_time_zone_get_offset(zone, interval) / 3600;
g_date_time_unref (gdt);
memset (&date, 0, sizeof(struct tm));
date.tm_year = year - 1900;
date.tm_mon = month - 1;
date.tm_mday = day;
- date.tm_hour = offset < -11 ? -offset : offset > 13 ? 24 - offset : 11;
- date.tm_min = 0;
+ date.tm_hour = offset < -11 ? -offset : offset > 13 ? 23 - offset : 10;
+ date.tm_min = 59;
date.tm_sec = 0;
ts.tv_sec = gnc_timegm(&date);
diff --git a/src/libqof/qof/test/test-gnc-date.c b/src/libqof/qof/test/test-gnc-date.c
index 4210177..fa3625d 100644
--- a/src/libqof/qof/test/test-gnc-date.c
+++ b/src/libqof/qof/test/test-gnc-date.c
@@ -1973,10 +1973,10 @@ test_gnc_dmy2timespec_end (void)
static void
test_gnc_dmy2timespec_neutral (void)
{
- GDateTime *gdt1 = gncdt.new_utc (1999, 7, 21, 11, 0, 0);
- GDateTime *gdt2 = gncdt.new_utc (1918, 3, 31, 11, 0, 0);
- GDateTime *gdt3 = gncdt.new_utc (1918, 4, 1, 11, 0, 0);
- GDateTime *gdt4 = gncdt.new_utc (2057, 11, 20, 11, 0, 0);
+ GDateTime *gdt1 = gncdt.new_utc (1999, 7, 21, 10, 59, 0);
+ GDateTime *gdt2 = gncdt.new_utc (1918, 3, 31, 10, 59, 0);
+ GDateTime *gdt3 = gncdt.new_utc (1918, 4, 1, 10, 59, 0);
+ GDateTime *gdt4 = gncdt.new_utc (2057, 11, 20, 10, 59, 0);
gint day, mon, yr;
Timespec t, r_t;
@@ -2129,10 +2129,10 @@ Timespec gdate_to_timespec (GDate d)// C: 7 in 6 Local: 0:0:0
static void
test_gdate_to_timespec (void)
{
- GDateTime *gdt1 = gncdt.new_utc (1999, 7, 21, 11, 0, 0);
- GDateTime *gdt2 = gncdt.new_utc (1918, 3, 31, 11, 0, 0);
- GDateTime *gdt3 = gncdt.new_utc (1918, 4, 1, 11, 0, 0);
- GDateTime *gdt4 = gncdt.new_utc (2057, 11, 20, 11, 0, 0);
+ GDateTime *gdt1 = gncdt.new_utc (1999, 7, 21, 10, 59, 0);
+ GDateTime *gdt2 = gncdt.new_utc (1918, 3, 31, 10, 59, 0);
+ GDateTime *gdt3 = gncdt.new_utc (1918, 4, 1, 10, 59, 0);
+ GDateTime *gdt4 = gncdt.new_utc (2057, 11, 20, 10, 59, 0);
gint day, mon, yr;
Timespec t, r_t;
Summary of changes:
.../report-system/test/test-report-utilities.scm | 36 ++++++++-----------
.../standard-reports/test/test-cash-flow.scm | 41 +++++++++++++---------
2 files changed, 39 insertions(+), 38 deletions(-)
More information about the gnucash-changes
mailing list