From dc5c8c87da95414a5c4e1b8516b225ba75dc730c Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Wed, 6 Mar 2013 07:50:02 +0100 Subject: [PATCH] - fixed GH# 116: Wrong timezone parsing in DateTimeParse (fix by Matej Knopp) --- Foundation/src/DateTimeParser.cpp | 14 +++++++++----- Foundation/testsuite/src/DateTimeParserTest.cpp | 11 ++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Foundation/src/DateTimeParser.cpp b/Foundation/src/DateTimeParser.cpp index b7a553a1a..9e923c209 100644 --- a/Foundation/src/DateTimeParser.cpp +++ b/Foundation/src/DateTimeParser.cpp @@ -1,7 +1,7 @@ // // DateTimeParser.cpp // -// $Id: //poco/1.4/Foundation/src/DateTimeParser.cpp#4 $ +// $Id: //poco/1.4/Foundation/src/DateTimeParser.cpp#5 $ // // Library: Foundation // Package: DateTime @@ -304,6 +304,7 @@ int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string: {"AWDT", 9*3600} }; + int tzd = 0; while (it != end && Ascii::isSpace(*it)) ++it; if (it != end) { @@ -317,10 +318,13 @@ int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string: for (unsigned i = 0; i < sizeof(zones)/sizeof(Zone); ++i) { if (designator == zones[i].designator) - return zones[i].timeZoneDifferential; + { + tzd = zones[i].timeZoneDifferential; + break; + } } } - else if (*it == '+' || *it == '-') + if (it != end && (*it == '+' || *it == '-')) { int sign = *it == '+' ? 1 : -1; ++it; @@ -329,10 +333,10 @@ int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string: if (it != end && *it == ':') ++it; int minutes = 0; PARSE_NUMBER_N(minutes, 2); - return sign*(hours*3600 + minutes*60); + tzd += sign*(hours*3600 + minutes*60); } } - return 0; + return tzd; } diff --git a/Foundation/testsuite/src/DateTimeParserTest.cpp b/Foundation/testsuite/src/DateTimeParserTest.cpp index 6bb706165..3ea8ce1c6 100644 --- a/Foundation/testsuite/src/DateTimeParserTest.cpp +++ b/Foundation/testsuite/src/DateTimeParserTest.cpp @@ -1,7 +1,7 @@ // // DateTimeParserTest.cpp // -// $Id: //poco/1.4/Foundation/testsuite/src/DateTimeParserTest.cpp#4 $ +// $Id: //poco/1.4/Foundation/testsuite/src/DateTimeParserTest.cpp#5 $ // // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // and Contributors. @@ -341,6 +341,15 @@ void DateTimeParserTest::testRFC1123() assert (dt.minute() == 17); assert (dt.second() == 30); assert (tzd == -14400); + + dt = DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, "Sun, 20 Jul 1969 16:17:30 GMT+01:00", tzd); + assert (dt.year() == 1969); + assert (dt.month() == 7); + assert (dt.day() == 20); + assert (dt.hour() == 16); + assert (dt.minute() == 17); + assert (dt.second() == 30); + assert (tzd == 3600); }