New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce -Wconversion warnings for date-time code #687

Merged
merged 2 commits into from May 5, 2017
Jump to file or symbol
Failed to load files and symbols.
+21 −18
Diff settings

Always

Just for now

Next

Reduce -Wconversion warnings for date-time code

  • Loading branch information...
krlmlr committed May 5, 2017
commit a7c18e4f951b7d9a31740014329b41cf2a625dfd
@@ -110,7 +110,7 @@ namespace Rcpp {
char txt[32];
struct tm temp = m_tm;
temp.tm_year -= baseYear(); // adjust for fact that system has year rel. to 1900
int res = ::strftime(txt, 31, fmt, &temp);
size_t res = ::strftime(txt, 31, fmt, &temp);
if (res == 0) {
return std::string("");
} else {
@@ -127,7 +127,7 @@ namespace Rcpp {
// update m_tm based on m_d
void update_tm() {
if (R_FINITE(m_d)) {
time_t t = 24*60*60 * m_d; // (fractional) days since epoch to seconds since epoch
time_t t = (time_t)(24*60*60 * m_d); // (fractional) days since epoch to seconds since epoch

This comment has been minimized.

@coatless

coatless May 5, 2017

Contributor

I think you may need to use a static_cast<time_t>() in place of the c-style / regular cast.

@coatless

coatless May 5, 2017

Contributor

I think you may need to use a static_cast<time_t>() in place of the c-style / regular cast.

m_tm = *gmtime_(&t);
} else {
m_tm.tm_sec = m_tm.tm_min = m_tm.tm_hour = m_tm.tm_isdst = NA_INTEGER;
@@ -158,7 +158,7 @@ namespace Rcpp {
inline Date operator+(const Date &date, int offset) {
Date newdate(date.m_d);
newdate.m_d += offset;
time_t t = 24*60*60 * newdate.m_d; // days since epoch to seconds since epo
time_t t = (time_t)(24*60*60 * newdate.m_d); // days since epoch to seconds since epo
newdate.m_tm = *gmtime_(&t);
return newdate;
}
@@ -76,7 +76,7 @@ namespace Rcpp {
char txtiso[64], txtsec[64];
time_t t = static_cast<time_t>(std::floor(m_dt));
struct tm temp = *localtime(&t); // localtime, not gmtime
int res = ::strftime(txtiso, 63, fmt, &temp);
size_t res = ::strftime(txtiso, 63, fmt, &temp);
if (res == 0) {
return std::string("");
} else {
@@ -99,10 +99,11 @@ namespace Rcpp {
// update m_tm based on m_dt
void update_tm() {
if (R_FINITE(m_dt)) {
time_t t = static_cast<time_t>(std::floor(m_dt));
double dt = std::floor(m_dt);
time_t t = static_cast<time_t>(dt);
m_tm = *gmtime_(&t);
// m_us is fractional (micro)secs as diff. between (fractional) m_dt and m_tm
m_us = static_cast<int>(::Rf_fround( (m_dt - t) * 1.0e6, 0.0));
m_us = static_cast<int>(::Rf_fround( (m_dt - dt) * 1.0e6, 0.0));
} else {
m_dt = NA_REAL; // NaN and Inf need it set
m_tm.tm_sec = m_tm.tm_min = m_tm.tm_hour = m_tm.tm_isdst = NA_INTEGER;
@@ -137,18 +138,20 @@ namespace Rcpp {
inline Datetime operator+(const Datetime &datetime, double offset) {
Datetime newdt(datetime.m_dt);
newdt.m_dt += offset;
time_t t = static_cast<time_t>(std::floor(newdt.m_dt));
double dt = std::floor(newdt.m_dt);
time_t t = static_cast<time_t>(dt);
newdt.m_tm = *gmtime_(&t);
newdt.m_us = static_cast<int>(::Rf_fround( (newdt.m_dt - t) * 1.0e6, 0.0));
newdt.m_us = static_cast<int>(::Rf_fround( (newdt.m_dt - dt) * 1.0e6, 0.0));
return newdt;
}
inline Datetime operator+(const Datetime &datetime, int offset) {
Datetime newdt(datetime.m_dt);
newdt.m_dt += offset;
time_t t = static_cast<time_t>(std::floor(newdt.m_dt));
double dt = std::floor(newdt.m_dt);
time_t t = static_cast<time_t>(dt);
newdt.m_tm = *gmtime_(&t);
newdt.m_us = static_cast<int>(::Rf_fround( (newdt.m_dt - t) * 1.0e6, 0.0));
newdt.m_us = static_cast<int>(::Rf_fround( (newdt.m_dt - dt) * 1.0e6, 0.0));
return newdt;
}
@@ -37,9 +37,9 @@ namespace Rcpp {
newDateVector(int n) : NumericVector(n) { setClass(); }
inline std::vector<Date> getDates() const {
int n = this->size();
size_t n = this->size();
std::vector<Date> v(n);
for (int i=0; i<n; i++)
for (size_t i=0; i<n; i++)
v[i] = (*this)[i];
return v;
}
@@ -63,8 +63,8 @@ namespace Rcpp {
};
inline std::ostream &operator<<(std::ostream & os, const newDateVector d) {
int n = d.size();
for (int i=0; i<n; i++) {
size_t n = d.size();
for (size_t i=0; i<n; i++) {
os << Date(d[i]).format() << " ";
if ((i+1) % 8 == 0) os << "\n";
}
@@ -45,9 +45,9 @@ namespace Rcpp {
}
inline std::vector<Datetime> getDatetimes() const {
int n = this->size();
size_t n = this->size();
std::vector<Datetime> v(n);
for (int i=0; i<n; i++)
for (size_t i=0; i<n; i++)
v[i] = (*this)[i];
return v;
}
@@ -79,8 +79,8 @@ namespace Rcpp {
};
inline std::ostream &operator<<(std::ostream & os, const newDatetimeVector d) {
int n = d.size();
for (int i=0; i<n; i++) {
size_t n = d.size();
for (size_t i=0; i<n; i++) {
os << Datetime(d[i]).format() << " ";
if ((i+1) % 4 == 0) os << "\n";
}
ProTip! Use n and p to navigate between commits in a pull request.