mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
helpers: Added intervalToFileNames
This commit is contained in:
parent
15a68de535
commit
2b94fc6418
2 changed files with 40 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -53,6 +53,7 @@ Timeline createTimelineFromData (const Rules&, Database&, const Filter&);
|
|||
Interval getLatestInterval (Database&);
|
||||
bool intervalMatchesFilter (const Interval&, const Filter&);
|
||||
std::string jsonFromIntervals (const std::vector <Interval>&);
|
||||
std::vector <std::string> intervalToFileNames (const Interval&);
|
||||
|
||||
// utiŀ.cpp
|
||||
std::string osName ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue