- fixed GH# 116: Wrong timezone parsing in DateTimeParse (fix by Matej Knopp)

This commit is contained in:
Guenter Obiltschnig
2013-03-06 07:50:02 +01:00
parent 3c7bae11fc
commit dc5c8c87da
2 changed files with 19 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
// //
// DateTimeParser.cpp // DateTimeParser.cpp
// //
// $Id: //poco/1.4/Foundation/src/DateTimeParser.cpp#4 $ // $Id: //poco/1.4/Foundation/src/DateTimeParser.cpp#5 $
// //
// Library: Foundation // Library: Foundation
// Package: DateTime // Package: DateTime
@@ -304,6 +304,7 @@ int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string:
{"AWDT", 9*3600} {"AWDT", 9*3600}
}; };
int tzd = 0;
while (it != end && Ascii::isSpace(*it)) ++it; while (it != end && Ascii::isSpace(*it)) ++it;
if (it != end) 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) for (unsigned i = 0; i < sizeof(zones)/sizeof(Zone); ++i)
{ {
if (designator == zones[i].designator) 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; int sign = *it == '+' ? 1 : -1;
++it; ++it;
@@ -329,10 +333,10 @@ int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string:
if (it != end && *it == ':') ++it; if (it != end && *it == ':') ++it;
int minutes = 0; int minutes = 0;
PARSE_NUMBER_N(minutes, 2); PARSE_NUMBER_N(minutes, 2);
return sign*(hours*3600 + minutes*60); tzd += sign*(hours*3600 + minutes*60);
} }
} }
return 0; return tzd;
} }

View File

@@ -1,7 +1,7 @@
// //
// DateTimeParserTest.cpp // 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. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -341,6 +341,15 @@ void DateTimeParserTest::testRFC1123()
assert (dt.minute() == 17); assert (dt.minute() == 17);
assert (dt.second() == 30); assert (dt.second() == 30);
assert (tzd == -14400); 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);
} }