mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 03:20:11 +01:00
fixed SF# 2804546
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// DateTimeParser.h
|
// DateTimeParser.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/DateTimeParser.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/DateTimeParser.h#4 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: DateTime
|
// Package: DateTime
|
||||||
@@ -61,6 +61,12 @@ class Foundation_API DateTimeParser
|
|||||||
/// Note: When parsing a time in 12-hour (AM/PM) format, the hour
|
/// Note: When parsing a time in 12-hour (AM/PM) format, the hour
|
||||||
/// (%h) must be parsed before the AM/PM designator (%a, %A),
|
/// (%h) must be parsed before the AM/PM designator (%a, %A),
|
||||||
/// otherwise the AM/PM designator will be ignored.
|
/// otherwise the AM/PM designator will be ignored.
|
||||||
|
///
|
||||||
|
/// See the DateTimeFormatter class for a list of supported format specifiers.
|
||||||
|
/// In addition to the format specifiers supported by DateTimeFormatter, an
|
||||||
|
/// additional specifier is supported: %r will parse a year given by either
|
||||||
|
/// two or four digits. Years 69-00 are interpreted in the 20th century
|
||||||
|
/// (1969-2000), years 01-68 in the 21th century (2001-2068).
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void parse(const std::string& fmt, const std::string& str, DateTime& dateTime, int& timeZoneDifferential);
|
static void parse(const std::string& fmt, const std::string& str, DateTime& dateTime, int& timeZoneDifferential);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// DateTimeParser.cpp
|
// DateTimeParser.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/src/DateTimeParser.cpp#19 $
|
// $Id: //poco/Main/Foundation/src/DateTimeParser.cpp#20 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: DateTime
|
// Package: DateTime
|
||||||
@@ -105,7 +105,7 @@ void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateT
|
|||||||
case 'y':
|
case 'y':
|
||||||
SKIP_JUNK();
|
SKIP_JUNK();
|
||||||
PARSE_NUMBER_N(year, 2);
|
PARSE_NUMBER_N(year, 2);
|
||||||
if (year >= 70)
|
if (year >= 69)
|
||||||
year += 1900;
|
year += 1900;
|
||||||
else
|
else
|
||||||
year += 2000;
|
year += 2000;
|
||||||
@@ -114,6 +114,17 @@ void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateT
|
|||||||
SKIP_JUNK();
|
SKIP_JUNK();
|
||||||
PARSE_NUMBER_N(year, 4);
|
PARSE_NUMBER_N(year, 4);
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
SKIP_JUNK();
|
||||||
|
PARSE_NUMBER(year);
|
||||||
|
if (year < 1000)
|
||||||
|
{
|
||||||
|
if (year >= 69)
|
||||||
|
year += 1900;
|
||||||
|
else
|
||||||
|
year += 2000;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
case 'h':
|
case 'h':
|
||||||
SKIP_JUNK();
|
SKIP_JUNK();
|
||||||
@@ -209,11 +220,11 @@ bool DateTimeParser::tryParse(const std::string& str, DateTime& dateTime, int& t
|
|||||||
if (str.length() < 4) return false;
|
if (str.length() < 4) return false;
|
||||||
|
|
||||||
if (str[3] == ',')
|
if (str[3] == ',')
|
||||||
return tryParse(DateTimeFormat::RFC822_FORMAT, str, dateTime, timeZoneDifferential);
|
return tryParse("%w, %e %b %r %H:%M:%S %Z", str, dateTime, timeZoneDifferential);
|
||||||
else if (str[3] == ' ')
|
else if (str[3] == ' ')
|
||||||
return tryParse(DateTimeFormat::ASCTIME_FORMAT, str, dateTime, timeZoneDifferential);
|
return tryParse(DateTimeFormat::ASCTIME_FORMAT, str, dateTime, timeZoneDifferential);
|
||||||
else if (str.find(',') != std::string::npos)
|
else if (str.find(',') != std::string::npos)
|
||||||
return tryParse(DateTimeFormat::RFC850_FORMAT, str, dateTime, timeZoneDifferential);
|
return tryParse("%W, %e %b %r %H:%M:%S %Z", str, dateTime, timeZoneDifferential);
|
||||||
else if (std::isdigit(str[0]))
|
else if (std::isdigit(str[0]))
|
||||||
{
|
{
|
||||||
if (str.find(' ') != std::string::npos || str.length() == 10)
|
if (str.find(' ') != std::string::npos || str.length() == 10)
|
||||||
@@ -306,7 +317,7 @@ int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string:
|
|||||||
int DateTimeParser::parseMonth(std::string::const_iterator& it, const std::string::const_iterator& end)
|
int DateTimeParser::parseMonth(std::string::const_iterator& it, const std::string::const_iterator& end)
|
||||||
{
|
{
|
||||||
std::string month;
|
std::string month;
|
||||||
while (it != end && std::isspace(*it) || std::ispunct(*it)) ++it;
|
while ((it != end && std::isspace(*it)) || std::ispunct(*it)) ++it;
|
||||||
bool isFirst = true;
|
bool isFirst = true;
|
||||||
while (it != end && std::isalpha(*it))
|
while (it != end && std::isalpha(*it))
|
||||||
{
|
{
|
||||||
@@ -327,7 +338,7 @@ int DateTimeParser::parseMonth(std::string::const_iterator& it, const std::strin
|
|||||||
int DateTimeParser::parseDayOfWeek(std::string::const_iterator& it, const std::string::const_iterator& end)
|
int DateTimeParser::parseDayOfWeek(std::string::const_iterator& it, const std::string::const_iterator& end)
|
||||||
{
|
{
|
||||||
std::string dow;
|
std::string dow;
|
||||||
while (it != end && std::isspace(*it) || std::ispunct(*it)) ++it;
|
while ((it != end && std::isspace(*it)) || std::ispunct(*it)) ++it;
|
||||||
bool isFirst = true;
|
bool isFirst = true;
|
||||||
while (it != end && std::isalpha(*it))
|
while (it != end && std::isalpha(*it))
|
||||||
{
|
{
|
||||||
@@ -348,7 +359,7 @@ int DateTimeParser::parseDayOfWeek(std::string::const_iterator& it, const std::s
|
|||||||
int DateTimeParser::parseAMPM(std::string::const_iterator& it, const std::string::const_iterator& end, int hour)
|
int DateTimeParser::parseAMPM(std::string::const_iterator& it, const std::string::const_iterator& end, int hour)
|
||||||
{
|
{
|
||||||
std::string ampm;
|
std::string ampm;
|
||||||
while (it != end && std::isspace(*it) || std::ispunct(*it)) ++it;
|
while ((it != end && std::isspace(*it)) || std::ispunct(*it)) ++it;
|
||||||
while (it != end && std::isalpha(*it))
|
while (it != end && std::isalpha(*it))
|
||||||
{
|
{
|
||||||
char ch = (*it++);
|
char ch = (*it++);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// DateTimeParserTest.cpp
|
// DateTimeParserTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/testsuite/src/DateTimeParserTest.cpp#2 $
|
// $Id: //poco/Main/Foundation/testsuite/src/DateTimeParserTest.cpp#12 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@@ -402,6 +402,15 @@ void DateTimeParserTest::testGuess()
|
|||||||
assert (dt.minute() == 30);
|
assert (dt.minute() == 30);
|
||||||
assert (dt.second() == 0);
|
assert (dt.second() == 0);
|
||||||
assert (tzd == 3600);
|
assert (tzd == 3600);
|
||||||
|
|
||||||
|
dt = DateTimeParser::parse("Sat, 8 Jan 2005 12:30:00 +0100", tzd);
|
||||||
|
assert (dt.year() == 2005);
|
||||||
|
assert (dt.month() == 1);
|
||||||
|
assert (dt.day() == 8);
|
||||||
|
assert (dt.hour() == 12);
|
||||||
|
assert (dt.minute() == 30);
|
||||||
|
assert (dt.second() == 0);
|
||||||
|
assert (tzd == 3600);
|
||||||
|
|
||||||
dt = DateTimeParser::parse("Sat Jan 8 12:30:00 2005", tzd);
|
dt = DateTimeParser::parse("Sat Jan 8 12:30:00 2005", tzd);
|
||||||
assert (dt.year() == 2005);
|
assert (dt.year() == 2005);
|
||||||
|
|||||||
Reference in New Issue
Block a user