Skip to content

Commit d41a48d

Browse files
committed
corrections to operator<<() for Date(time)
now it even works. the amazement.
1 parent 08a2cff commit d41a48d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

inst/include/Rcpp/date_datetime/Date.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ namespace Rcpp {
110110
return std::string(txt);
111111
}
112112

113-
inline std::ostream &operator<<(std::ostream & s) const {
114-
s << this->format() << std::endl;
115-
return s;
116-
}
117-
113+
friend inline std::ostream &operator<<(std::ostream & os, const Date d);
118114

119115
private:
120116
double m_d; // (fractional) day number, relative to epoch of Jan 1, 1970
@@ -167,6 +163,11 @@ namespace Rcpp {
167163
inline bool operator<=(const Date &d1, const Date& d2) { return d1.m_d <= d2.m_d; }
168164
inline bool operator!=(const Date &d1, const Date& d2) { return d1.m_d != d2.m_d; }
169165

166+
inline std::ostream &operator<<(std::ostream & os, const Date d) {
167+
os << d.format();
168+
return os;
169+
}
170+
170171
namespace internal {
171172

172173
inline SEXP getPosixClasses() {

inst/include/Rcpp/date_datetime/Datetime.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ namespace Rcpp {
7777
return std::string(txtsec);
7878
}
7979

80-
inline std::ostream &operator<<(std::ostream & s) const {
81-
s << this->format() << std::endl;
82-
return s;
83-
}
80+
friend inline std::ostream &operator<<(std::ostream & s, const Datetime d);
8481

8582
private:
8683
double m_dt; // fractional seconds since epoch
@@ -151,6 +148,10 @@ namespace Rcpp {
151148
inline bool operator<=(const Datetime &d1, const Datetime& d2) { return d1.m_dt <= d2.m_dt; }
152149
inline bool operator!=(const Datetime &d1, const Datetime& d2) { return d1.m_dt != d2.m_dt; }
153150

151+
inline std::ostream &operator<<(std::ostream & os, const Datetime d) {
152+
os << d.format();
153+
return os;
154+
}
154155

155156
}
156157

0 commit comments

Comments
 (0)