9#include "openinghours_p.h"
16 if (m_state == Interval::Invalid) {
17 return m_comment.isEmpty() ? Interval::Open : Interval::Unknown;
22bool Rule::hasImplicitState()
const
24 return m_state == Interval::Invalid;
27void Rule::setState(
State state)
29 if (state == State::Off) {
30 m_state = Interval::Closed;
37void Rule::copyStateFrom(
const Rule &otherRule)
39 m_state = otherRule.m_state;
40 m_stateFlags = otherRule.m_stateFlags;
43bool Rule::hasComment()
const
45 return !m_comment.isEmpty();
48void Rule::setComment(
const char *str,
int len)
53int Rule::requiredCapabilities()
const
55 int c = Capability::None;
56 c |= m_timeSelector ? m_timeSelector->requiredCapabilities() : Capability::None;
57 c |= m_weekdaySelector ? m_weekdaySelector->requiredCapabilities() : Capability::None;
58 c |= m_weekSelector ? m_weekSelector->requiredCapabilities() : Capability::None;
59 c |= m_monthdaySelector ? m_monthdaySelector->requiredCapabilities() : Capability::None;
60 c |= m_yearSelector ? m_yearSelector->requiredCapabilities() : Capability::None;
61 c |= m_wideRangeSelectorComment.isEmpty() ? Capability::None : Capability::NotImplemented;
66bool Rule::isEmpty()
const
70 && (selectorCount() == 0)
72 && m_wideRangeSelectorComment.isEmpty();
75bool Rule::hasSmallRangeSelector()
const
77 return m_weekdaySelector || m_timeSelector;
80bool Rule::hasWideRangeSelector()
const
82 return m_yearSelector || m_weekSelector || m_monthdaySelector || !m_wideRangeSelectorComment.isEmpty();
88 if (!m_timeSelector && !m_weekdaySelector && !m_monthdaySelector && !m_weekSelector && !m_yearSelector) {
93 auto maybeSpace = [&]() {
99 expr = m_yearSelector->toExpression();
101 if (m_monthdaySelector) {
103 expr += m_monthdaySelector->toExpression({});
105 if (m_weekSelector) {
107 expr +=
"week " + m_weekSelector->toExpression();
109 if (!m_wideRangeSelectorComment.isEmpty()) {
110 expr +=
'"' + m_wideRangeSelectorComment.toUtf8() +
'"';
112 if (m_colonAfterWideRangeSelector) {
115 if (m_weekdaySelector) {
117 expr += m_weekdaySelector->toExpression();
119 if (m_timeSelector) {
121 expr += m_timeSelector->toExpression();
128 case Interval::Closed:
130 expr += m_stateFlags & Off ?
"off" :
"closed";
132 case Interval::Unknown:
136 case Interval::Invalid:
139 if (!m_comment.isEmpty()) {
143 expr +=
'"' + m_comment.toUtf8() +
'"';
148int Rule::selectorCount()
const
150 const auto selectors = { (bool)m_yearSelector, (
bool)m_monthdaySelector, (bool)m_weekSelector, (
bool)m_weekdaySelector, (bool)m_timeSelector };
151 return std::count(std::begin(selectors), std::end(selectors),
true);
State
Opening state during a time interval.
OSM opening hours parsing and evaluation.
bool isEmpty() const const
QString fromUtf8(QByteArrayView str)