added %F (microseconds) support to DateTimeFormatter/PatternFormatter/DateTimeParser

This commit is contained in:
Guenter Obiltschnig
2009-03-06 07:15:23 +00:00
parent b0bbfb5554
commit 4ca6562afb
5 changed files with 19 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
//
// DateTimeFormatter.h
//
// $Id: //poco/Main/Foundation/include/Poco/DateTimeFormatter.h#3 $
// $Id: //poco/Main/Foundation/include/Poco/DateTimeFormatter.h#4 $
//
// Library: Foundation
// Package: DateTime
@@ -94,6 +94,7 @@ public:
/// * %S - second (00 .. 59)
/// * %i - millisecond (000 .. 999)
/// * %c - centisecond (0 .. 9)
/// * %F - fractional seconds/microseconds (000000 - 999999)
/// * %z - time zone differential in ISO 8601 format (Z or +NN.NN).
/// * %Z - time zone differential in RFC format (GMT or +NNNN)
/// * %% - percent sign
@@ -123,6 +124,7 @@ public:
/// * %s - total seconds (0 .. n)
/// * %i - milliseconds (000 .. 999)
/// * %c - centisecond (0 .. 9)
/// * %F - fractional seconds/microseconds (000000 - 999999)
/// * %% - percent sign
static void append(std::string& str, const Timestamp& timestamp, const std::string& fmt, int timeZoneDifferential = UTC);

View File

@@ -1,7 +1,7 @@
//
// PatternFormatter.h
//
// $Id: //poco/svn/Foundation/include/Poco/PatternFormatter.h#3 $
// $Id: //poco/Main/Foundation/include/Poco/PatternFormatter.h#4 $
//
// Library: Foundation
// Package: Logging
@@ -85,6 +85,7 @@ class Foundation_API PatternFormatter: public Formatter
/// * %S - message date/time second (00 .. 59)
/// * %i - message date/time millisecond (000 .. 999)
/// * %c - message date/time centisecond (0 .. 9)
/// * %F - message date/time fractional seconds/microseconds (000000 - 999999)
/// * %z - time zone differential in ISO 8601 format (Z or +NN.NN).
/// * %Z - time zone differential in RFC format (GMT or +NNNN)
/// * %[name] - the value of the message parameter with the given name

View File

@@ -1,7 +1,7 @@
//
// DateTimeFormatter.cpp
//
// $Id: //poco/Main/Foundation/src/DateTimeFormatter.cpp#13 $
// $Id: //poco/Main/Foundation/src/DateTimeFormatter.cpp#14 $
//
// Library: Foundation
// Package: DateTime
@@ -75,6 +75,7 @@ void DateTimeFormatter::append(std::string& str, const DateTime& dateTime, const
case 'S': NumberFormatter::append0(str, dateTime.second(), 2); break;
case 'i': NumberFormatter::append0(str, dateTime.millisecond(), 3); break;
case 'c': NumberFormatter::append(str, dateTime.millisecond()/100); break;
case 'F': NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6); break;
case 'z': tzdISO(str, timeZoneDifferential); break;
case 'Z': tzdRFC(str, timeZoneDifferential); break;
default: str += *it;
@@ -108,6 +109,7 @@ void DateTimeFormatter::append(std::string& str, const Timespan& timespan, const
case 's': NumberFormatter::append(str, timespan.totalSeconds()); break;
case 'i': NumberFormatter::append0(str, timespan.milliseconds(), 3); break;
case 'c': NumberFormatter::append(str, timespan.milliseconds()/100); break;
case 'F': NumberFormatter::append0(str, timespan.milliseconds()*1000 + timespan.microseconds(), 6); break;
default: str += *it;
}
++it;

View File

@@ -1,7 +1,7 @@
//
// DateTimeParser.cpp
//
// $Id: //poco/Main/Foundation/src/DateTimeParser.cpp#18 $
// $Id: //poco/Main/Foundation/src/DateTimeParser.cpp#19 $
//
// Library: Foundation
// Package: DateTime
@@ -65,6 +65,7 @@ void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateT
int minute = 0;
int second = 0;
int millis = 0;
int micros = 0;
int tzd = 0;
std::string::const_iterator it = str.begin();
@@ -139,6 +140,11 @@ void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateT
PARSE_NUMBER_N(millis, 1);
millis *= 100;
break;
case 'F':
SKIP_JUNK();
PARSE_NUMBER_N(millis, 3);
PARSE_NUMBER_N(micros, 3);
break;
case 'z':
case 'Z':
tzd = parseTZD(it, end);
@@ -151,8 +157,8 @@ void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateT
}
if (month == 0) month = 1;
if (day == 0) day = 1;
if (DateTime::isValid(year, month, day, hour, minute, second, millis))
dateTime.assign(year, month, day, hour, minute, second, millis);
if (DateTime::isValid(year, month, day, hour, minute, second, millis, micros))
dateTime.assign(year, month, day, hour, minute, second, millis, micros);
else
throw SyntaxException("date/time component out of range");
timeZoneDifferential = tzd;

View File

@@ -1,7 +1,7 @@
//
// PatternFormatter.cpp
//
// $Id: //poco/svn/Foundation/src/PatternFormatter.cpp#3 $
// $Id: //poco/Main/Foundation/src/PatternFormatter.cpp#16 $
//
// Library: Foundation
// Package: Logging
@@ -143,6 +143,7 @@ void PatternFormatter::format(const Message& msg, std::string& text)
case 'S': fmt0(text, dateTime.second(), 2); break;
case 'i': fmt0(text, dateTime.millisecond(), 3); break;
case 'c': fmt(text, dateTime.millisecond()/100); break;
case 'F': fmt0(text, dateTime.millisecond()*1000 + dateTime.microsecond(), 6); break;
case 'z': text.append(DateTimeFormatter::tzdISO(_localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
case 'Z': text.append(DateTimeFormatter::tzdRFC(_localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break;
case '[':