From 9753a63eb8a3a9f4cdb92f2350d28f8a11b5bdc2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 22 Mar 2016 01:08:46 -0400 Subject: [PATCH] Interval: Added ::jsn --- src/Interval.cpp | 33 +++++++++++++++++++++++++++++++++ src/Interval.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/Interval.cpp b/src/Interval.cpp index d9924139..78771122 100644 --- a/src/Interval.cpp +++ b/src/Interval.cpp @@ -197,6 +197,39 @@ std::string Interval::serialize () const return out.str (); } +//////////////////////////////////////////////////////////////////////////////// +std::string Interval::json () const +{ + std::stringstream out; + out << "{\"type\":\"inc\""; + + if (_start.toEpoch ()) + out << ",\"start\":\"" << _start.toISO () << "\""; + + if (_end.toEpoch ()) + out << ",\"end\":\"" << _end.toISO () << "\""; + + if (_tags.size ()) + { + + std::string tags; + for (auto& tag : _tags) + { + if (tags[0]) + tags += ","; + + tags += "\"" + tag + "\""; + } + + out << ",\"tags\":[" + << tags + << "]"; + } + + out << "}"; + return out.str (); +} + //////////////////////////////////////////////////////////////////////////////// std::string Interval::dump () const { diff --git a/src/Interval.h b/src/Interval.h index e16d23f4..41dad511 100644 --- a/src/Interval.h +++ b/src/Interval.h @@ -51,6 +51,7 @@ public: std::string summarize () const; std::string serialize () const; + std::string json () const; std::string dump () const; private: