Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upupdate time_t to use the Rcpp mktime00 function on on non-unix system… #6
Conversation
…s, uncure if removing the timezone setting is incorrect, however get/setenv were giving errors.
|
Result of running R CMD CHECK passed
|
| } else | ||
| unsetenv("TZ"); | ||
| tzset(); | ||
| time_t ret = Rcpp::mktime00(*tm); |
dpastoor
Jan 4, 2017
Author
Contributor
@eddelbuettel I blew away the getenv/setenv() components as I'm getting an undeclared identifier error for both?
@eddelbuettel I blew away the getenv/setenv() components as I'm getting an undeclared identifier error for both?
eddelbuettel
Jan 4, 2017
Owner
We can get setenv() / getenv() from somewhere else. That has come up before.
We can get setenv() / getenv() from somewhere else. That has come up before.
| } else | ||
| unsetenv("TZ"); | ||
| tzset(); | ||
| time_t ret = Rcpp::mktime00(*tm); |
eddelbuettel
Jan 4, 2017
Owner
It's a fair idea but we may need the TZ variable... Let me give this some more thought.
But a very good first step.
It's a fair idea but we may need the TZ variable... Let me give this some more thought.
But a very good first step.
eddelbuettel
Jan 4, 2017
Owner
Different route: I just defined another elif defined(__MINGW32__) || defined(__MINGW32__) and in that just call mktime00() as you do here. Seems to work.
Different route: I just defined another elif defined(__MINGW32__) || defined(__MINGW32__) and in that just call mktime00() as you do here. Seems to work.
|
@eddelbuettel like this? Wouldn't we still want a trailing else to fall back on something? Also, will mktime00 handle tz() properly (it looks like it does in the cursory test checks you have) |
|
I think localtime seeps through, as we are coming from R, we are generally set. |
|
Can you make your change to // cf 'man timegm' for the workaround on non-Linux systems
inline time_t local_timegm(struct tm *tm) {
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
// and there may be more OSs that have timegm() ...
return timegm(tm);
#elif defined(__MINGW32__) || defined(__MINGW64__)
return Rcpp::mktime00(*tm); // Rcpp exports a copy of the R-internal function
#else
char *tz = getenv("TZ");
if (tz) tz = strdup(tz);
setenv("TZ", "", 1);
tzset();
time_t ret = mktime(tm);
if (tz) {
setenv("TZ", tz, 1);
free(tz);
} else
unsetenv("TZ");
tzset();
return ret;
#endif
} |
|
I merged by hand. Your two commits are in. |
|
great! I also just built and ran the tomlExamples related to time and worked great! |
|
Yep, I ran those too just like you and I think we're good. Will commit in a moment into a new branch (or, rather, the stale branch I had here for six months), then try to catch up to cpptoml upstream ... and with that head towards a 0.1.0 releases. This has been a really useful chat! |
|
Thank you so much for your work - really looking forward to being able to use this instead of yaml! |
|
This PR is now indirectly merge (crediting two of your commits) but I wanted in a branch first for more testing and changes... |
…s, uncure if removing the timezone setting is incorrect, however get/setenv were giving errors.