[Rcpp-commits] r3800 - in pkg/RcppBDT: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Oct 21 16:56:18 CEST 2012
Author: edd
Date: 2012-10-21 16:56:18 +0200 (Sun, 21 Oct 2012)
New Revision: 3800
Modified:
pkg/RcppBDT/ChangeLog
pkg/RcppBDT/src/RcppBDTpt.cpp
Log:
added ctor from numeric
Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog 2012-10-21 14:06:12 UTC (rev 3799)
+++ pkg/RcppBDT/ChangeLog 2012-10-21 14:56:18 UTC (rev 3800)
@@ -2,6 +2,7 @@
* src/RcppBDTpt.cpp: Added addHours(), addMinutes(), addSeconds() and
addFractionalSeconds() to posix time class, shadowing Boost's side
+ * src/RcppBDTpt.cpp: Added constructor from numeric
2012-09-22 Dirk Eddelbuettel <edd at debian.org>
Modified: pkg/RcppBDT/src/RcppBDTpt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTpt.cpp 2012-10-21 14:06:12 UTC (rev 3799)
+++ pkg/RcppBDT/src/RcppBDTpt.cpp 2012-10-21 14:56:18 UTC (rev 3800)
@@ -42,7 +42,8 @@
public:
bdtPt() { setFromLocalTimeInMicroSeconds(); } // default empty constructor
- bdtPt(SEXP dt) { setFromDatetime(dt); } // constructor from R's Datetime
+ bdtPt(SEXP dt) { setFromDatetime(dt); } // constructor from R's / Rcpp's Datetime
+ bdtPt(double dt) { setFromDouble(dt); } // constructor from double using Rcpp's Datetime
bdtPt(int year, int month, int day, // constructor from date and duration
int hours, int minutes, int seconds,
int fractionalseconds) : m_pt(boost::gregorian::date(year, month, day),
@@ -56,6 +57,11 @@
void setFromTimeT(const time_t t) { m_pt = boost::posix_time::from_time_t(t); }
void setFromDatetime(const SEXP dt) { m_pt = Rcpp::as<boost::posix_time::ptime>(dt); }
+ void setFromDouble(const double d) {
+ Rcpp::Datetime dt(d);
+ m_pt = boost::posix_time::ptime(boost::gregorian::date(dt.getYear(), dt.getMonth(), dt.getDay()),
+ boost::posix_time::time_duration(dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMicroSeconds()/1000.0));
+ }
Rcpp::Datetime getDatetime() { return Rcpp::wrap(m_pt); }
@@ -79,6 +85,7 @@
.constructor("default constructor setting current local time")
.constructor<SEXP>("constructor using R Datetime")
+ .constructor<double>("constructor from numeric via Datetime")
.constructor<int,int,int,int,int,int,int>("constructor with year, month, day, hours, minutes, seconds and fractional_seconds")
.method("setFromLocalTimeInSeconds", &bdtPt::setFromLocalTimeInSeconds, "set from local time with seconds")
More information about the Rcpp-commits
mailing list