KPublicTransport

journeyutil.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 "journeyutil_p.h"
8#include "stopoverutil_p.h"
9#include "timeutil_p.h"
10
11#include <KPublicTransport/Journey>
12#include <KPublicTransport/Stopover>
13
14#include <QDateTime>
15#include <QTimeZone>
16
17using namespace KPublicTransport;
18
19QDateTime JourneyUtil::firstTransportDeparture(const Journey &jny)
20{
21 for (const auto &section : jny.sections()) {
22 if (section.mode() == JourneySection::PublicTransport) {
23 return section.scheduledDepartureTime();
24 }
25 }
26
27 return jny.scheduledDepartureTime();
28}
29
30bool JourneyUtil::firstTransportDepartureLessThan(const Journey &lhs, const Journey &rhs)
31{
32 return firstTransportDeparture(lhs) < firstTransportDeparture(rhs);
33}
34
35bool JourneyUtil::firstTransportDepartureEqual(const Journey &lhs, const Journey &rhs)
36{
37 return firstTransportDeparture(lhs) == firstTransportDeparture(rhs);
38}
39
40void JourneyUtil::applyTimeZone(Journey &jny, const QTimeZone &tz)
41{
42 auto sections = std::move(jny.takeSections());
43 for (auto &sec : sections) {
44 sec.setScheduledDepartureTime(TimeUtil::applyTimeZone(sec.scheduledDepartureTime(), tz));
45 sec.setExpectedDepartureTime(TimeUtil::applyTimeZone(sec.expectedDepartureTime(), tz));
46 sec.setScheduledArrivalTime(TimeUtil::applyTimeZone(sec.scheduledArrivalTime(), tz));
47 sec.setExpectedArrivalTime(TimeUtil::applyTimeZone(sec.expectedArrivalTime(), tz));
48
49 auto stops = sec.takeIntermediateStops();
50 for (auto &stop : stops) {
51 StopoverUtil::applyTimeZone(stop, tz);
52 }
53 sec.setIntermediateStops(std::move(stops));
54 }
55 jny.setSections(std::move(sections));
56}
57
58void JourneyUtil::propagateTimeZones(Journey &jny)
59{
60 auto sections = std::move(jny.takeSections());
61 for (auto &sec : sections) {
62 if (const auto tz = sec.from().timeZone(); tz.isValid()) {
63 sec.setScheduledDepartureTime(TimeUtil::applyTimeZone(sec.scheduledDepartureTime(), tz));
64 sec.setExpectedDepartureTime(TimeUtil::applyTimeZone(sec.expectedDepartureTime(), tz));
65 }
66 if (const auto tz = sec.to().timeZone(); tz.isValid()) {
67 sec.setScheduledArrivalTime(TimeUtil::applyTimeZone(sec.scheduledArrivalTime(), tz));
68 sec.setExpectedArrivalTime(TimeUtil::applyTimeZone(sec.expectedArrivalTime(), tz));
69 }
70
71 auto stops = sec.takeIntermediateStops();
72 for (auto &stop : stops) {
73 StopoverUtil::propagateTimeZone(stop);
74 }
75 sec.setIntermediateStops(std::move(stops));
76 }
77 jny.setSections(std::move(sections));
78}
A journey plan.
Definition journey.h:272
QDateTime scheduledDepartureTime
Departure time of the journey, according to schedule.
Definition journey.h:277
QVariantList sections
Journey sections for consumption by QML.
Definition journey.h:275
void setSections(std::vector< JourneySection > &&sections)
Sets the journey sections.
Definition journey.cpp:700
std::vector< JourneySection > && takeSections()
Moves the journey sections out of this object.
Definition journey.cpp:694
void stop(Ekos::AlignState mode)
Query operations and data types for accessing realtime public transport information from online servi...
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.