mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
helper: Added jsonFromIntervals
This commit is contained in:
parent
4b1bf763d5
commit
57b45f9c73
2 changed files with 34 additions and 0 deletions
|
@ -215,3 +215,36 @@ bool intervalMatchesFilter (const Interval& interval, const Filter& filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Compose a JSON document of intervals. In the trivial case:
|
||||||
|
// [
|
||||||
|
// ]
|
||||||
|
//
|
||||||
|
// In the non-trivial case:
|
||||||
|
// [
|
||||||
|
// {...},
|
||||||
|
// {...}
|
||||||
|
// ]
|
||||||
|
//
|
||||||
|
std::string jsonFromIntervals (const std::vector <Interval>& intervals)
|
||||||
|
{
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
out << "[\n";
|
||||||
|
int counter = 0;
|
||||||
|
for (auto& interval : intervals)
|
||||||
|
{
|
||||||
|
if (counter)
|
||||||
|
out << ",\n";
|
||||||
|
|
||||||
|
out << interval.json ();
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter)
|
||||||
|
out << "\n";
|
||||||
|
|
||||||
|
out << "]\n";
|
||||||
|
return out.str ();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -51,6 +51,7 @@ Filter createFilterFromCLI (const CLI&);
|
||||||
Timeline createTimelineFromData (const Rules&, Database&, const Filter&);
|
Timeline createTimelineFromData (const Rules&, Database&, const Filter&);
|
||||||
Interval getLatestInterval (Timeline&, Database&, const Filter&);
|
Interval getLatestInterval (Timeline&, Database&, const Filter&);
|
||||||
bool intervalMatchesFilter (const Interval&, const Filter&);
|
bool intervalMatchesFilter (const Interval&, const Filter&);
|
||||||
|
std::string jsonFromIntervals (const std::vector <Interval>&);
|
||||||
|
|
||||||
// utiŀ.cpp
|
// utiŀ.cpp
|
||||||
std::string osName ();
|
std::string osName ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue