7#include "openinghourscache_p.h"
10#include <KOpeningHours/Interval>
11#include <KOpeningHours/OpeningHours>
17bool OpeningHoursCache::Entry::operator<(
const Entry &other)
const
19 if (elementId == other.elementId) {
22 return elementId < other.elementId;
25OpeningHoursCache::OpeningHoursCache()
30OpeningHoursCache::~OpeningHoursCache() =
default;
32void OpeningHoursCache::setMapData(
const MapData &mapData)
34 if (m_mapData == mapData) {
38 m_cacheEntries.clear();
44 const auto actualEnd = (
end.isValid() && end > actualBegin) ?
end : actualBegin.addYears(1);
46 if (actualBegin == m_begin && actualEnd == m_end) {
50 m_begin = actualBegin;
52 m_cacheEntries.clear();
57 Entry entry{elem.id(), oh, UnknownResult};
58 const auto it = std::lower_bound(m_cacheEntries.begin(), m_cacheEntries.end(), entry);
59 if (it != m_cacheEntries.end() && (*it).elementId == elem.id() && (*it).oh == oh) {
60 if ((*it).results & HasEntireRangeResult) {
61 return (*it).results & EntirelyClosedInTimeRange;
63 entry.results = (*it).results;
67 expr.setLocation(elem.center().latF(), elem.center().lonF());
68 expr.setRegion(m_mapData.regionCode());
69 expr.setTimeZone(m_mapData.timeZone());
72 qCDebug(
Log) <<
"opening hours expression error:" << expr.error() << oh << elem.url();
74 auto i = expr.interval(m_begin);
75 while (i.state() == KOpeningHours::Interval::Closed && !i.hasOpenEnd() && (i.end() < m_end || !m_end.isValid())) {
76 i = expr.nextInterval(i);
79 qCDebug(
Log) <<
"opening hours expression runtime error:" << expr.error() << oh << i << elem.url();
81 if (i.state() == KOpeningHours::Interval::Closed) {
82 entry.results |= EntirelyClosedInTimeRange;
85 entry.results |= HasEntireRangeResult;
86 const bool closed = entry.results & EntirelyClosedInTimeRange;
88 if (it != m_cacheEntries.end() && (*it).elementId == elem.id() && (*it).oh == oh) {
89 *it = std::move(entry);
91 m_cacheEntries.insert(it, std::move(entry));
98 Entry entry{elem.id(), oh, UnknownResult};
99 const auto it = std::lower_bound(m_cacheEntries.begin(), m_cacheEntries.end(), entry);
100 if (it != m_cacheEntries.end() && (*it).elementId == elem.id() && (*it).oh == oh) {
101 if ((*it).results & HasCurrentTimeResult) {
102 return (*it).results & IsAtCurrentTime;
104 entry.results = (*it).results;
108 expr.setLocation(elem.center().latF(), elem.center().lonF());
109 expr.setRegion(m_mapData.regionCode());
110 expr.setTimeZone(m_mapData.timeZone());
113 qCDebug(
Log) <<
"opening hours expression error:" << expr.error() << oh << elem.url();
115 const auto i = expr.interval(currentDateTime());
116 if (i.state() == KOpeningHours::Interval::Open) {
117 entry.results |= IsAtCurrentTime;
121 entry.results |= HasCurrentTimeResult;
122 const bool open = entry.results & IsAtCurrentTime;
124 if (it != m_cacheEntries.end() && (*it).elementId == elem.id() && (*it).oh == oh) {
125 *it = std::move(entry);
127 m_cacheEntries.insert(it, std::move(entry));
132QDateTime OpeningHoursCache::currentDateTime()
const
134 if (!m_begin.isValid() && !m_end.isValid()) {
137 if (!m_begin.isValid()) {
140 if (!m_end.isValid()) {
Raw OSM map data, separated by levels.
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
OSM-based multi-floor indoor maps for buildings.
const QList< QKeySequence > & begin()
const QList< QKeySequence > & end()
QDateTime addSecs(qint64 s) const const
QDateTime currentDateTime()