KOpeningHours::OpeningHours

Search for usage in LXR

#include <openinghours.h>

Public Types

enum  Error {
  Null, NoError, SyntaxError, MissingRegion,
  MissingLocation, IncompatibleMode, UnsupportedFeature, EvaluationError
}
 
enum  Mode { IntervalMode = 1, PointInTimeMode = 2 }
 
typedef QFlags< ModeModes
 

Properties

Error error
 
float latitude
 
float longitude
 
QString normalizedExpression
 
QString region
 
QString timeZone
 

Public Member Functions

 OpeningHours ()
 
 OpeningHours (const QByteArray &openingHours, Modes modes=IntervalMode)
 
 OpeningHours (const char *openingHours, std::size_t size, Modes modes=IntervalMode)
 
 OpeningHours (const OpeningHours &)
 
 OpeningHours (OpeningHours &&)
 
Error error () const
 
Q_INVOKABLE KOpeningHours::Interval interval (const QDateTime &dt) const
 
float latitude () const
 
float longitude () const
 
Q_INVOKABLE KOpeningHours::Interval nextInterval (const KOpeningHours::Interval &interval) const
 
QByteArray normalizedExpression () const
 
OpeningHoursoperator= (const OpeningHours &)
 
OpeningHoursoperator= (OpeningHours &&)
 
QString region () const
 
void setExpression (const QByteArray &openingHours, Modes modes=IntervalMode)
 
void setExpression (const char *openingHours, std::size_t size, Modes modes=IntervalMode)
 
void setLatitude (float latitude)
 
Q_INVOKABLE void setLocation (float latitude, float longitude)
 
void setLongitude (float longitude)
 
void setRegion (QStringView region)
 
void setTimeZone (const QTimeZone &tz)
 
QByteArray simplifiedExpression () const
 
QTimeZone timeZone () const
 

Static Public Member Functions

static OpeningHours fromJsonLd (const QJsonObject &obj)
 

Detailed Description

An OSM opening hours specification.

This is the main entry point into this library, providing both a way to parse opening hours expressions and to evaluate them.

See also
https://wiki.openstreetmap.org/wiki/Key:opening_hours

Definition at line 32 of file openinghours.h.

Member Enumeration Documentation

Error codes.

Enumerator
Null 

no expression is set

NoError 

there is no error, the expression is valid and can be used

SyntaxError 

syntax error in the opening hours expression

MissingRegion 

expression refers to public or school holidays, but that information is not available

MissingLocation 

evaluation requires location information and those aren't set

IncompatibleMode 

expression mode doesn't match the expected mode

UnsupportedFeature 

expression uses a feature that isn't implemented/supported (yet)

EvaluationError 

runtime error during evaluating the expression

Definition at line 130 of file openinghours.h.

Evaluation modes for opening hours expressions.

Enumerator
IntervalMode 

Expressions that describe time ranges.

PointInTimeMode 

Expressions that describe points in time.

Definition at line 45 of file openinghours.h.

Constructor & Destructor Documentation

OpeningHours::OpeningHours ( )
explicit

Create an empty/invalid instance.

Definition at line 294 of file openinghours.cpp.

OpeningHours::OpeningHours ( const QByteArray openingHours,
Modes  modes = IntervalMode 
)
explicit

Parse OSM opening hours expression openingHours.

Parameters
modesSpecify whether time interval and/or point in time expressions are expected. If openingHours doesn't match modes, error() return IncompatibleMode.

Definition at line 300 of file openinghours.cpp.

OpeningHours::OpeningHours ( const char *  openingHours,
std::size_t  size,
Modes  modes = IntervalMode 
)
explicit

Parse OSM opening hours expression openingHours.

Parameters
modesSpecify whether time interval and/or point in time expressions are expected. If openingHours doesn't match modes, error() return IncompatibleMode.

Definition at line 306 of file openinghours.cpp.

Member Function Documentation

Error KOpeningHours::OpeningHours::error ( ) const

Error status of this expression.

OpeningHours OpeningHours::fromJsonLd ( const QJsonObject obj)
static

Convert opening hours in schema.org JSON-LD format.

This supports the following formats:

Definition at line 642 of file openinghours.cpp.

Interval OpeningHours::interval ( const QDateTime dt) const

Returns the interval containing dt.

Definition at line 491 of file openinghours.cpp.

Interval OpeningHours::nextInterval ( const KOpeningHours::Interval interval) const

Returns the interval immediately following interval.

Definition at line 579 of file openinghours.cpp.

QByteArray KOpeningHours::OpeningHours::normalizedExpression ( ) const

Returns the OSM opening hours expression reconstructed from this object.

In many cases it will be the same as the expression given to the constructor or to setExpression, but some normalization can happen as well, especially in case of non-conform input.

void OpeningHours::setExpression ( const QByteArray openingHours,
OpeningHours::Modes  modes = IntervalMode 
)

Parse OSM opening hours expression openingHours.

Parameters
modesSpecify whether time interval and/or point in time expressions are expected. If openingHours doesn't match modes, error() return IncompatibleMode. Prefer this over creating new instances if you are processing many expressions at once.

Definition at line 320 of file openinghours.cpp.

void OpeningHours::setExpression ( const char *  openingHours,
std::size_t  size,
Modes  modes = IntervalMode 
)

Parse OSM opening hours expression openingHours.

Parameters
modesSpecify whether time interval and/or point in time expressions are expected. If openingHours doesn't match modes, error() return IncompatibleMode. Prefer this over creating new instances if you are processing many expressions at once.

Definition at line 325 of file openinghours.cpp.

void OpeningHours::setLocation ( float  latitude,
float  longitude 
)

Geographic coordinate at which this expression should be evaluated.

This is needed for expressions containing location-based variable time references, such as "sunset". If the expression requires a location, error() returns MissingLocation if no location has been specified.

Definition at line 423 of file openinghours.cpp.

void OpeningHours::setRegion ( QStringView  region)

ISO 3166-2 region or ISO 316-1 country in which this expression should be evaluated.

This is needed for expressions containing public holiday references ("PH"). If the expression references a public holiday, error() returns MissingRegion if no region has been specified, or if no holiday data is available for the specified region.

Definition at line 458 of file openinghours.cpp.

void OpeningHours::setTimeZone ( const QTimeZone tz)

Timezone in which this expression should be evaluated.

If not specified, this assumes local time.

Definition at line 470 of file openinghours.cpp.

QByteArray OpeningHours::simplifiedExpression ( ) const

Returns a simplified OSM opening hours expression reconstructed from this object.

In many cases it will be the same as normalizedExpression(), but further simplifications can happen, to make the expression shorter/simpler.

Definition at line 412 of file openinghours.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 9 2021 23:04:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.