From 2c0783785283982eb6aca246130481905a97a365 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 9 Apr 2012 00:16:09 -0400 Subject: [PATCH] Bug - Fixed bug where ISO dates were parsed and the TZ was modified, which should have no bearing on a Zulu time. --- ChangeLog | 2 ++ src/Date.cpp | 8 ++++---- src/Nibbler.cpp | 26 +++++++++----------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25572d1da..987fe7893 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,8 @@ Bugs Uli Martens). + Fixed bug where '6 months' was interpreted as 180 days, but when rendered was shown as '5 months' (thanks to Aikido Guy). + + Fixed bug where ISO dates were parsed and the TZ was modified, which should + have no bearing on a Zulu time. ------ old releases ------------------------------ diff --git a/src/Date.cpp b/src/Date.cpp index 85e6bf187..75905265d 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -131,13 +131,13 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */) if (isRelativeDate (input)) return; - // Parse an ISO date. + // Parse a formatted date. Nibbler n (input); - if (n.getDateISO (_t) && n.depleted ()) + if (n.getDate (format, _t) && n.depleted ()) return; - // Parse a formatted date. - if (n.getDate (format, _t) && n.depleted ()) + // Parse an ISO date. + if (n.getDateISO (_t) && n.depleted ()) return; // Perhaps it is an epoch date, in string form? diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index 7f7c8dc3c..77584cb84 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -694,24 +694,16 @@ bool Nibbler::getDateISO (time_t& t) // Convert to epoch. struct tm tms = {0}; - tms.tm_isdst = -1; // Requests that mktime determine summer time effect. - tms.tm_mday = day; - tms.tm_mon = month - 1; - tms.tm_year = year - 1900; - tms.tm_hour = hour; - tms.tm_min = minute; - tms.tm_sec = second; - - char *tz = getenv ("TZ"); - setenv ("TZ", "UTC", 1); - tzset (); - t = mktime (&tms); - if (tz) - setenv ("TZ", tz, 1); - else - unsetenv ("TZ"); - tzset(); + tms.tm_isdst = -1; // Requests that mktime determine summer time effect. + tms.tm_mday = day; + tms.tm_mon = month - 1; + tms.tm_year = year - 1900; + tms.tm_hour = hour; + tms.tm_min = minute; + tms.tm_sec = second; + tms.tm_gmtoff = 0; + t = timegm (&tms); return true; } }