Add ReplaceExcludeTime method to TimeTable.

This commit is contained in:
Sergey Magidovich 2015-12-08 13:15:52 +03:00 committed by Sergey Yershov
parent 9e72a7e8eb
commit 9d84d50896
3 changed files with 26 additions and 5 deletions

View file

@ -102,6 +102,18 @@ UNIT_TEST(TestTimeTable_ExcludeTime)
tt.SetOpeningTime({8_h + 15_min, 15_h + 30_min});
TEST(!tt.AddExcludeTime({7_h, 14_h}), ());
}
{
auto tt = TimeTable::GetPredefinedTimeTable();
tt.SetTwentyFourHours(false);
tt.SetOpeningTime({8_h + 15_min, 18_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(tt.ReplaceExcludeTime({13_h, 14_h}, 1), ());
TEST(!tt.ReplaceExcludeTime({10_h + 30_min, 14_h}, 1), ());
TEST_EQUAL(tt.GetExcludeTime().size(), 3, ());
}
}
UNIT_TEST(TestAppendTimeTable)

View file

@ -115,7 +115,7 @@ TimeTable TimeTable::GetPredefinedTimeTable()
osmoh::Weekday::Saturday
};
tt.m_openingTime = tt.GetPredifinedOpeningTime();
tt.m_openingTime = tt.GetPredefinedOpeningTime();
return tt;
}
@ -152,11 +152,19 @@ bool TimeTable::SetOpeningTime(osmoh::Timespan const & span)
bool TimeTable::AddExcludeTime(osmoh::Timespan const & span)
{
if (IsTwentyFourHours())
return ReplaceExcludeTime(span, GetExcludeTime().size());
}
bool TimeTable::ReplaceExcludeTime(osmoh::Timespan const & span, size_t const index)
{
if (IsTwentyFourHours() || index > m_excludeTime.size())
return false;
auto copy = m_excludeTime;
copy.push_back(span);
if (index == m_excludeTime.size())
copy.push_back(span);
else
copy[index] = span;
if (!FixTimeSpans(copy, m_openingTime))
return false;
@ -191,7 +199,7 @@ bool TimeTable::IsValid() const
return true;
}
osmoh::Timespan TimeTable::GetPredifinedOpeningTime() const
osmoh::Timespan TimeTable::GetPredefinedOpeningTime() const
{
using osmoh::operator""_h;
return {10_h, 22_h};

View file

@ -30,12 +30,13 @@ public:
bool SetOpeningTime(osmoh::Timespan const & span);
bool AddExcludeTime(osmoh::Timespan const & span);
bool ReplaceExcludeTime(osmoh::Timespan const & span, size_t const index);
bool RemoveExcludeTime(size_t const index);
osmoh::TTimespans const & GetExcludeTime() const { return m_excludeTime; }
bool IsValid() const;
osmoh::Timespan GetPredifinedOpeningTime() const;
osmoh::Timespan GetPredefinedOpeningTime() const;
osmoh::Timespan GetPredefinedExcludeTime() const;
private: