gnucash maint: Bug 774237 - FTBFS under some timezones (eg. GMT-14)
John Ralls
jralls at code.gnucash.org
Sat Dec 10 17:33:14 EST 2016
Updated via https://github.com/Gnucash/gnucash/commit/fcd817a6 (commit)
from https://github.com/Gnucash/gnucash/commit/fc3dc3e7 (commit)
commit fcd817a6bf44298173a0053e63bf8397c0381a21
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Dec 10 14:26:16 2016 -0800
Bug 774237 - FTBFS under some timezones (eg. GMT-14)
Fix the neutral offset calculations so that the fixed UTC time doesn't
change the date in the timezones near the international date line. Divide
offset by 60 instead of 3600 so that the Chatham Islands (GMT-12:45 with DST)
use 9:59 instead of 10:59 like the rest of NZ (GMT-12).
diff --git a/src/libqof/qof/gnc-date-p.h b/src/libqof/qof/gnc-date-p.h
index 80e064f..161f0ef 100644
--- a/src/libqof/qof/gnc-date-p.h
+++ b/src/libqof/qof/gnc-date-p.h
@@ -70,6 +70,7 @@ const char *qof_win32_get_time_format(QofWin32Picture picture);
typedef struct
{
void (*timespec_normalize) (Timespec *t);
+ GTimeZone* (*timezone_new_local) (void);
} Testfuncs;
Testfuncs *gnc_date_load_funcs (void);
diff --git a/src/libqof/qof/gnc-date.c b/src/libqof/qof/gnc-date.c
index d23d197..27c52ff 100644
--- a/src/libqof/qof/gnc-date.c
+++ b/src/libqof/qof/gnc-date.c
@@ -1581,16 +1581,17 @@ gnc_dmy2timespec_neutral (int day, int month, int year)
struct tm date;
Timespec ts = {0, 0};
GTimeZone *zone = gnc_g_time_zone_new_local();
- GDateTime *gdt = gnc_g_date_time_new_local (year, month, day, 12, 0, 0.0);
+ GDateTime *gdt = gnc_g_date_time_new_local (year, month, day, 10, 59, 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(zone, interval) / 3600;
+ int offset = g_time_zone_get_offset(zone, interval) / 60;
+ int off_hr = (offset / 60) + (offset % 60 ? (offset < 0 ? -1 : 1) : 0);
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 ? 23 - offset : 10;
+ date.tm_hour = off_hr < -10 ? -off_hr : off_hr > 13 ? 23 - off_hr : 10;
date.tm_min = 59;
date.tm_sec = 0;
@@ -1813,5 +1814,6 @@ gnc_date_load_funcs (void)
{
Testfuncs *tf = g_slice_new (Testfuncs);
tf->timespec_normalize = timespec_normalize;
+ tf->timezone_new_local = gnc_g_time_zone_new_local;
return tf;
}
diff --git a/src/libqof/qof/test/test-gnc-date.c b/src/libqof/qof/test/test-gnc-date.c
index 6aefd3f..acd48f9 100644
--- a/src/libqof/qof/test/test-gnc-date.c
+++ b/src/libqof/qof/test/test-gnc-date.c
@@ -1972,14 +1972,30 @@ test_gnc_dmy2timespec_end (void)
g_date_time_unref (gdt4);
}
+static GDateTime*
+offset_adjust(GDateTime *gdt)
+{
+ Testfuncs *tf = gnc_date_load_funcs();
+ GTimeZone *zone = tf->timezone_new_local();
+ 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(zone, interval) / 60;
+ int off_hr = (offset / 60) + (offset % 60 ? (offset < 0 ? -1 : 1) : 0);
+ int correction = off_hr < -10 ? -10 - off_hr : off_hr > 13 ? 13 - off_hr : 0;
+ GDateTime* new_gdt = g_date_time_add_hours(gdt, correction);
+ g_date_time_unref(gdt);
+ g_slice_free(Testfuncs, tf);
+ return new_gdt;
+}
+
/*gnc_dmy2timespec_neutral*/
static void
test_gnc_dmy2timespec_neutral (void)
{
- 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);
+ GDateTime *gdt1 = offset_adjust(gncdt.new_utc (1999, 7, 21, 10, 59, 0));
+ GDateTime *gdt2 = offset_adjust(gncdt.new_utc (1918, 3, 31, 10, 59, 0));
+ GDateTime *gdt3 = offset_adjust(gncdt.new_utc (1918, 4, 1, 10, 59, 0));
+ GDateTime *gdt4 = offset_adjust(gncdt.new_utc (2057, 11, 20, 10, 59, 0));
gint day, mon, yr;
Timespec t, r_t;
@@ -2132,10 +2148,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, 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);
+ GDateTime *gdt1 = offset_adjust(gncdt.new_utc (1999, 7, 21, 10, 59, 0));
+ GDateTime *gdt2 = offset_adjust(gncdt.new_utc (1918, 3, 31, 10, 59, 0));
+ GDateTime *gdt3 = offset_adjust(gncdt.new_utc (1918, 4, 1, 10, 59, 0));
+ GDateTime *gdt4 = offset_adjust(gncdt.new_utc (2057, 11, 20, 10, 59, 0));
gint day, mon, yr;
Timespec t, r_t;
@@ -2416,7 +2432,6 @@ test_suite_gnc_date (void)
{
_gnc_date_time_init (&gncdt);
-
GNC_TEST_ADD_FUNC (suitename, "gnc localtime", test_gnc_localtime);
GNC_TEST_ADD_FUNC (suitename, "gnc gmtime", test_gnc_gmtime);
GNC_TEST_ADD_FUNC (suitename, "gnc mktime", test_gnc_mktime);
Summary of changes:
src/libqof/qof/gnc-date-p.h | 1 +
src/libqof/qof/gnc-date.c | 8 +++++---
src/libqof/qof/test/test-gnc-date.c | 33 ++++++++++++++++++++++++---------
3 files changed, 30 insertions(+), 12 deletions(-)
More information about the gnucash-changes
mailing list