Skip to content

Commit 8e90f89

Browse files
committed
Merge PR 587 by @dcdillon
2 parents 8aeb038 + 14c68d8 commit 8e90f89

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

ChangeLog

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@
1010
* inst/include/Rcpp/vector/Matrix.h: Protected Matrix op Scalar
1111
definitions with #ifndef RCPP_NO_SUGAR
1212

13+
* inst/include/Rcpp/date_datetime/newDateVector.h: Fixed the copy
14+
constructor and added assignment operator.
15+
* inst/include/Rcpp/date_datetime/newDatetimeVector.h: Fixed the copy
16+
constructor and added assignment operator.
17+
* inst/unitTests/cpp/dates.cpp: Added assignment operator tests for
18+
DatetimeVector and DateVector for both new and old.
19+
* inst/unitTests/runit.Date.R: Added assignment operator tests for
20+
DatetimeVector and DateVector for both new and old.
21+
1322
2016-11-10 Dirk Eddelbuettel <[email protected]>
1423

1524
* inst/include/Rcpp/date_datetime/newDateVector.h: Added constructor
1625
using VectorBase<>
1726

18-
2016-01-05 Daniel C. Dillon <[email protected]>
27+
2016-11-05 Daniel C. Dillon <[email protected]>
1928

2029
* inst/include/Rcpp/date_datetime/newDatetimeVector.h: Added constructor
2130
to instantiate newDatetimeVector from VectorBase.

inst/include/Rcpp/date_datetime/newDateVector.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace Rcpp {
2929
class newDateVector : public NumericVector {
3030
public:
3131
template <int RTYPE, bool NA, typename VEC>
32-
newDateVector(const VectorBase<RTYPE,NA,VEC>& vec) : NumericVector(vec) {}
32+
newDateVector(const VectorBase<RTYPE,NA,VEC>& vec) : NumericVector(vec) {
33+
setClass();
34+
}
3335

3436
newDateVector(SEXP vec) : NumericVector(vec) { setClass(); }
3537
newDateVector(int n) : NumericVector(n) { setClass(); }
@@ -41,6 +43,14 @@ namespace Rcpp {
4143
v[i] = (*this)[i];
4244
return v;
4345
}
46+
47+
inline newDateVector &operator=(const newDateVector &rhs) {
48+
if (this != &rhs) {
49+
NumericVector::operator=(rhs);
50+
}
51+
52+
return *this;
53+
}
4454

4555
private:
4656

inst/include/Rcpp/date_datetime/newDatetimeVector.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace Rcpp {
3030
public:
3131
template <int RTYPE, bool NA, typename VEC>
3232
newDatetimeVector(const VectorBase<RTYPE,NA,VEC>& other) :
33-
NumericVector(other) {}
33+
NumericVector(other) {
34+
setClass(other.attr("tzone"));
35+
}
3436

3537
newDatetimeVector(SEXP vec, const char* tz = "") :
3638
NumericVector(vec) {
@@ -49,6 +51,15 @@ namespace Rcpp {
4951
v[i] = (*this)[i];
5052
return v;
5153
}
54+
55+
inline newDatetimeVector &operator=(const newDatetimeVector &rhs) {
56+
if (this != &rhs) {
57+
NumericVector::operator=(rhs);
58+
this->attr("tzone") = rhs.attr("tzone");
59+
}
60+
61+
return *this;
62+
}
5263

5364
private:
5465

inst/unitTests/cpp/dates.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,17 @@ SEXP DatetimeVector_ctor(DatetimeVector d) {
158158
DatetimeVector dt = DatetimeVector(d);
159159
return wrap(dt);
160160
}
161+
162+
// [[Rcpp::export]]
163+
DatetimeVector DatetimeVector_assignment(DatetimeVector v1,
164+
DatetimeVector v2) {
165+
166+
v1 = v2;
167+
return v1;
168+
}
169+
170+
// [[Rcpp::export]]
171+
DateVector DateVector_assignment(DateVector v1, DateVector v2) {
172+
v1 = v2;
173+
return v1;
174+
}

inst/unitTests/runit.Date.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,19 @@ if (.runThisTest) {
181181
checkEquals(fun(vec), c(now, rep(posixtNA, 3), now+2.345), msg = "Datetime.ctor.NA.NaN.Inf.set")
182182
}
183183
}
184+
185+
test.DatetimeVector.assignment <- function() {
186+
now <- Sys.time()
187+
v1 <- c(now, now + 1, now + 2)
188+
v2 <- c(now + 3, now + 4, now + 5)
189+
checkEquals(v2, DatetimeVector_assignment(v1, v2))
190+
}
191+
192+
test.DateVector.assignment <- function() {
193+
now <- Sys.Date()
194+
v1 <- c(now, now + 1, now + 2)
195+
v2 <- c(now + 3, now + 4, now + 5)
196+
checkEquals(v2, DateVector_assignment(v1, v2))
197+
}
184198

185199
}

0 commit comments

Comments
 (0)