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 char *openingHours, std::size_t size, Modes modes=IntervalMode)
 
 OpeningHours (const OpeningHours &)
 
 OpeningHours (const QByteArray &openingHours, Modes modes=IntervalMode)
 
 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 char *openingHours, std::size_t size, Modes modes=IntervalMode)
 
void setExpression (const QByteArray &openingHours, 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

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.

◆ Mode

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() [1/3]

OpeningHours::OpeningHours ( )
explicit

Create an empty/invalid instance.

Definition at line 314 of file openinghours.cpp.

◆ OpeningHours() [2/3]

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 320 of file openinghours.cpp.

◆ OpeningHours() [3/3]

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 326 of file openinghours.cpp.

Member Function Documentation

◆ error()

Error KOpeningHours::OpeningHours::error ( ) const

Error status of this expression.

◆ fromJsonLd()

OpeningHours OpeningHours::fromJsonLd ( const QJsonObject obj)
static

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

This supports the following formats:

Definition at line 663 of file openinghours.cpp.

◆ interval()

Interval OpeningHours::interval ( const QDateTime dt) const

Returns the interval containing dt.

Definition at line 512 of file openinghours.cpp.

◆ nextInterval()

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

Returns the interval immediately following interval.

Definition at line 600 of file openinghours.cpp.

◆ normalizedExpression()

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.

◆ setExpression() [1/2]

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 345 of file openinghours.cpp.

◆ setExpression() [2/2]

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 340 of file openinghours.cpp.

◆ setLocation()

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 444 of file openinghours.cpp.

◆ setRegion()

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 479 of file openinghours.cpp.

◆ setTimeZone()

void OpeningHours::setTimeZone ( const QTimeZone tz)

Timezone in which this expression should be evaluated.

If not specified, this assumes local time.

Definition at line 491 of file openinghours.cpp.

◆ simplifiedExpression()

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 432 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-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:52:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.