Interval: Added ::jsn

This commit is contained in:
Paul Beckingham 2016-03-22 01:08:46 -04:00
parent 85c5140f2c
commit 9753a63eb8
2 changed files with 34 additions and 0 deletions

View file

@ -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
{

View file

@ -51,6 +51,7 @@ public:
std::string summarize () const;
std::string serialize () const;
std::string json () const;
std::string dump () const;
private: