From 721405d1fcd7bef4383007c7331396c5b6938a31 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Thu, 30 Oct 2014 14:06:13 +0100 Subject: [PATCH] #318: Logger local time doesn't automatically account for DST (PatternFormatter) --- Foundation/include/Poco/PatternFormatter.h | 17 ++++++++--------- Foundation/src/PatternFormatter.cpp | 17 +++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Foundation/include/Poco/PatternFormatter.h b/Foundation/include/Poco/PatternFormatter.h index 50c87643f..0ab1a33b3 100644 --- a/Foundation/include/Poco/PatternFormatter.h +++ b/Foundation/include/Poco/PatternFormatter.h @@ -121,10 +121,11 @@ protected: /// Returns a string for the given priority value. private: - struct PatternAction { - PatternAction(): key(0), length(0) {} + PatternAction(): key(0), length(0) + { + } char key; int length; @@ -132,16 +133,14 @@ private: std::string prepend; }; - std::vector _patternActions; - bool _localTime; - Timestamp::TimeDiff _localTimeOffset; - std::string _pattern; - - - void ParsePattern(); + void parsePattern(); /// Will parse the _pattern string into the vector of PatternActions, /// which contains the message key, any text that needs to be written first /// a proprety in case of %[] and required length. + + std::vector _patternActions; + bool _localTime; + std::string _pattern; }; diff --git a/Foundation/src/PatternFormatter.cpp b/Foundation/src/PatternFormatter.cpp index 29ad388dd..ff216c49c 100644 --- a/Foundation/src/PatternFormatter.cpp +++ b/Foundation/src/PatternFormatter.cpp @@ -34,18 +34,16 @@ const std::string PatternFormatter::PROP_TIMES = "times"; PatternFormatter::PatternFormatter(): - _localTime(false), - _localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst())) + _localTime(false) { } PatternFormatter::PatternFormatter(const std::string& format): _localTime(false), - _localTimeOffset(Timestamp::resolution()*(Timezone::utcOffset() + Timezone::dst())), _pattern(format) { - ParsePattern(); + parsePattern(); } @@ -60,7 +58,8 @@ void PatternFormatter::format(const Message& msg, std::string& text) bool localTime = _localTime; if (localTime) { - timestamp += _localTimeOffset; + timestamp += Timezone::utcOffset()*Timestamp::resolution(); + timestamp += Timezone::dst()*Timestamp::resolution(); } DateTime dateTime = timestamp; for (std::vector::iterator ip = _patternActions.begin(); ip != _patternActions.end(); ++ip) @@ -124,7 +123,8 @@ void PatternFormatter::format(const Message& msg, std::string& text) if (!localTime) { localTime = true; - timestamp += _localTimeOffset; + timestamp += Timezone::utcOffset()*Timestamp::resolution(); + timestamp += Timezone::dst()*Timestamp::resolution(); dateTime = timestamp; } break; @@ -132,7 +132,8 @@ void PatternFormatter::format(const Message& msg, std::string& text) } } -void PatternFormatter::ParsePattern() + +void PatternFormatter::parsePattern() { _patternActions.clear(); std::string::const_iterator it = _pattern.begin(); @@ -196,7 +197,7 @@ void PatternFormatter::setProperty(const std::string& name, const std::string& v if (name == PROP_PATTERN) { _pattern = value; - ParsePattern(); + parsePattern(); } else if (name == PROP_TIMES) {