diff --git a/ml_date.cpp b/ml_date.cpp index 046faee..163438f 100644 --- a/ml_date.cpp +++ b/ml_date.cpp @@ -14,7 +14,7 @@ std::string date_to_string(const long datetime, const std::string format) { time_t timestamp = datetime; char mbstr[128]; - if (std::strftime(mbstr, sizeof(mbstr), format.c_str(), std::localtime(×tamp))) { + if (std::strftime(mbstr, sizeof(mbstr), format.c_str(), std::gmtime(×tamp))) { std::string result = {mbstr}; return result; } @@ -32,13 +32,11 @@ time_t time_to_epoch ( const struct tm *ltm, int utcdiff ) { int i; tyears = ltm->tm_year - 70 ; // tm->tm_year is from 1900. - leaps = (tyears + 2) / 4; // no of next two lines until year 2100. + leaps = (tyears + 2) / 4; + // no of next two lines until year 2100. //i = (ltm->tm_year – 100) / 100; //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]; tdays += ltm->tm_mday-1; // days of month passed. @@ -67,8 +65,8 @@ long string_to_date(const std::string &datestr, const std::string &format) { timeinfo->tm_min = tm.tm_min; timeinfo->tm_sec = tm.tm_sec; - int offset = -1 * timeinfo->tm_gmtoff; // for local time - //int offset = 0; + // int offset = -1 * timeinfo->tm_gmtoff; // for local time + int offset = 0; return time_to_epoch(timeinfo, offset); } diff --git a/tests/test.lsp b/tests/test.lsp index ca2fdb2..2069438 100644 --- a/tests/test.lsp +++ b/tests/test.lsp @@ -100,7 +100,7 @@ (ut::define-test "result of (!= nil nil)" '(ut::assert-false (!= nil nil))) -; it is in local time +; it is not in local time (ut::define-test "result of (str-to-date \"01.01.1970\" \"%d.%m.%Y\")" '(ut::assert-equal 0 (str-to-date "01.01.1970" "%d.%m.%Y"))) (ut::define-test "result of (date-add (str-to-date \"01.01.1970\" \"%d.%m.%Y\") 1 \"day\")" '(ut::assert-equal 86400 (date-add (str-to-date "01.01.1970" "%d.%m.%Y") 1 "day")))