|
2 | 2 | //
|
3 | 3 | // Datetime.h: Rcpp R/C++ interface class library -- Datetime (POSIXct)
|
4 | 4 | //
|
5 |
| -// Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois |
6 | 6 | //
|
7 | 7 | // This file is part of Rcpp.
|
8 | 8 | //
|
@@ -55,6 +55,7 @@ namespace Rcpp {
|
55 | 55 |
|
56 | 56 | // Minimal set of date operations.
|
57 | 57 | friend Datetime operator+( const Datetime &dt, double offset);
|
| 58 | + friend Datetime operator+( const Datetime &dt, int offset); |
58 | 59 | friend double operator-( const Datetime &dt1, const Datetime& dt2);
|
59 | 60 | friend bool operator<( const Datetime &dt1, const Datetime& dt2);
|
60 | 61 | friend bool operator>( const Datetime &dt1, const Datetime& dt2);
|
@@ -114,6 +115,15 @@ namespace Rcpp {
|
114 | 115 | return newdt;
|
115 | 116 | }
|
116 | 117 |
|
| 118 | + inline Datetime operator+(const Datetime &datetime, int offset) { |
| 119 | + Datetime newdt(datetime.m_dt); |
| 120 | + newdt.m_dt += offset; |
| 121 | + time_t t = static_cast<time_t>(std::floor(newdt.m_dt)); |
| 122 | + newdt.m_tm = *gmtime_(&t); |
| 123 | + newdt.m_us = static_cast<int>(::Rf_fround( (newdt.m_dt - t) * 1.0e6, 0.0)); |
| 124 | + return newdt; |
| 125 | + } |
| 126 | + |
117 | 127 | inline double operator-(const Datetime& d1, const Datetime& d2) { return d1.m_dt - d2.m_dt; }
|
118 | 128 | inline bool operator<(const Datetime &d1, const Datetime& d2) { return d1.m_dt < d2.m_dt; }
|
119 | 129 | inline bool operator>(const Datetime &d1, const Datetime& d2) { return d1.m_dt > d2.m_dt; }
|
|
0 commit comments