helpers: Added intervalToFileNames

This commit is contained in:
Paul Beckingham 2016-04-13 23:43:08 -04:00
parent 15a68de535
commit 2b94fc6418
2 changed files with 40 additions and 0 deletions

View file

@ -258,3 +258,42 @@ std::string jsonFromIntervals (const std::vector <Interval>& intervals)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Given an interval, determine which files names need to be written.
std::vector <std::string> intervalToFileNames (const Interval& interval)
{
std::vector <std::string> files;
auto start_y = interval.start ().year ();
auto start_m = interval.start ().month ();
auto end = interval.end ();
if (end.toEpoch () == 0)
end = Datetime ();
auto end_y = end.year ();
auto end_m = end.month ();
while (start_y <= end_y ||
(start_y == end_y && start_m <= end_m))
{
std::stringstream name;
name << std::setw (4) << std::setfill ('0') << start_y
<< '-'
<< std::setw (2) << std::setfill ('0') << start_m
<< ".data";
files.push_back (name.str ());
// Next month.
start_m += 1;
if (start_m > 12)
{
start_y += 1;
start_m = 1;
}
}
return files;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -53,6 +53,7 @@ Timeline createTimelineFromData (const Rules&, Database&, const Filter&);
Interval getLatestInterval (Database&); Interval getLatestInterval (Database&);
bool intervalMatchesFilter (const Interval&, const Filter&); bool intervalMatchesFilter (const Interval&, const Filter&);
std::string jsonFromIntervals (const std::vector <Interval>&); std::string jsonFromIntervals (const std::vector <Interval>&);
std::vector <std::string> intervalToFileNames (const Interval&);
// utiŀ.cpp // utiŀ.cpp
std::string osName (); std::string osName ();