KPublicTransport

stopoverutil.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "stopoverutil_p.h"
8#include "timeutil_p.h"
9
10#include <KPublicTransport/Stopover>
11#include <KPublicTransport/StopoverRequest>
12
13#include <QDateTime>
14#include <QTimeZone>
15
16using namespace KPublicTransport;
17
18static QDateTime clipSeconds(QDateTime dt)
19{
20 dt.setTime({dt.time().hour(), dt.time().minute()});
21 return dt;
22}
23
24bool StopoverUtil::timeLessThan(const StopoverRequest &req, const Stopover &lhs, const Stopover &rhs)
25{
27 return clipSeconds(lhs.scheduledDepartureTime()) < clipSeconds(rhs.scheduledDepartureTime());
28 } else {
29 return clipSeconds(lhs.scheduledArrivalTime()) < clipSeconds(rhs.scheduledArrivalTime());
30 }
31}
32
33bool StopoverUtil::timeEqual(const StopoverRequest &req, const Stopover &lhs, const Stopover &rhs)
34{
36 return clipSeconds(lhs.scheduledDepartureTime()) == clipSeconds(rhs.scheduledDepartureTime());
37 } else {
38 return clipSeconds(lhs.scheduledArrivalTime()) == clipSeconds(rhs.scheduledArrivalTime());
39 }
40}
41
42void StopoverUtil::applyTimeZone(Stopover &dep, const QTimeZone &tz)
43{
44 dep.setScheduledDepartureTime(TimeUtil::applyTimeZone(dep.scheduledDepartureTime(), tz));
45 dep.setExpectedDepartureTime(TimeUtil::applyTimeZone(dep.expectedDepartureTime(), tz));
46 dep.setScheduledArrivalTime(TimeUtil::applyTimeZone(dep.scheduledArrivalTime(), tz));
47 dep.setExpectedArrivalTime(TimeUtil::applyTimeZone(dep.expectedArrivalTime(), tz));
48}
49
50void StopoverUtil::propagateTimeZone(Stopover &stop)
51{
52 if (const auto tz = stop.stopPoint().timeZone(); tz.isValid()) {
53 StopoverUtil::applyTimeZone(stop, tz);
54 }
55}
Describes an arrival or departure search.
@ QueryDeparture
Search for departures.
Mode mode
Controls whether to search for arrivals or departures.
Information about an arrival and/or departure of a vehicle at a stop area.
Definition stopover.h:26
QDateTime expectedDepartureTime
Actual departure time, if available.
Definition stopover.h:45
QDateTime expectedArrivalTime
Actual arrival time, if available.
Definition stopover.h:34
QDateTime scheduledArrivalTime
Planned arrival time.
Definition stopover.h:30
QDateTime scheduledDepartureTime
Planned departure time.
Definition stopover.h:41
void stop(Ekos::AlignState mode)
Query operations and data types for accessing realtime public transport information from online servi...
void setTime(QTime time)
QTime time() const const
int hour() const const
int minute() const const
bool isValid() const const
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.