-
Notifications
You must be signed in to change notification settings - Fork 3
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
Time improvements #27
Conversation
…n Unix systems. Fixed slightly broken unit test for weekdays under MSVC.
…altime_s / gmtime_s or localtime_r / gmtime_r to avoid crashes.
Pull Request Test Coverage Report for Build db3b7966-1e9d-4fbf-ab64-e115ee9942d8Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning error handling: I would be fine with returning a xlnt::optional
object by your new *_safe
functions.
However, the only function that reasonably may fail is date::weekday
(as the others use the current date/time as input), but I think this function doesn't need to use localtime_safe
(see below).
…rding to the feedback. Fixed an issue in the time_helpers under MSVC where the error and success cases were handled the other way around.
As a minor remark, coverage is decreased due to the |
… tests for cases where dates and datetimes are null (invalid/empty).
Good point, thank you! I added unit tests for covering all cases that might fail due to an invalid |
…ases. This fixes unit tests passing on MSVC but not passing when using other compilers.
And, once again, CI has caught a case where all unit tests passed on MSVC, but failed on Linux. Nice! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor remarks. We are almost there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the changes!
As promised, this pull request does the following:
localtime_r
on Linux and other Unix systems that support it to improve thread-safety.Note: the improved wrappers for the C time functions are based on the previous ones, but contain the improvements stated above. However, this also means that the new wrappers - just like the old ones - don't have any handling for failed calls to
localtime
orgmtime
. For example, under MSVC, the C Standard Library of MSVC has the limitation forlocaltime
,gmtime
andmktime
that it only supports dates between January 1st 1970 00:00:00 UTC and December 31st 3000 23:59:59 UTC. However, Excel supports dates beginning with January 1st, 1900, while XLNT under MSVC would not handle it correctly, without any information to the caller of our safe functions that something failed. We could change that by returning anxlnt::optional
in case we detect that something has failed. Currently, the following will happen:localtime_s
andgmtime_s
(under MSVC), as well aslocaltime_r
andgmtime_r
under Unix, a default-initializedstd::tm
would be returned (that is not useful in most cases, of course)std::localtime
andstd::gmtime
(on other systems than Windows and Unix),we would dereference achanged to no longer cause a crash and behave like on Windows and Unix - but this still means that the caller has no idea that the call failednullptr
and cause a crashI definitely think that this is not great and should be improved - but I created this pull request to first ask what you @m7913d think about my proposed solution 🙂