Rcpp Version 1.0.14
Loading...
Searching...
No Matches
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
) {
45
return
internal::new_posixt_object
(
date
.getFractionalTimestamp());
46
}
47
48
}
49
50
#endif
Rcpp::Datetime
Definition
Datetime.h:33
Rcpp::Datetime::m_dt
double m_dt
Definition
Datetime.h:95
Rcpp::Datetime::Datetime
Datetime()
Definition
Datetime.h:35
Rcpp::Datetime::update_tm
void update_tm()
Definition
Datetime.h:100
Rcpp::internal::new_posixt_object
SEXP new_posixt_object(double d)
Definition
Date.h:186
Rcpp::internal::getPosixClasses
SEXP getPosixClasses()
Definition
Date.h:179
Rcpp
Rcpp API.
Definition
algo.h:28
Rcpp::Function
Function_Impl< PreserveStorage > Function
Definition
Function.h:131
Rcpp::as
T as(SEXP x)
Definition
as.h:151
Rcpp::wrap< Datetime >
SEXP wrap< Datetime >(const Datetime &date)
Definition
Datetime.h:44
Rcpp::wrap_extra_steps< Rcpp::Datetime >
SEXP wrap_extra_steps< Rcpp::Datetime >(SEXP)
Definition
Datetime.h:38
inst
include
Rcpp
api
meat
Datetime.h
Generated on Sun Jan 12 2025 11:21:42 for Rcpp Version 1.0.14 by
1.9.8