@@ -26,20 +26,20 @@ namespace Rcpp {
26
26
27
27
class Date {
28
28
public:
29
- Date (){
29
+ Date () {
30
30
m_d = 0 ;
31
31
update_tm ();
32
32
}
33
33
Date (SEXP s);
34
34
35
35
// from integer (with negative dates before Jan 1, 1970)
36
- Date (const int &dt){
36
+ Date (const int &dt) {
37
37
m_d = dt;
38
38
update_tm ();
39
39
}
40
40
41
41
// from fractional integer since epoch, just like R
42
- Date (const double &dt){
42
+ Date (const double &dt) {
43
43
m_d = dt;
44
44
update_tm ();
45
45
}
@@ -65,9 +65,9 @@ namespace Rcpp {
65
65
66
66
~Date () {};
67
67
68
- double getDate (void ) const {
69
- return m_d;
70
- }
68
+ double getDate (void ) const {
69
+ return m_d;
70
+ }
71
71
72
72
// intra-day useless for date class
73
73
// int getSeconds() const { return m_tm.tm_sec; }
@@ -85,25 +85,25 @@ namespace Rcpp {
85
85
}
86
86
87
87
// Minimal set of date operations.
88
- friend Date operator +(const Date &date, int offset);
89
- friend double operator -(const Date& date1, const Date& date2);
90
- friend bool operator <(const Date &date1, const Date& date2);
91
- friend bool operator >(const Date &date1, const Date& date2);
88
+ friend Date operator +( const Date &date, int offset);
89
+ friend double operator -( const Date & date1, const Date& date2);
90
+ friend bool operator <( const Date &date1, const Date& date2);
91
+ friend bool operator >( const Date &date1, const Date& date2);
92
92
friend bool operator ==(const Date &date1, const Date& date2);
93
93
friend bool operator >=(const Date &date1, const Date& date2);
94
94
friend bool operator <=(const Date &date1, const Date& date2);
95
95
friend bool operator !=(const Date &date1, const Date& date2);
96
96
97
97
inline int is_na () const {
98
- return traits::is_na<REALSXP>( m_d ) ;
98
+ return traits::is_na<REALSXP>(m_d) ;
99
99
}
100
100
101
101
private:
102
102
double m_d; // (fractional) day number, relative to epoch of Jan 1, 1970
103
103
struct tm m_tm; // standard time representation
104
104
105
105
// update m_tm based on m_d
106
- void update_tm (){
106
+ void update_tm () {
107
107
if (R_FINITE (m_d)) {
108
108
time_t t = 24 *60 *60 * m_d; // (fractional) days since epoch to seconds since epoch
109
109
m_tm = *gmtime_ (&t);
@@ -120,16 +120,16 @@ namespace Rcpp {
120
120
121
121
// needed to wrap containers of Date such as vector<Date> or map<string,Date>
122
122
namespace internal {
123
- template <> inline double caster<Rcpp::Date,double >( Rcpp::Date from){
123
+ template <> inline double caster<Rcpp::Date,double >(Rcpp::Date from) {
124
124
return static_cast <double >( from.getDate () ) ;
125
125
}
126
- template <> inline Rcpp::Date caster<double ,Rcpp::Date>( double from){
127
- return Rcpp::Date ( static_cast <int >( from ) ) ;
126
+ template <> inline Rcpp::Date caster<double ,Rcpp::Date>(double from) {
127
+ return Rcpp::Date (static_cast <int >(from)) ;
128
128
}
129
129
}
130
130
131
- template <> inline SEXP wrap_extra_steps<Rcpp::Date>( SEXP x ) {
132
- Rf_setAttrib ( x, R_ClassSymbol, Rf_mkString ( " Date" ) ) ;
131
+ template <> inline SEXP wrap_extra_steps<Rcpp::Date>(SEXP x) {
132
+ Rf_setAttrib ( x, R_ClassSymbol, Rf_mkString (" Date" )) ;
133
133
return x ;
134
134
}
135
135
@@ -141,31 +141,31 @@ namespace Rcpp {
141
141
return newdate;
142
142
}
143
143
144
- inline double operator -(const Date& d1, const Date& d2) { return d1.m_d - d2.m_d ; }
145
- inline bool operator <(const Date &d1, const Date& d2) { return d1.m_d < d2.m_d ; }
146
- inline bool operator >(const Date &d1, const Date& d2) { return d1.m_d > d2.m_d ; }
147
- inline bool operator ==(const Date &d1, const Date& d2) { return d1.m_d == d2.m_d ; }
148
- inline bool operator >=(const Date &d1, const Date& d2) { return d1.m_d >= d2.m_d ; }
149
- inline bool operator <=(const Date &d1, const Date& d2) { return d1.m_d <= d2.m_d ; }
150
- inline bool operator !=(const Date &d1, const Date& d2) { return d1.m_d != d2.m_d ; }
144
+ inline double operator -( const Date& d1, const Date& d2) { return d1.m_d - d2.m_d ; }
145
+ inline bool operator <( const Date &d1, const Date& d2) { return d1.m_d < d2.m_d ; }
146
+ inline bool operator >( const Date &d1, const Date& d2) { return d1.m_d > d2.m_d ; }
147
+ inline bool operator ==(const Date &d1, const Date& d2) { return d1.m_d == d2.m_d ; }
148
+ inline bool operator >=(const Date &d1, const Date& d2) { return d1.m_d >= d2.m_d ; }
149
+ inline bool operator <=(const Date &d1, const Date& d2) { return d1.m_d <= d2.m_d ; }
150
+ inline bool operator !=(const Date &d1, const Date& d2) { return d1.m_d != d2.m_d ; }
151
151
152
- namespace internal {
152
+ namespace internal {
153
153
154
- inline SEXP getPosixClasses (){
154
+ inline SEXP getPosixClasses () {
155
155
Shield<SEXP> datetimeclass (Rf_allocVector (STRSXP,2 ));
156
156
SET_STRING_ELT (datetimeclass, 0 , Rf_mkChar (" POSIXct" ));
157
157
SET_STRING_ELT (datetimeclass, 1 , Rf_mkChar (" POSIXt" ));
158
158
return datetimeclass ;
159
159
}
160
160
161
- inline SEXP new_posixt_object ( double d){
162
- Shield<SEXP> x ( Rf_ScalarReal ( d ) ) ;
163
- Rf_setAttrib (x, R_ClassSymbol, getPosixClasses () );
161
+ inline SEXP new_posixt_object ( double d) {
162
+ Shield<SEXP> x (Rf_ScalarReal (d)) ;
163
+ Rf_setAttrib (x, R_ClassSymbol, getPosixClasses ());
164
164
return x ;
165
165
}
166
166
167
- inline SEXP new_date_object ( double d){
168
- Shield<SEXP> x (Rf_ScalarReal ( d ) ) ;
167
+ inline SEXP new_date_object (double d) {
168
+ Shield<SEXP> x (Rf_ScalarReal (d) ) ;
169
169
Rf_setAttrib (x, R_ClassSymbol, Rf_mkString (" Date" ));
170
170
return x;
171
171
}
0 commit comments