summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2010-05-04 22:01:48 +0200
committerLukas Zeller <luz@synthesis.ch>2010-05-13 14:06:57 +0200
commita8e6aac2bc2f0a4ed6f85e84aada17737553c9fb (patch)
treec2bb97903ad89b461b70a0c768b481e717aec9a6
parent61ebdfc3ee9fb408fa297c3686c956b64f773152 (diff)
time zone matching: added debug and error logging
Previously, failures in VTIMEZONEtoTZEntry() were ignored. VTIMEZONEtoInternal() then continued with incomplete information, typically leading to wrong results. This patch adds an error message and debug logging. The error message makes it obvious that something went wrong. The debug logging is necessary to debug more subtle problems.
-rwxr-xr-xsrc/sysync/timezones.cpp18
-rwxr-xr-xsrc/sysync/timezones.h2
-rw-r--r--src/sysync/vtimezone.cpp23
3 files changed, 33 insertions, 10 deletions
diff --git a/src/sysync/timezones.cpp b/src/sysync/timezones.cpp
index 39cf8bf..3ca5b73 100755
--- a/src/sysync/timezones.cpp
+++ b/src/sysync/timezones.cpp
@@ -109,7 +109,7 @@ bool GZones::initialize()
}
-bool GZones::matchTZ(const tz_entry &aTZ, timecontext_t &aContext)
+bool GZones::matchTZ(const tz_entry &aTZ, TDebugLogger *aLogP, timecontext_t &aContext)
{
// keeps track of best match while iterating
class comparison : public visitor {
@@ -128,16 +128,20 @@ bool GZones::matchTZ(const tz_entry &aTZ, timecontext_t &aContext)
/** the last entry without dynYear, i.e., the main entry of a group */
timecontext_t fLeadContext;
+ TDebugLogger *fLogP;
+
/** time zones */
GZones *fG;
+
public:
- comparison(const tz_entry &aTZ, GZones *g) :
+ comparison(const tz_entry &aTZ, TDebugLogger *aLogP, GZones *g) :
fRuleMatch(false),
fLocationMatch(false),
fContext(TCTX_UNKNOWN),
fTZID(aTZ.name),
fLeadContext(TCTX_UNKNOWN),
+ fLogP(aLogP),
fG(g)
{
// prepare information for tzcmp() and YearFit()
@@ -164,6 +168,8 @@ bool GZones::matchTZ(const tz_entry &aTZ, timecontext_t &aContext)
!fTZ.name.empty() && // empty match is NOT better !!
fTZ.name == aTZ.name) {
// name AND rule match => best possible match, return early
+ PLOGDEBUGPRINTFX(fLogP, DBG_PARSE+DBG_EXOTIC,
+ ("matchTZ: final rule and name match for %s", fTZ.name.c_str()));
fContext = fLeadContext;
return true;
}
@@ -175,6 +181,10 @@ bool GZones::matchTZ(const tz_entry &aTZ, timecontext_t &aContext)
(!fRuleMatch && rule_match)) {
// previous match did not match location or
// not the rules and we do, so this match is better
+ PLOGDEBUGPRINTFX(fLogP, DBG_PARSE+DBG_EXOTIC,
+ ("matchTZ %s: location %s found, rules %s",
+ aTZ.name.c_str(), aTZ.location.c_str(),
+ rule_match ? "match" : "don't match"));
fLocationMatch = true;
fRuleMatch = rule_match;
fContext = fLeadContext;
@@ -186,6 +196,8 @@ bool GZones::matchTZ(const tz_entry &aTZ, timecontext_t &aContext)
if (!fLocationMatch &&
rule_match &&
!fRuleMatch) {
+ PLOGDEBUGPRINTFX(fLogP, DBG_PARSE+DBG_EXOTIC,
+ ("matchTZ %s: rules match", aTZ.name.c_str()));
fContext = fLeadContext;
fRuleMatch = true;
}
@@ -204,7 +216,7 @@ bool GZones::matchTZ(const tz_entry &aTZ, timecontext_t &aContext)
} // result
}
- c(aTZ, this);
+ c(aTZ, aLogP, this);
foreachTZ(c);
diff --git a/src/sysync/timezones.h b/src/sysync/timezones.h
index 095ead5..16e5071 100755
--- a/src/sysync/timezones.h
+++ b/src/sysync/timezones.h
@@ -251,7 +251,7 @@ class GZones {
* refers to the tz_entry without a dynYear
* @return true if match found
*/
- bool matchTZ(const tz_entry &aTZ, timecontext_t &aContext);
+ bool matchTZ(const tz_entry &aTZ, TDebugLogger *aLogP, timecontext_t &aContext);
class visitor {
public:
diff --git a/src/sysync/vtimezone.cpp b/src/sysync/vtimezone.cpp
index 4eee4b5..f737379 100644
--- a/src/sysync/vtimezone.cpp
+++ b/src/sysync/vtimezone.cpp
@@ -258,6 +258,7 @@ static bool GetTZInfo( cAppCharP aText,
timecontext_t tctx;
lineartime_t dtstart, dtH= 0;
string a, st;
+ bool success = true;
if (aNth==-1) { // search for the last (in time)
sInt32 i= 1;
@@ -286,9 +287,11 @@ static bool GetTZInfo( cAppCharP aText,
string vvv;
internalRToRRULE2( vvv, r, false, aLogP );
Rtm_to_tChange ( r, dtstart, c );
+ } else {
+ success = false;
} // if
- return true;
+ return success;
} // GetTZInfo
@@ -397,13 +400,19 @@ bool VTIMEZONEtoTZEntry( const char* aText, // VTIMEZONE string to be parsed
TDebugLogger* aLogP)
{
short dBias; // the full bias for DST
+ bool success = true;
t.name = "";
t.ident = "";
t.dynYear= "CUR";
t.biasDST= 0;
- GetTZInfo( aText,VTZ_STD, t.std, t.bias, aStdName, -1, aLogP );
- if (!GetTZInfo( aText,VTZ_DST, t.dst, dBias, aDstName, -1, aLogP )) dBias= t.bias;
+ if (!GetTZInfo( aText,VTZ_STD, t.std, t.bias, aStdName, -1, aLogP )) {
+ success = false;
+ }
+ if (!GetTZInfo( aText,VTZ_DST, t.dst, dBias, aDstName, -1, aLogP )) {
+ dBias= t.bias;
+ success = false;
+ }
if (t.bias == dBias) ClrDST( t ); // no DST ?
else t.biasDST= dBias - t.bias; // t.biasDST WILL be calculated here
@@ -411,7 +420,7 @@ bool VTIMEZONEtoTZEntry( const char* aText, // VTIMEZONE string to be parsed
// get TZID as found in VTIMEZONE
t.name = VValue( aText, VTZ_ID );
- return true;
+ return success;
} // VTIMEZONEtoTZEntry
@@ -430,7 +439,9 @@ bool VTIMEZONEtoInternal( const char* aText, // VTIMEZONE string to be parsed
lName;
timecontext_t lContext;
- VTIMEZONEtoTZEntry( aText, t, stdName, dstName, aLogP );
+ if (!VTIMEZONEtoTZEntry( aText, t, stdName, dstName, aLogP )) {
+ PLOGDEBUGPRINTFX(aLogP, DBG_PARSE+DBG_ERROR, ("parsing VTIMEZONE failed:\n%s", aText));
+ }
if (aTzidP) *aTzidP = t.name; // return the original TZID as found, needed to match with TZID occurences in rest of vCalendar
bool sC= !(stdName=="");
@@ -453,7 +464,7 @@ bool VTIMEZONEtoInternal( const char* aText, // VTIMEZONE string to be parsed
// find best match for VTIMEZONE: checks name and rules
// allows multiple timezone, if last is ok !
if (!g) return false; // avoid crashes with g==NULL
- ok= g->matchTZ(t, aContext);
+ ok= g->matchTZ(t, aLogP, aContext);
if (!ok && !okM) { // store it "as is" if both is not ok
ClrDST( t );