Rcpp Version 1.0.9
Datetime.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_Datetime_h
21 #define Rcpp_api_meat_Datetime_h
22 
23 namespace Rcpp {
24 
25  inline Datetime::Datetime(SEXP d) {
26  m_dt = Rcpp::as<double>(d);
27  update_tm();
28  }
29 
30  inline Datetime::Datetime(const std::string &s, const std::string &fmt) {
31  Rcpp::Function strptime("strptime"); // we cheat and call strptime() from R
32  Rcpp::Function asPOSIXct("as.POSIXct"); // and we need to convert to POSIXct
33  m_dt = Rcpp::as<double>(asPOSIXct(strptime(s, fmt)));
34  update_tm();
35  }
36 
37  template<>
38  inline SEXP wrap_extra_steps<Rcpp::Datetime>(SEXP x) {
39  Rf_setAttrib(x, R_ClassSymbol, internal::getPosixClasses());
40  return x;
41  }
42 
43  template <>
44  inline SEXP wrap<Datetime>(const Datetime &date) {
46  }
47 
48 }
49 
50 #endif
double m_dt
Definition: Datetime.h:95
double getFractionalTimestamp(void) const
Definition: Datetime.h:48
void update_tm()
Definition: Datetime.h:100
SEXP new_posixt_object(double d)
Definition: Date.h:186
SEXP getPosixClasses()
Definition: Date.h:179
Rcpp API.
Definition: algo.h:28
Function_Impl< PreserveStorage > Function
Definition: Function.h:122
SEXP wrap< Datetime >(const Datetime &date)
Definition: Datetime.h:44