Run only one of mini_mktime(), mktime() #21885
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mini_mktime() is a faster, stripped down version of mktime() that ignores locale-dependent information. But it doesn't work when the structure it fills in contains fields that are locale-related. A patch 20 some years ago called mktime() to fill in the missing fields.
But that ends up executing similar algorithms twice. If we need the locale-related info, why not just call mktime() once and be done with it. I figured I must be missing something, so started a smoke-me branch with this change. https://perl.develop-help.com/?b=smoke-me%2Fkhw-mktime. So far everything is passing.
There is one glitch on my Linux glibc. mktime() did not accept 60 for the second number (a leap second) , and mini_mktime() does. And there is a test that includes a leap second.
The right thing to do to calculate the number of seconds since the epoch is to have a table of when actual leap seconds happened, and take that into account. I guess there haven't been enough of them to make a difference. https://en.wikipedia.org/wiki/Leap_second has an extended discussion on this.
This commit uses plain mktime() when the fields exist that are not populated by min_mktime