Skip to content

Commit

Permalink
fix the XmlRpcValue and struct tm conversions. includes related bits …
Browse files Browse the repository at this point in the history
…from CVS, and fixes the tests.
  • Loading branch information
nega committed May 16, 2007
1 parent 53fea1e commit b68b373
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/XmlRpcValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/TestValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testDateTime()
int offset = 0;
XmlRpcValue dateTime("<value><dateTime.iso8601>19040101T03:12:35</dateTime.iso8601></value>", &offset);
struct tm &t = dateTime;
assert(t.tm_year == 1904 && t.tm_min == 12);
assert(t.tm_year == (1904 - 1900)&& t.tm_min == 12);
}


Expand Down

0 comments on commit b68b373

Please sign in to comment.