1
- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1
+ // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2
2
//
3
3
// Date.h: Rcpp R/C++ interface class library -- dates
4
4
//
5
- // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
5
+ // Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
6
6
//
7
7
// This file is part of Rcpp.
8
8
//
@@ -55,28 +55,28 @@ namespace Rcpp {
55
55
m_tm.tm_mday = year;
56
56
} else {
57
57
m_tm.tm_mday = day;
58
- m_tm.tm_mon = mon - 1 ; // range 0 to 11
58
+ m_tm.tm_mon = mon - 1 ; // range 0 to 11
59
59
m_tm.tm_year = year - baseYear ();
60
60
}
61
- double tmp = mktime00 (m_tm); // use mktime() replacement borrowed from R
62
- m_tm.tm_year += baseYear () ; // we'd rather keep it as a normal year
61
+ double tmp = mktime00 (m_tm); // use mktime() replacement borrowed from R
62
+ m_tm.tm_year += baseYear () ; // we'd rather keep it as a normal year
63
63
m_d = tmp/(24 *60 *60 );
64
64
}
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; }
74
74
// int getMinutes() const { return m_tm.tm_min; }
75
75
// int getHours() const { return m_tm.tm_hour; }
76
76
int getDay () const { return m_tm.tm_mday ; }
77
- int getMonth () const { return m_tm.tm_mon + 1 ; } // makes it 1 .. 12
78
- int getYear () const { return m_tm.tm_year ; } // does include 1900 (see Date.cpp)
79
- int getWeekday () const { return m_tm.tm_wday + 1 ; } // makes it 1 .. 7
77
+ int getMonth () const { return m_tm.tm_mon + 1 ; } // makes it 1 .. 12
78
+ int getYear () const { return m_tm.tm_year ; } // does include 1900 (see Date.cpp)
79
+ int getWeekday () const { return m_tm.tm_wday + 1 ; } // makes it 1 .. 7
80
80
int getYearday () const { return m_tm.tm_yday + 1 ; } // makes it 1 .. 366
81
81
82
82
// 1900 as per POSIX mktime() et al
@@ -99,13 +99,13 @@ namespace Rcpp {
99
99
}
100
100
101
101
private:
102
- double m_d; // (fractional) day number, relative to epoch of Jan 1, 1970
103
- struct tm m_tm; // standard time representation
102
+ double m_d; // (fractional) day number, relative to epoch of Jan 1, 1970
103
+ struct tm m_tm; // standard time representation
104
104
105
105
// update m_tm based on m_d
106
106
void update_tm (){
107
107
if (R_FINITE (m_d)) {
108
- time_t t = 24 *60 *60 * m_d; // (fractional) days since epoch to seconds since epoch
108
+ time_t t = 24 *60 *60 * m_d; // (fractional) days since epoch to seconds since epoch
109
109
m_tm = *gmtime_ (&t);
110
110
} else {
111
111
m_tm.tm_sec = m_tm.tm_min = m_tm.tm_hour = m_tm.tm_isdst = NA_INTEGER;
@@ -120,12 +120,12 @@ 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){
124
- return static_cast <double >( from.getDate () ) ;
125
- }
126
- template <> inline Rcpp::Date caster<double ,Rcpp::Date>( double from){
127
- return Rcpp::Date ( static_cast <int >( from ) ) ;
128
- }
123
+ template <> inline double caster<Rcpp::Date,double >( Rcpp::Date from){
124
+ return static_cast <double >( from.getDate () ) ;
125
+ }
126
+ template <> inline Rcpp::Date caster<double ,Rcpp::Date>( double from){
127
+ return Rcpp::Date ( static_cast <int >( from ) ) ;
128
+ }
129
129
}
130
130
131
131
template <> inline SEXP wrap_extra_steps<Rcpp::Date>( SEXP x ){
@@ -136,7 +136,7 @@ namespace Rcpp {
136
136
inline Date operator +(const Date &date, int offset) {
137
137
Date newdate (date.m_d );
138
138
newdate.m_d += offset;
139
- time_t t = 24 *60 *60 * newdate.m_d ; // days since epoch to seconds since epo
139
+ time_t t = 24 *60 *60 * newdate.m_d ; // days since epoch to seconds since epo
140
140
newdate.m_tm = *gmtime_ (&t);
141
141
return newdate;
142
142
}
0 commit comments