Skip to content

Commit 0187051

Browse files
committed
allow setting the timezone
default is empty string == not set which implies local timezone that is what we had before, and what R does
1 parent 5b88a1b commit 0187051

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2016-10-17 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/date_datetime/newDatetimeVector.h (Rcpp): Allow
4+
setting of timezone attribute; default not-set leads to local as in R
5+
16
2016-10-16 Dirk Eddelbuettel <[email protected]>
27

38
* inst/include/Rcpp.h (RCPP_NEW_DATE_DATETIME_VECTORS): Add a new

inst/include/Rcpp/date_datetime/newDatetimeVector.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ namespace Rcpp {
2828

2929
class newDatetimeVector : public NumericVector {
3030
public:
31-
newDatetimeVector(SEXP vec) : NumericVector(vec) { setClass(); }
32-
newDatetimeVector(int n) : NumericVector(n) { setClass(); }
31+
newDatetimeVector(SEXP vec, const char* tz = "") :
32+
NumericVector(vec) {
33+
setClass(tz);
34+
}
35+
newDatetimeVector(int n, const char* tz = "") :
36+
NumericVector(n) {
37+
setClass(tz);
38+
}
3339

3440
inline std::vector<Datetime> getDatetimes() const {
3541
int n = this->size();
@@ -41,11 +47,16 @@ namespace Rcpp {
4147

4248
private:
4349

44-
void setClass() {
50+
void setClass(const char *tz) {
4551
Shield<SEXP> datetimeclass(Rf_allocVector(STRSXP,2));
4652
SET_STRING_ELT(datetimeclass, 0, Rf_mkChar("POSIXct"));
4753
SET_STRING_ELT(datetimeclass, 1, Rf_mkChar("POSIXt"));
4854
Rf_setAttrib(*this, R_ClassSymbol, datetimeclass);
55+
56+
if (tz != "") {
57+
Shield<SEXP> tzsexp(Rf_mkString(tz));
58+
Rf_setAttrib(*this, Rf_install("tzone"), tzsexp);
59+
}
4960
}
5061
};
5162
}

0 commit comments

Comments
 (0)