From 68fe437889d5d004855cd07981a129e424f5db83 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 11 Jan 2011 00:07:11 -0500 Subject: [PATCH] Taskd - Modified Task::composeJSON to use ISO 8601 date format, and the new hierarchical annotation format. --- src/Task.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 68a9675b3..5aa7e8eac 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -430,17 +430,71 @@ std::string Task::composeJSON () const std::stringstream out; out << "{"; + // Used for determining type. + Att att; + + // First the non-annotations. + int attributes_written = 0; + int annotation_count = 0; std::map ::const_iterator i; for (i = this->begin (); i != this->end (); ++i) { - if (i != this->begin ()) + if (attributes_written) out << ","; - out << "\"" - << i->second.name () - << "\":\"" - << i->second.value () - << "\""; + if (i->second.name ().substr (0, 11) == "annotation_") + { + ++annotation_count; + } + else if (att.type (i->second.name ()) == "date") + { + Date d (i->second.value ()); + out << "\"" + << i->second.name () + << "\":\"" + << d.toISO () + << "\""; + + ++attributes_written; + } + else + { + out << "\"" + << i->second.name () + << "\":\"" + << i->second.value () + << "\""; + + ++attributes_written; + } + } + + // Now the annotations, if any. + if (annotation_count) + { + out << "," + << "\"annotations\":["; + + int annotations_written = 0; + for (i = this->begin (); i != this->end (); ++i) + { + if (i->second.name ().substr (0, 11) == "annotation_") + { + if (annotations_written) + out << ","; + + Date d (i->second.name ().substr (11)); + out << "{\"entry\":\"" + << d.toISO () + << "\",\"description\":\"" + << i->second.value () + << "\"}"; + + ++annotations_written; + } + } + + out << "]"; } out << "}";