From d93962c5479806a3c35f66e38271d3c6e229ba64 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Tue, 8 Dec 2015 13:37:56 +0300 Subject: [PATCH] Generate next exclude time properly. --- editor/editor_tests/opening_hours_ui_test.cpp | 15 +++++++++++++++ editor/opening_hours_ui.cpp | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/editor/editor_tests/opening_hours_ui_test.cpp b/editor/editor_tests/opening_hours_ui_test.cpp index ede7c5b8f6..7298f6b38c 100644 --- a/editor/editor_tests/opening_hours_ui_test.cpp +++ b/editor/editor_tests/opening_hours_ui_test.cpp @@ -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) diff --git a/editor/opening_hours_ui.cpp b/editor/opening_hours_ui.cpp index 008e83ff20..a636f5c339 100644 --- a/editor/opening_hours_ui.cpp +++ b/editor/opening_hours_ui.cpp @@ -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 ------------------------------------------------------------------------------------