Skip to content

Commit d85db8e

Browse files
committed
adding operator<< for Date(time)Vector
1 parent d41a48d commit d85db8e

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* inst/include/Rcpp/date_datetime/Date.h (format, operator<<): Added
44
* inst/include/Rcpp/date_datetime/Datetime.h (format, operator<<): Ditto
5+
* inst/include/Rcpp/date_datetime/newDateVector.h (operator<<): Ditto
6+
* inst/include/Rcpp/date_datetime/newDatetimeVector.h (operator<<): Ditto
57

68
2016-11-23 Dirk Eddelbuettel <[email protected]>
79

inst/NEWS.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
\itemize{
99
\item The exception stack message is now correctly demangled on all
1010
compiler versions (Jim Hester in \ghpr{598})
11-
\item Date and Datetime object now have format methods
11+
\item Date and Datetime object and vector now have format methods and
12+
\code{operator<<} support (PR\ghpr{599})
1213
}
1314
\item Changes in Rcpp unit tests
1415
\itemize{

inst/include/Rcpp/date_datetime/newDateVector.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,24 @@ namespace Rcpp {
5252
return *this;
5353
}
5454

55+
friend inline std::ostream &operator<<(std::ostream & s, const newDateVector d);
56+
5557
private:
5658

5759
void setClass() {
5860
Shield<SEXP> dateclass(Rf_mkString("Date"));
5961
Rf_setAttrib(*this, R_ClassSymbol, dateclass);
6062
}
6163
};
64+
65+
inline std::ostream &operator<<(std::ostream & os, const newDateVector d) {
66+
int n = d.size();
67+
for (int i=0; i<n; i++) {
68+
os << Date(d[i]).format() << " ";
69+
if ((i+1) % 8 == 0) os << "\n";
70+
}
71+
return os;
72+
}
6273
}
6374

6475
#endif

inst/include/Rcpp/date_datetime/newDatetimeVector.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ namespace Rcpp {
6161
return *this;
6262
}
6363

64+
friend inline std::ostream &operator<<(std::ostream & s, const newDatetimeVector d);
65+
6466
private:
6567

6668
void setClass(const char *tz) {
@@ -75,6 +77,16 @@ namespace Rcpp {
7577
}
7678
}
7779
};
80+
81+
inline std::ostream &operator<<(std::ostream & os, const newDatetimeVector d) {
82+
int n = d.size();
83+
for (int i=0; i<n; i++) {
84+
os << Datetime(d[i]).format() << " ";
85+
if ((i+1) % 4 == 0) os << "\n";
86+
}
87+
return os;
88+
}
89+
7890
}
7991

8092
#endif

0 commit comments

Comments
 (0)