From b68b3736a44431c1a26c76b18e68a07ae88a2f83 Mon Sep 17 00:00:00 2001 From: nega Date: Wed, 16 May 2007 20:38:47 +0000 Subject: [PATCH] fix the XmlRpcValue and struct tm conversions. includes related bits from CVS, and fixes the tests. --- src/XmlRpcValue.cpp | 10 ++++++---- test/TestValues.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/XmlRpcValue.cpp b/src/XmlRpcValue.cpp index 180c72f..6cf9ca1 100644 --- a/src/XmlRpcValue.cpp +++ b/src/XmlRpcValue.cpp @@ -395,6 +395,8 @@ namespace XmlRpc { if (sscanf(stime.c_str(),"%4d%2d%2dT%2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec) != 6) return false; + t.tm_year -= 1900; + t.tm_mon -= 1; t.tm_isdst = -1; _type = TypeDateTime; _value.asTime = new struct tm(t); @@ -406,8 +408,8 @@ namespace XmlRpc { { struct tm* t = _value.asTime; char buf[20]; - snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d", - t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d", + 1900+t->tm_year,1+t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); buf[sizeof(buf)-1] = 0; std::string xml = VALUE_TAG; @@ -558,8 +560,8 @@ namespace XmlRpc { { struct tm* t = _value.asTime; char buf[20]; - snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d", - t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + snprintf(buf, sizeof(buf)-1, "%04d%02d%02dT%02d:%02d:%02d", + 1900+t->tm_year,1+t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); buf[sizeof(buf)-1] = 0; os << buf; break; diff --git a/test/TestValues.cpp b/test/TestValues.cpp index e770e51..5156a70 100644 --- a/test/TestValues.cpp +++ b/test/TestValues.cpp @@ -93,7 +93,7 @@ void testDateTime() int offset = 0; XmlRpcValue dateTime("19040101T03:12:35", &offset); struct tm &t = dateTime; - assert(t.tm_year == 1904 && t.tm_min == 12); + assert(t.tm_year == (1904 - 1900)&& t.tm_min == 12); }