gigasecond: Addresses: 319#344
Conversation
Use a direct implementation of construct_date. This avoids issues with mktime(). timegm() not used as not universal. All tests pass with standard solution.
|
Hey @DrJPizzle Thanks for the submission. I'm a bit concerned about the complexity of this solution given that it's much more complicated than the actual problem. If you were to use Additionally, be sure to run |
|
@ryanplusplus mktime was the cause of the problem. It works is 99.9% of cases, but its implementation is pretty complex, (it deals with leap seconds, has complex handling of DST etc) and issues can arise, as seen in the initial issue report. |
|
@DrJPizzle I was referring to this comment from you:
|
|
This would be an addition. You would still need the existing code. Perhaps some clarification of thinking is in order: As a result most applications fall into 2 categories:
And the libraries that do the conversion, tend to be a complex 'best-effort' affair. There are none that I know of that for example do leap-years and time zones but not DST that are universally present in the standard library. The reason being, most of the time the human readable form came from a system time that's regularly updated, has drift problems, is subject to all these changes and complexities etc. Hence everything is a guess, and so you may as well have as good a guess as possible. For example where I am:
Whereas
but
For your test cases though the answers are not so nuanced. I guess they are based on one particular location. I.e.: the tests are of the form: But as seem from above: the question of: what time/date comes 1e9 seconds after "6 Feb 12:53:20 2002" doesn't have an answer. (It does have an answer in UTC, which seems to be the answer you are after.) I don't see a way around this issue if you need to use one of those libraries that "just takes care" of the conversion. You will need your own (gmtime() aside as discussed). There is a separate point I was getting at by:
That is the question mostly has the same answer in any fixed timezone. The only exception I can see is if the start or end time would have include a leap second differently depending on the timezone. |
|
Thanks @DrJPizzle. I think for now we should go with these changes. Long term we can wait to see if there is a change in the exercise in the common repo or look at simply dropping the exercise. Can you run |
|
Thanks! |
|
Interesting discussion. Currently going through some changes in the common repo here. |
Well done @bergjohan , thanks for working on this first one 🎉
Well done @bergjohan , thanks for working on this first one 🎉
Use a direct implementation of construct_date.
This avoids issues with mktime().
timegm() not used as not universal.
All tests pass with standard solution.