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 upC level function that returns the offset at a given time-point in a given timezone #32
Conversation
…offset at a given time-point in a given timezone
|
Nice PR. Please also add ChangeLog and NEWS as usual. Maybe even a test :) |
| @@ -163,6 +163,10 @@ BEGIN_RCPP | |||
| END_RCPP | |||
| } | |||
|
|
|||
|
|
|||
| // export this function so it can be called at the C level by other packages: | |||
| int _RcppCCTZ_getOffset(long long s, const char* tzstr); | |||
eddelbuettel
Sep 7, 2019
Owner
int64_t, maybe, or uint64_t, or ...int128_t ? long long is less determined across architectures methinks.
Also: do we really need more than, say uint64_t ?
int64_t, maybe, or uint64_t, or ...int128_t ? long long is less determined across architectures methinks.
Also: do we really need more than, say uint64_t ?
lsilvest
Sep 7, 2019
Author
Contributor
Indeed, I pulled that from older code; I have changed that to std::int_fast64_t as that is what's used throughout the library.
Indeed, I pulled that from older code; I have changed that to std::int_fast64_t as that is what's used throughout the library.
eddelbuettel
Sep 7, 2019
Owner
I tend to use plain int64_t more but I trust the CCTZ folks on this :)
I tend to use plain int64_t more but I trust the CCTZ folks on this :)
| {NULL, NULL, 0} | ||
| }; | ||
|
|
||
| RcppExport void R_init_RcppCCTZ(DllInfo *dll) { | ||
| R_RegisterCCallable("RcppCCTZ", "_RcppCCTZ_getOffset", (DL_FUNC) &_RcppCCTZ_getOffset); |
eddelbuettel
Sep 7, 2019
Owner
Registering at the C level for other functions is such a good idea that I am really embarrassed I did not think of it myself. There is probably scope for one or two more so yes, let's get this started!
Registering at the C level for other functions is such a good idea that I am really embarrassed I did not think of it myself. There is probably scope for one or two more so yes, let's get this started!
lsilvest
Sep 7, 2019
Author
Contributor
Yes, will try to think about a coherent set that would make sense. Shall I create an issue to keep track of this?
Yes, will try to think about a coherent set that would make sense. Shall I create an issue to keep track of this?
eddelbuettel
Sep 7, 2019
Owner
Yes please! Issues are best for that.
Yes please! Issues are best for that.
| const auto tp = time_point<seconds>(seconds(s)); | ||
| auto abs_lookup = tz.lookup(tp); | ||
| return abs_lookup.offset; | ||
| } |
eddelbuettel
Sep 7, 2019
Owner
Nice work.
Nice work.
lsilvest
Sep 7, 2019
Author
Contributor
Thanks; I have added a NEWS and ChangeLog and also bumped the minor version number from 0.2.6 to 0.2.7.
Thanks; I have added a NEWS and ChangeLog and also bumped the minor version number from 0.2.6 to 0.2.7.
lsilvest
Sep 7, 2019
Author
Contributor
Test is a little difficult, as we can't directly call this function from R, so we'd need a C++ only test. Not at all sure how to do this; shall we leave it as-is right now and look into this when we add additional C low-level routines?
Test is a little difficult, as we can't directly call this function from R, so we'd need a C++ only test. Not at all sure how to do this; shall we leave it as-is right now and look into this when we add additional C low-level routines?
eddelbuettel
Sep 7, 2019
Owner
Good point about the test (esp from another package) -- that is doable but not worth it.
But can we test the basic offset computation? Maybe from a wrapper?
Good point about the test (esp from another package) -- that is doable but not worth it.
But can we test the basic offset computation? Maybe from a wrapper?
lsilvest
Sep 7, 2019
Author
Contributor
I think the only way we can test the call from R is if we make an R function for it or for a function that calls it (which is for example what nanotime does. Then we would have to document it at the R level, right? Or can we write a wrapper without exporting it at the package level (which we could call something like _RcppCCTZ_test_exported_C_functions and would simply return TRUE or FALSE)?
I think the only way we can test the call from R is if we make an R function for it or for a function that calls it (which is for example what nanotime does. Then we would have to document it at the R level, right? Or can we write a wrapper without exporting it at the package level (which we could call something like _RcppCCTZ_test_exported_C_functions and would simply return TRUE or FALSE)?
eddelbuettel
Sep 7, 2019
Owner
You probably have thought much much harder about this particular question than I have.
So if we can't, we can't. The tests can of course come from the nanotime side too.
You probably have thought much much harder about this particular question than I have.
So if we can't, we can't. The tests can of course come from the nanotime side too.
lsilvest
Sep 7, 2019
Author
Contributor
nanotime makes that call and tests it with a few offsets, so I think it's OK for this function. That said, I'm not sure what's the best way to handle this issue that will come up again if additional functions are exported. Will think about that more...
nanotime makes that call and tests it with a few offsets, so I think it's OK for this function. That said, I'm not sure what's the best way to handle this issue that will come up again if additional functions are exported. Will think about that more...
eddelbuettel
Sep 7, 2019
Owner
In Rcpp we went balistic (as we had to ...) and within the unit testing framework build and a run a client package. It's all just scripting ...
In Rcpp we went balistic (as we had to ...) and within the unit testing framework build and a run a client package. It's all just scripting ...
lsilvest
Sep 7, 2019
Author
Contributor
Seems the way to go: will look at how it's done in Rccp.
Seems the way to go: will look at how it's done in Rccp.
eddelbuettel
Sep 7, 2019
Owner
Not sure we need to here. Tests over from nanotime seems fine and legit given that we own both ends.
Not sure we need to here. Tests over from nanotime seems fine and legit given that we own both ends.
…r to 'std::int_fast64_t'
|
Don't mean to be a pain with ChangeLog and inst/NEWS.Rd. If you prefer that I do it that's fine too. Just let me know... |
| @@ -1,8 +1,8 @@ | |||
| Package: RcppCCTZ | |||
| Type: Package | |||
| Title: 'Rcpp' Bindings for the 'CCTZ' Library | |||
| Version: 0.2.6 | |||
| Date: 2019-08-03 | |||
| Version: 0.2.7 | |||
eddelbuettel
Sep 7, 2019
Owner
I tend not to make releases from PRs quite yet. Let's make tthat 0.2.6.1, and adjust the ChangeLog to one of those 'Roll minor version' entries as well?
I tend not to make releases from PRs quite yet. Let's make tthat 0.2.6.1, and adjust the ChangeLog to one of those 'Roll minor version' entries as well?
lsilvest
Sep 7, 2019
Author
Contributor
Absolutely, that makes sense.
Absolutely, that makes sense.
lsilvest
Sep 7, 2019
Author
Contributor
Btw, the reason a version change is good is that nanotime will depend on it in order for period to work correctly, so it's useful that we can request that specific version. So 0.2.6.1 works perfectly :)
Btw, the reason a version change is good is that nanotime will depend on it in order for period to work correctly, so it's useful that we can request that specific version. So 0.2.6.1 works perfectly :)
eddelbuettel
Sep 7, 2019
Owner
I have been using that three-digits-for-releases and four for interim versions that are still differentiable for a really long time. It really works. :) And also with the package_version S3 class (and/or the dpkg package comparison).
I have been using that three-digits-for-releases and four for interim versions that are still differentiable for a really long time. It really works. :) And also with the package_version S3 class (and/or the dpkg package comparison).
| @@ -0,0 +1,4 @@ | |||
| Changes in version 0.2.7 | |||
eddelbuettel
Sep 7, 2019
Owner
Sorry -- that should into inst/NEWS.Rd.
Sorry -- that should into inst/NEWS.Rd.
lsilvest
Sep 7, 2019
Author
Contributor
Ah, missed the location!
Ah, missed the location!
| @@ -1,3 +1,11 @@ | |||
| 2019-09-07 Leonardo Silvestri <lsilvestri@ztsdb.org> | |||
|
|
|||
| * DESCRIPTION (Version, Date): Release 0.2.7 | |||
eddelbuettel
Sep 7, 2019
Owner
'Roll minor version'
'Roll minor version'
eddelbuettel
Sep 7, 2019
Owner
Looks like this still says 0.2.7. I'll clean it up in a minute ...
Looks like this still says 0.2.7. I'll clean it up in a minute ...
eddelbuettel
Sep 7, 2019
Owner
Or maybe I am caught in a 'you are reviewing, finish this' loop at GH...
Or maybe I am caught in a 'you are reviewing, finish this' loop at GH...
23cdb32
into
eddelbuettel:master
|
I edited the ChangeLog and pushed so make sure you pull if you need to make further changes. Thanks for the PR -- very nice! |
|
Excellent, thanks! |
For
nanotime'speriodtype, we need access to the timezone data so that adding and subtracting aperiodis correctly handled. The operation look like this:In order to do this, we need a function to get the offset for a particular timezone at a given time-point, the function
getOffset.This function is then registered as a C function using
R_RegisterCCallableso that it can be called at C level by another package.This is an ad-hoc change for
nanotime, but it could make sense to add the set of functions exported in R (or one could wait until there's a specific request of course!).