After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 506251 - src/engine/test/test-date fails on systems with a timezone east of UTC
src/engine/test/test-date fails on systems with a timezone east of UTC
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Engine
git-master
Other Windows
: Normal minor
: ---
Assigned To: Derek Atkins
Derek Atkins
Depends on:
Blocks:
 
 
Reported: 2007-12-29 14:01 UTC by Daniel Harding
Modified: 2018-06-29 21:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Output from test-date when failing. (10.64 KB, text/plain)
2008-11-15 20:33 UTC, Daniel Harding
  Details
Simplistic fix to test-date.c to prevent timezone-related failures. (3.37 KB, patch)
2008-11-15 20:40 UTC, Daniel Harding
committed Details | Review

Description Daniel Harding 2007-12-29 14:01:13 UTC
I was seeing multiple failures in src/engine/test/test-date when running "make check".  I tracked this down to the usage of mktime() in gnc_iso8601_to_timespec_gmt and gnc_timespec_to_iso8601_buff.  When the timespec is (or would be) very close to the epoch, mktime() will fail if the timezone is east of UTC.

For example, consider gnc_iso8601_to_timespec_gmt where the resulting timespec should be zero.  Because mktime actually returns local time, if the timezone is east of UTC, the local time time_t value corresponding to a zero timespec would actually be negative.  mktime cannot handle this and errors out with the value of -1, causing the conversion to fail.

src/engine/test/test-date.c has multiple tests that specify/require timespecs at or very close to zero.  Lines 93-134 explicitly test strings that should result in a zero timespec, which all fail on systems with timezones east of UTC.  In addition, the loops in lines 397-402 and 404-418 can also result in timespecs that will fail.  Fixing the loops is easy - simply skip any iterations in which the timespec falls in the range [0, max(0, -gnc_timezone()) ).  The zero timespec tests cannot be fixed without either reimplementing gnc_iso8601_to_timespec_gmt to not depend on mktime, or changing the test to use a timespec at least twelve hours later than the zero timespec.  They could probably also be safely removed since there are plenty of other tests using non-failing timespecs to make sure the conversions happen properly.  It is unlikely that the zero timespec tests will catch any errors that the other tests will not.
Comment 1 Rolf Leggewie 2008-11-14 21:18:52 UTC
Is this still an issue.  I understand this is a compile-time problem.  I still wonder if it has anything to do with bug 137017.
Comment 2 Daniel Harding 2008-11-15 20:33:23 UTC
Created attachment 122750 [details]
Output from test-date when failing.

Yes, it is still an issue.  The test compiles fine, it simply fails at run-time when run on a system with a time zone east of UTC (for example, UTC+10:00 for Sydney, Australia).  I have attached the output of the test in the failure case.
Comment 3 Daniel Harding 2008-11-15 20:40:21 UTC
Created attachment 122751 [details] [review]
Simplistic fix to test-date.c to prevent timezone-related failures.

Here is a patch that fixes this problem in a very simplistic way:  it removes all the calls to check_conversion which test zero seconds (the epoch) and it changes the check_time function to skip any timestamps that are before noon on January 1, 1970, UTC.  This may not be the best approach to solving the problem, however.
Comment 4 Christian Stimming 2008-11-26 13:40:22 UTC
Committed to trunk, r17721. Thanks!
Comment 5 John Ralls 2018-06-29 21:57:41 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=506251. Please update any external references or bookmarks.