forked from organicmaps/organicmaps-tmp
Generate next exclude time properly.
This commit is contained in:
parent
9d84d50896
commit
d93962c547
2 changed files with 27 additions and 2 deletions
|
@ -114,6 +114,21 @@ UNIT_TEST(TestTimeTable_ExcludeTime)
|
|||
TEST(!tt.ReplaceExcludeTime({10_h + 30_min, 14_h}, 1), ());
|
||||
TEST_EQUAL(tt.GetExcludeTime().size(), 3, ());
|
||||
}
|
||||
{
|
||||
auto tt = TimeTable::GetPredefinedTimeTable();
|
||||
tt.SetTwentyFourHours(false);
|
||||
|
||||
tt.SetOpeningTime({8_h + 15_min, 23_h + 30_min});
|
||||
TEST(tt.AddExcludeTime({10_h, 11_h}), ());
|
||||
TEST(tt.AddExcludeTime({12_h, 13_h}), ());
|
||||
TEST(tt.AddExcludeTime({15_h, 17_h}), ());
|
||||
TEST_EQUAL(tt.GetPredefinedExcludeTime().GetStart().GetHourMinutes().GetHoursCount(), 19, ());
|
||||
TEST_EQUAL(tt.GetPredefinedExcludeTime().GetEnd().GetHourMinutes().GetHoursCount(), 20, ());
|
||||
|
||||
TEST(tt.AddExcludeTime({18_h, 23_h}), ());
|
||||
TEST_EQUAL(tt.GetPredefinedExcludeTime().GetStart().GetHourMinutes().GetHoursCount(), 1, ());
|
||||
TEST_EQUAL(tt.GetPredefinedExcludeTime().GetEnd().GetHourMinutes().GetHoursCount(), 2, ());
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(TestAppendTimeTable)
|
||||
|
|
|
@ -208,8 +208,18 @@ osmoh::Timespan TimeTable::GetPredefinedOpeningTime() const
|
|||
osmoh::Timespan TimeTable::GetPredefinedExcludeTime() const
|
||||
{
|
||||
using osmoh::operator""_h;
|
||||
// TODO(mgsergio): Genarate next span with start = end of the last once + 1_h
|
||||
return {12_h, 13_h};
|
||||
if (GetExcludeTime().empty())
|
||||
return {12_h, 13_h};
|
||||
|
||||
auto nextExcludeTimeStart = GetExcludeTime().back().GetEnd().GetHourMinutes();
|
||||
nextExcludeTimeStart.AddDuration(2_h);
|
||||
if (nextExcludeTimeStart.GetDuration() >= 24_h - 1_h)
|
||||
nextExcludeTimeStart.AddDuration(-24_h);
|
||||
|
||||
auto nextExcludeTimeEnd = nextExcludeTimeStart;
|
||||
nextExcludeTimeEnd.AddDuration(1_h);
|
||||
|
||||
return {nextExcludeTimeStart, nextExcludeTimeEnd};
|
||||
}
|
||||
|
||||
// TimeTableSet ------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue