KPublicTransport

stopoverutil.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "stopoverutil_p.h"
8 #include "lineutil_p.h"
9 #include "timeutil_p.h"
10 
11 #include <KPublicTransport/Stopover>
12 #include <KPublicTransport/StopoverRequest>
13 
14 #include <QDateTime>
15 #include <QTimeZone>
16 
17 using namespace KPublicTransport;
18 
19 static QDateTime clipSeconds(QDateTime dt)
20 {
21  dt.setTime({dt.time().hour(), dt.time().minute()});
22  return dt;
23 }
24 
25 bool StopoverUtil::timeLessThan(const StopoverRequest &req, const Stopover &lhs, const Stopover &rhs)
26 {
28  return clipSeconds(lhs.scheduledDepartureTime()) < clipSeconds(rhs.scheduledDepartureTime());
29  } else {
30  return clipSeconds(lhs.scheduledArrivalTime()) < clipSeconds(rhs.scheduledArrivalTime());
31  }
32 }
33 
34 bool StopoverUtil::timeEqual(const StopoverRequest &req, const Stopover &lhs, const Stopover &rhs)
35 {
37  return clipSeconds(lhs.scheduledDepartureTime()) == clipSeconds(rhs.scheduledDepartureTime());
38  } else {
39  return clipSeconds(lhs.scheduledArrivalTime()) == clipSeconds(rhs.scheduledArrivalTime());
40  }
41 }
42 
43 void StopoverUtil::applyTimeZone(Stopover &dep, const QTimeZone &tz)
44 {
45  dep.setScheduledDepartureTime(TimeUtil::applyTimeZone(dep.scheduledDepartureTime(), tz));
46  dep.setExpectedDepartureTime(TimeUtil::applyTimeZone(dep.expectedDepartureTime(), tz));
47  dep.setScheduledArrivalTime(TimeUtil::applyTimeZone(dep.scheduledArrivalTime(), tz));
48  dep.setExpectedArrivalTime(TimeUtil::applyTimeZone(dep.expectedArrivalTime(), tz));
49 }
50 
51 void StopoverUtil::applyMetaData(Stopover &dep, bool download)
52 {
53  auto route = dep.route();
54  auto line = route.line();
55  LineUtil::applyMetaData(line, dep.stopPoint(), download);
56  route.setLine(line);
57  dep.setRoute(route);
58 }
int minute() const const
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
KPublicTransport::Location stopPoint
The stop point of this departure.
Definition: stopover.h:64
void setTime(const QTime &time)
QTime time() const const
KPublicTransport::Route route
The departing route.
Definition: stopover.h:61
QDateTime scheduledArrivalTime
Planned arrival time.
Definition: stopover.h:30
Describes an arrival or departure search.
QDateTime expectedDepartureTime
Actual departure time, if available.
Definition: stopover.h:45
int hour() const const
Information about an arrival and/or departure of a vehicle at a stop area.
Definition: stopover.h:25
Mode mode
Controls whether to search for arrivals or departures.
QDateTime expectedArrivalTime
Actual arrival time, if available.
Definition: stopover.h:34
KPublicTransport::Line line
Line this route belongs to.
Definition: line.h:124
QDateTime scheduledDepartureTime
Planned departure time.
Definition: stopover.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 23:07:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.