22 #ifndef Rcpp__Datetime_h
23 #define Rcpp__Datetime_h
27 #if defined(WIN32) || defined(__WIN32) || defined(__WIN32__)
46 Datetime(
const std::string &s,
const std::string &fmt=
"%Y-%m-%d %H:%M:%OS");
73 operator double()
const {
return m_dt; }
75 inline std::string
format(
const char *fmt =
"%Y-%m-%d %H:%M:%S")
const {
76 char txtiso[64], txtsec[64];
77 time_t t =
static_cast<time_t
>(std::floor(
m_dt));
78 struct tm temp = *localtime(&t);
79 size_t res = ::strftime(txtiso, 63, fmt, &temp);
81 return std::string(
"");
83 res = ::snprintf(txtsec, 63,
"%s.%06d", txtiso,
m_us);
85 return std::string(
"");
87 return std::string(txtsec);
101 if (R_FINITE(
m_dt)) {
102 double dt = std::floor(
m_dt);
103 time_t t =
static_cast<time_t
>(
dt);
106 m_us =
static_cast<int>(::Rf_fround( (
m_dt -
dt) * 1.0e6, 0.0));
136 template<> SEXP wrap_extra_steps<Rcpp::Datetime>(SEXP x);
140 newdt.
m_dt += offset;
141 double dt = std::floor(newdt.
m_dt);
142 time_t t =
static_cast<time_t
>(
dt);
144 newdt.
m_us =
static_cast<int>(::Rf_fround( (newdt.
m_dt -
dt) * 1.0e6, 0.0));
150 newdt.
m_dt += offset;
151 double dt = std::floor(newdt.
m_dt);
152 time_t t =
static_cast<time_t
>(
dt);
154 newdt.
m_us =
static_cast<int>(::Rf_fround( (newdt.
m_dt -
dt) * 1.0e6, 0.0));
int getMicroSeconds() const
friend bool operator>(const Datetime &dt1, const Datetime &dt2)
friend std::ostream & operator<<(std::ostream &s, const Datetime d)
friend bool operator==(const Datetime &dt1, const Datetime &dt2)
friend bool operator<=(const Datetime &dt1, const Datetime &dt2)
double getFractionalTimestamp(void) const
friend double operator-(const Datetime &dt1, const Datetime &dt2)
static unsigned int baseYear()
std::string format(const char *fmt="%Y-%m-%d %H:%M:%S") const
friend bool operator>=(const Datetime &dt1, const Datetime &dt2)
friend Datetime operator+(const Datetime &dt, double offset)
Datetime(const double &dt)
friend bool operator<(const Datetime &dt1, const Datetime &dt2)
friend bool operator!=(const Datetime &dt1, const Datetime &dt2)
double dt(double x, double n, int lg)
bool is_na< REALSXP >(double x)
bool operator>=(const Date &d1, const Date &d2)
bool operator!=(const Date &d1, const Date &d2)
double operator-(const Date &d1, const Date &d2)
bool operator>(const Date &d1, const Date &d2)
attribute_hidden struct tm * gmtime_(const time_t *const x)
std::ostream & operator<<(std::ostream &os, const Date d)
bool operator<(const Date &d1, const Date &d2)
bool operator==(const Date &d1, const Date &d2)
bool operator<=(const Date &d1, const Date &d2)
Date operator+(const Date &date, int offset)