-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fix signedness bug #19
base: master
Are you sure you want to change the base?
Conversation
this fixes calculation for all years < 1200.
When testing with dates < 1200 one will encounter a bug which results in the wrong unix timestamps being generated:
without the bugfix: with the bugfix |
I'm not sure I have authorization to release this—I'm not even 100% sure I know how to build/test it, to be honest—but I'd feel a lot more comfortable about trying if you could add a test for it to your merge request. Thx for your contribution! |
@barefootcoder thanks for the suggestion, while trying to write unit tests I found one more issue with the function: With my first commit ("Fix signedness bug") the difference is only one day though. The reason for this seems to be that the function in one case counts the leap years upward starting from 2000 and skips 2401, while in the other case it starts from 2401 and skips 2000. I think that the one that skips the larger year is the correct behavior, but I'm not 100% certain on that. I modified the function such that in both cases this is the behavior. Since thinking about which of the years on the edge of the interval is quiet tricky I would be grateful if someone could verify my calculations for the leap years between 0 and 1901 or check some negative dates. There is a chance that the second_between_years should instead consider the lowest provided year and no the highest one and that it was intended behavoir. Best, Benjamin |
Oh no, I think it's even more complicated: The right year in the only usage of this function is passed through Lines 345 to 347 in c17a49a
, so it matches the left year in it's number of days. Leaving out the first instead of the last year in the iteration should not make a difference this way. The function was probably designed in such a way that it is only able to give the correct result for years that satisfy this requirement, such that it does not matter if one skips the first or last year. Maybe one could rename the function from But that also means that the tests for this function like y2038/t/seconds_between_years.t.c Line 14 in c17a49a
can not be written as straightfoward as one might think. The dates with which the function can be tested must either both be leap years or both be normal years. Some of the current tests do not satisfy this requirement, but still work because the iteration direction was starting from the lower year 2000: Lines 531 to 532 in c17a49a
I think the solution of this will take some time... Best, Benjamin |
Tests should be fixed now. |
this fixes calculation for all years < 1200.