reverting some date code
still not finished
This commit is contained in:
12
ml_date.cpp
12
ml_date.cpp
@@ -23,8 +23,7 @@ std::string date_to_string(const long datetime, const std::string format) {
|
||||
}
|
||||
|
||||
time_t time_to_epoch ( const struct tm *ltm, int utcdiff ) {
|
||||
// const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
const int mon_days [] = {31, 31+28, 31+28+31,
|
||||
const int mon_days [] = {0, 31, 31+28, 31+28+31,
|
||||
31+28+31+30, 31+28+31+30+31, 31+28+31+30+31+30,
|
||||
31+28+31+30+31+30+31, 31+28+31+30+31+30+31+31, 31+28+31+30+31+30+31+31+30,
|
||||
31+28+31+30+31+30+31+31+30+31, 31+28+31+30+31+30+31+31+30+31+30, 31+28+31+30+31+30+31+31+30+31+30+31};
|
||||
@@ -38,8 +37,9 @@ time_t time_to_epoch ( const struct tm *ltm, int utcdiff ) {
|
||||
//leaps -= ( (i/4)*3 + i%4 );
|
||||
|
||||
// tdays = 0;
|
||||
// const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
// for (i=0; i < ltm->tm_mon; i++) tdays += mon_days[i];
|
||||
tdays = mon_days[ltm->tm_mon-1];
|
||||
tdays = mon_days[ltm->tm_mon];
|
||||
|
||||
tdays += ltm->tm_mday-1; // days of month passed.
|
||||
tdays = tdays + (tyears * 365) + leaps;
|
||||
@@ -67,10 +67,12 @@ long string_to_date(const std::string &datestr, const std::string &format) {
|
||||
timeinfo->tm_min = tm.tm_min;
|
||||
timeinfo->tm_sec = tm.tm_sec;
|
||||
|
||||
return time_to_epoch(timeinfo, -1 * timeinfo->tm_gmtoff);
|
||||
int offset = -1 * timeinfo->tm_gmtoff; // for local time
|
||||
//int offset = 0;
|
||||
return time_to_epoch(timeinfo, offset);
|
||||
}
|
||||
|
||||
throw std::runtime_error("string_to_date invalid date string or format");
|
||||
throw std::runtime_error("invalid date string or format (" + datestr + ", " + format + ")" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user