Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_date_ymwdhMs fails because of summer time #1214

Closed
Apteryks opened this issue Mar 27, 2018 · 3 comments
Closed

test_date_ymwdhMs fails because of summer time #1214

Apteryks opened this issue Mar 27, 2018 · 3 comments

Comments

@Apteryks
Copy link

Expected or desired behavior

All the tests should succeed.

Actual behavior

The test_date_ymwdhMs in the test-utils.cc file fails like:

/utils/date-basic: OK
/utils/date-ymwdhMs: 3h 10800 10800
2w 1206000 1209600
**
ERROR:test-utils.cc:102:void test_date_ymwdhMs(): 'tests[i].diff - diff <= tests[i].tolerance' should be TRUE

Notice the the time difference is 1 h (3600 s). I attribute the problem to the fact that the date function uses the local time (taking into consideration summer time) but the expected diff does not (only does basic arithmetic such as 2 * 7 * 24 * 60 * 60).

I'm not sure of a good solution: should we bump the tolerance up to 3600 s, or should we set the date of the tests to some time where there are no summer time effects, or... ?

This was discovered by attempting to build mu with Guix (https://www.gnu.org/guix/).

Thank you!

Steps to reproduce

Build the latest stable release and run the tests.

Versions of mu, mu4e/emacs, operating system etc.

Guix at commit 4bd2e2a5b04a52e2ebccb23e782efd53199e8af6 (mu 1.0, glib 2.54.2, etc.)

@Apteryks
Copy link
Author

I've done some more experiments and yeah, the reason is because glib is smarter than the tests when it comes to DST.

#include <assert.h>
using namespace std;

GDateTime* now0 = g_date_time_new_now_local();
time_t now0_sec = g_date_time_to_unix(now0);
time_t now1_sec = time(NULL);
cout << "glib unix time: " << now0_sec << endl;
cout << "<time.h> unix time: " << now1_sec << endl;
assert(now0_sec == now1_sec);

GDateTime* then0 = g_date_time_add_weeks(now0, -2);
time_t then0_sec = g_date_time_to_unix(then0);
cout << "2 weeks (glib) ago was: " << then0_sec << endl;

time_t then1_sec = now1_sec - (2 * 7 * 24 * 3600);
cout << "2 weeks (manual) ago was: " << then1_sec << endl;
cout << "diff is: " << then0_sec - then1_sec << endl;

Produces the output:

glib unix time: 1522200829
<time.h> unix time: 1522200829
2 weeks (glib) ago was: 1520994829
2 weeks (manual) ago was: 1520991229
/utils/date-basic: OK
/utils/date-ymwdhMs: glib unix time: 1522200966
<time.h> unix time: 1522200966
2 weeks (glib) ago was: 1520994966
2 weeks (manual) ago was: 1520991366
diff is: 3600

@bojov
Copy link

bojov commented Mar 28, 2018

The same problem problem on Fedora 27 with latest updates and mu v1.0 and mu master repos.
make test on v1.0 returns:
TEST: test-utils... (pid=12963) /utils/date-basic: OK /utils/date-ymwdhMs: ** ERROR:test-utils.cc:102:void test_date_ymwdhMs(): 'tests[i].diff - diff <= tests[i].tolerance' should be TRUE FAIL GTester: last random seed: R02S2bcfca7b9f16ec501af68bc265a1bb57
make test on mu master branch returns:
TEST: test-utils... (pid=5538) /utils/date-basic: OK /utils/date-ymwdhMs: ** ERROR:test-utils.cc:105:void test_date_ymwdhMs(): 'tests[i].diff - diff <= tests[i].tolerance' should be TRUE FAIL GTester: last random seed: R02S6eb022ec8d99045526d31c4491df831e

@djcb
Copy link
Owner

djcb commented Mar 31, 2018

Ah, good catch! I've fixed it.

@djcb djcb closed this as completed Mar 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants