KPublicTransport

timeutil.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "timeutil_p.h"
8
9#include <QDateTime>
10#include <QTimeZone>
11
12using namespace KPublicTransport;
13
14QDateTime TimeUtil::applyTimeZone(QDateTime dt, const QTimeZone &tz)
15{
16 if (!dt.isValid()) {
17 return dt;
18 }
19 switch (dt.timeSpec()) {
20 case Qt::LocalTime:
21 dt.setTimeZone(tz);
22 break;
23 case Qt::UTC:
24 dt = dt.toTimeZone(tz);
25 break;
27 if (tz.offsetFromUtc(dt) == dt.offsetFromUtc()) {
28 dt.setTimeZone(tz);
29 }
30 break;
31 case Qt::TimeZone:
32 if ( dt.timeZone() == QTimeZone::utc() && tz != QTimeZone::utc()) {
33 dt = dt.toTimeZone(tz);
34 }
35 break;
36 }
37 return dt;
38}
Query operations and data types for accessing realtime public transport information from online servi...
bool isValid() const const
int offsetFromUtc() const const
void setTimeZone(const QTimeZone &toZone)
Qt::TimeSpec timeSpec() const const
QTimeZone timeZone() const const
QDateTime toTimeZone(const QTimeZone &timeZone) const const
LocalTime
int offsetFromUtc(const QDateTime &atDateTime) const const
QTimeZone utc()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:57:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.