Rcpp Version 1.0.9
Date.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
4 //
5 // This file is part of Rcpp.
6 //
7 // Rcpp is free software: you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // Rcpp is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19 
20 #ifndef Rcpp_api_meat_Date_h
21 #define Rcpp_api_meat_Date_h
22 
23 namespace Rcpp{
24 
25  inline Date::Date(SEXP d) {
26  m_d = Rcpp::as<double>(d);
27  update_tm();
28  }
29 
30  inline Date::Date(const std::string &s, const std::string &fmt) {
31  Function strptime("strptime"); // we cheat and call strptime() from R
32  Function asDate("as.Date"); // and we need to convert to Date
33  m_d = Rcpp::as<int>(asDate(strptime(s, fmt, "UTC")));
34  update_tm();
35  }
36 
37  template <>
38  inline SEXP wrap(const Date &date) {
39  return internal::new_date_object(date.getDate());
40  }
41 
42 }
43 
44 #endif
Date()
Definition: Date.h:33
double m_d
Definition: Date.h:122
void update_tm()
Definition: Date.h:126
double getDate(void) const
Definition: Date.h:70
SEXP new_date_object(double d)
Definition: Date.h:192
Rcpp API.
Definition: algo.h:28
Function_Impl< PreserveStorage > Function
Definition: Function.h:122
SEXP wrap(const Date &date)
Definition: Date.h:38