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 Typedef Documentation

◆ Modes

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.

Property Documentation

◆ error

Error KOpeningHours::OpeningHours::error
read

Definition at line 35 of file openinghours.h.

◆ latitude

float KOpeningHours::OpeningHours::latitude
readwrite

Definition at line 37 of file openinghours.h.

◆ longitude

float KOpeningHours::OpeningHours::longitude
readwrite

Definition at line 38 of file openinghours.h.

◆ normalizedExpression

QString KOpeningHours::OpeningHours::normalizedExpression
read

Definition at line 36 of file openinghours.h.

◆ region

QString KOpeningHours::OpeningHours::region
readwrite

Definition at line 40 of file openinghours.h.

◆ timeZone

QString KOpeningHours::OpeningHours::timeZone
readwrite

Definition at line 42 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()

OpeningHours::Error OpeningHours::error ( ) const

Error status of this expression.

Definition at line 506 of file openinghours.cpp.

◆ 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.

◆ latitude()

float OpeningHours::latitude ( ) const

Definition at line 451 of file openinghours.cpp.

◆ longitude()

float OpeningHours::longitude ( ) const

Definition at line 462 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 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.

Definition at line 403 of file openinghours.cpp.

◆ region()

QString OpeningHours::region ( ) const

Definition at line 474 of file openinghours.cpp.

◆ 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.

◆ setLatitude()

void OpeningHours::setLatitude ( float latitude)

Definition at line 456 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.

◆ setLongitude()

void OpeningHours::setLongitude ( float longitude)

Definition at line 467 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.

◆ timeZone()

QTimeZone OpeningHours::timeZone ( ) const

Definition at line 486 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-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.