Since RcppDate (classic class) is moving out of Rcpp I'm trying to use Rcpp::Date and there seems to be a small problem. getYear() method adds 1900 when it shouldn't, so 2001 becoms 3901, for example. I assume that Rcpp::Date and Rcpp::Datetime are intended to be replacements for RcppDate and RcppDatetime, resp., but they seem to be missing std::ostream operator<<(). Rcpp::Date also seems to have more timezone related logic. Is there documentation on this? Thanks, Dominick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101204/b61bfcf3/attachment.htm>
[Rcpp-devel] Rcpp::Date bug
4 messages · Dominick Samperi, Dirk Eddelbuettel
On 4 December 2010 at 15:04, Dominick Samperi wrote:
| getYear() method adds 1900 when it shouldn't, so 2001 becoms 3901,
| for example.
Confirmed:
R> require(inline, quiet=TRUE, warn=FALSE)
R> require(Rcpp, quiet=TRUE, warn=FALSE)
R>
R> foo <- cxxfunction(signature(sDate="Date"), '
+ Rcpp::Date d(sDate);
+ return(Rcpp::List::create(Rcpp::Named("day") = d.getDay(),
+ Rcpp::Named("month") = d.getMonth(),
+ Rcpp::Named("year") = d.getYear(),
+ Rcpp::Named("weekeday") = d.getWeekday(),
+ Rcpp::Named("yearday") = d.getYearday()));
+ ', plugin="Rcpp")
R>
R> foo(Sys.Date())
$day
[1] 4
$month
[1] 12
$year
[1] 3910
$weekeday
[1] 7
$yearday
[1] 338
R>
Now fixed in rev2714.
Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
On Sat, Dec 4, 2010 at 3:22 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
On 4 December 2010 at 15:04, Dominick Samperi wrote:
| getYear() method adds 1900 when it shouldn't, so 2001 becoms 3901,
| for example.
Confirmed:
R> require(inline, quiet=TRUE, warn=FALSE)
R> require(Rcpp, quiet=TRUE, warn=FALSE)
R>
R> foo <- cxxfunction(signature(sDate="Date"), '
+ Rcpp::Date d(sDate);
+ return(Rcpp::List::create(Rcpp::Named("day") = d.getDay(),
+ Rcpp::Named("month") = d.getMonth(),
+ Rcpp::Named("year") = d.getYear(),
+ Rcpp::Named("weekeday") = d.getWeekday(),
+ Rcpp::Named("yearday") = d.getYearday()));
+ ', plugin="Rcpp")
R>
R> foo(Sys.Date())
$day
[1] 4
$month
[1] 12
$year
[1] 3910
$weekeday
[1] 7
$yearday
[1] 338
R>
Now fixed in rev2714.
Thanks. Another small issue: the getHour() method of Rcpp::Datetime appears to return GMT time. Is there an easy way to convert to localtime?
Dirk -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101204/e7e10367/attachment.htm>
On 4 December 2010 at 19:13, Dominick Samperi wrote:
| Another small issue: the getHour() method of Rcpp::Datetime appears | to return GMT time. Is there an easy way to convert to localtime? Dealing with TZ consistently is a bit like descending in a snake-filled pit, especially when the architecture and platform issues get added. For my purposes, UTC at the C++ level has been sufficient. If I must translate to local or others, this has usually been done at the R level. I may only have encoded gmtime() and could maybe revisit to support localtime() too -- if that was the issue -- but I am not sure when I'd get to that. Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com