mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
helper: Added splitInterval
This commit is contained in:
parent
3b45e90c5e
commit
75414b50ca
2 changed files with 32 additions and 0 deletions
|
@ -583,3 +583,34 @@ int quantizeTo15Minutes (const int minutes)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <Interval> splitInterval (
|
||||
const Interval& interval,
|
||||
const std::vector <Range>& exclusions)
|
||||
{
|
||||
std::vector <Interval> all;
|
||||
|
||||
// Start with a single range from the interval, from which to subtract.
|
||||
std::vector <Range> intervalFragments {interval.range};
|
||||
for (auto& exclusion : exclusions)
|
||||
{
|
||||
std::vector <Range> brokenFragments;
|
||||
for (auto& fragment : intervalFragments)
|
||||
for (auto& broken : fragment.subtract (exclusion))
|
||||
brokenFragments.push_back (broken);
|
||||
|
||||
intervalFragments = brokenFragments;
|
||||
}
|
||||
|
||||
// Return all the fragments as intervals.
|
||||
for (auto& fragment : intervalFragments)
|
||||
{
|
||||
// Clone the interval, set the new range.
|
||||
Interval clipped {interval};
|
||||
clipped.range = fragment;
|
||||
all.push_back (clipped);
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -60,6 +60,7 @@ std::vector <Range> combineHolidaysAndExclusions (const Range&, const Rules&, co
|
|||
Palette createPalette (const Rules&);
|
||||
std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&);
|
||||
int quantizeTo15Minutes (const int);
|
||||
std::vector <Interval> splitInterval (const Interval&, const std::vector <Range>&);
|
||||
|
||||
// utiŀ.cpp
|
||||
std::string osName ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue