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; -*-
22//
33// Date.h: Rcpp R/C++ interface class library -- dates
44//
5- // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
5+ // Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
66//
77// This file is part of Rcpp.
88//
@@ -55,28 +55,28 @@ namespace Rcpp {
5555 m_tm.tm_mday = year;
5656 } else {
5757 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
5959 m_tm.tm_year = year - baseYear ();
6060 }
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
6363 m_d = tmp/(24 *60 *60 );
6464 }
6565
6666 ~Date () {};
6767
68- double getDate (void ) const {
69- return m_d;
70- }
68+ double getDate (void ) const {
69+ return m_d;
70+ }
7171
7272 // intra-day useless for date class
7373 // int getSeconds() const { return m_tm.tm_sec; }
7474 // int getMinutes() const { return m_tm.tm_min; }
7575 // int getHours() const { return m_tm.tm_hour; }
7676 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
8080 int getYearday () const { return m_tm.tm_yday + 1 ; } // makes it 1 .. 366
8181
8282 // 1900 as per POSIX mktime() et al
@@ -99,13 +99,13 @@ namespace Rcpp {
9999 }
100100
101101 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
104104
105105 // update m_tm based on m_d
106106 void update_tm (){
107107 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
109109 m_tm = *gmtime_ (&t);
110110 } else {
111111 m_tm.tm_sec = m_tm.tm_min = m_tm.tm_hour = m_tm.tm_isdst = NA_INTEGER;
@@ -120,12 +120,12 @@ namespace Rcpp {
120120
121121 // needed to wrap containers of Date such as vector<Date> or map<string,Date>
122122 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+ }
129129 }
130130
131131 template <> inline SEXP wrap_extra_steps<Rcpp::Date>( SEXP x ){
@@ -136,7 +136,7 @@ namespace Rcpp {
136136 inline Date operator +(const Date &date, int offset) {
137137 Date newdate (date.m_d );
138138 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
140140 newdate.m_tm = *gmtime_ (&t);
141141 return newdate;
142142 }
0 commit comments