| 305 | } |
| 306 | |
| 307 | bool MakeTimeTableSet(osmoh::OpeningHours const & oh, ui::TimeTableSet & tts) |
| 308 | { |
| 309 | if (!oh.IsValid()) |
| 310 | return false; |
| 311 | |
| 312 | if (oh.HasYearSelector() || oh.HasWeekSelector() || oh.HasMonthSelector()) |
| 313 | return false; |
| 314 | |
| 315 | tts = ui::TimeTableSet(); |
| 316 | if (oh.IsTwentyFourHours()) |
| 317 | return true; |
| 318 | |
| 319 | bool first = true; |
| 320 | for (auto const & rulePart : oh.GetRule()) |
| 321 | { |
| 322 | if (rulePart.IsEmpty()) |
| 323 | continue; |
| 324 | |
| 325 | ui::TimeTable tt = ui::TimeTable::GetUninitializedTimeTable(); |
| 326 | tt.SetOpeningTime(tt.GetPredefinedOpeningTime()); |
| 327 | |
| 328 | // Comments and unknown rules belong to advanced mode. |
| 329 | if (rulePart.GetModifier() == osmoh::RuleSequence::Modifier::Unknown || |
| 330 | rulePart.GetModifier() == osmoh::RuleSequence::Modifier::Comment) |
| 331 | return false; |
| 332 | |
| 333 | if (rulePart.GetModifier() == osmoh::RuleSequence::Modifier::Closed) |
| 334 | { |
| 335 | // Off modifier in the first part in oh is useless. Skip it. |
| 336 | if (first == true) |
| 337 | continue; |
| 338 | |
| 339 | if (!ExcludeRulePart(rulePart, tts)) |
| 340 | return false; |
| 341 | continue; |
| 342 | } |
| 343 | |
| 344 | if (rulePart.HasWeekdays()) |
| 345 | SetUpWeekdays(rulePart.GetWeekdays(), tt); |
| 346 | else |
| 347 | tt.SetOpeningDays(kWholeWeek); |
| 348 | |
| 349 | auto const & times = rulePart.GetTimes(); |
| 350 | |
| 351 | bool isTwentyFourHours = times.empty() || (times.size() == 1 && times.front() == kTwentyFourHours); |
| 352 | |
| 353 | if (isTwentyFourHours) |
| 354 | { |
| 355 | tt.SetTwentyFourHours(true); |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | tt.SetTwentyFourHours(false); |
| 360 | SetUpTimeTable(rulePart.GetTimes(), tt); |
| 361 | } |
| 362 | |
| 363 | // Check size as well since ExcludeRulePart can add new time tables. |
| 364 | bool const appended = first && tts.Size() == 1 ? tts.Replace(tt, 0) : tts.Append(tt); |