Commit 5df7b94e authored by Volker Krause's avatar Volker Krause
Browse files

Propagate static timezones to intermediate stops as well

parent d4772668
Pipeline #71798 passed with stage
in 17 seconds
......@@ -74,6 +74,7 @@ target_sources(KPublicTransport PRIVATE
datatypes/rentalvehicleutil.cpp
datatypes/stopover.cpp
datatypes/stopoverutil.cpp
datatypes/timeutil.cpp
datatypes/vehicle.cpp
gbfs/gbfs.cpp
......
......@@ -6,6 +6,8 @@
#include "journeyutil_p.h"
#include "lineutil_p.h"
#include "stopoverutil_p.h"
#include "timeutil_p.h"
#include <KPublicTransport/Journey>
#include <KPublicTransport/Stopover>
......@@ -36,32 +38,20 @@ bool JourneyUtil::firstTransportDepartureEqual(const Journey &lhs, const Journey
return firstTransportDeparture(lhs) == firstTransportDeparture(rhs);
}
static QDateTime applyTimeZone(QDateTime dt, const QTimeZone &tz)
{
if (!dt.isValid()) {
return dt;
}
switch (dt.timeSpec()) {
case Qt::LocalTime:
dt.setTimeZone(tz);
break;
case Qt::UTC:
dt = dt.toTimeZone(tz);
break;
default:
break;
}
return dt;
}
void JourneyUtil::applyTimeZone(Journey &jny, const QTimeZone &tz)
{
auto sections = std::move(jny.takeSections());
for (auto &sec : sections) {
sec.setScheduledDepartureTime(applyTimeZone(sec.scheduledDepartureTime(), tz));
sec.setExpectedDepartureTime(applyTimeZone(sec.expectedDepartureTime(), tz));
sec.setScheduledArrivalTime(applyTimeZone(sec.scheduledArrivalTime(), tz));
sec.setExpectedArrivalTime(applyTimeZone(sec.expectedArrivalTime(), tz));
sec.setScheduledDepartureTime(TimeUtil::applyTimeZone(sec.scheduledDepartureTime(), tz));
sec.setExpectedDepartureTime(TimeUtil::applyTimeZone(sec.expectedDepartureTime(), tz));
sec.setScheduledArrivalTime(TimeUtil::applyTimeZone(sec.scheduledArrivalTime(), tz));
sec.setExpectedArrivalTime(TimeUtil::applyTimeZone(sec.expectedArrivalTime(), tz));
auto stops = sec.takeIntermediateStops();
for (auto &stop : stops) {
StopoverUtil::applyTimeZone(stop, tz);
}
sec.setIntermediateStops(std::move(stops));
}
jny.setSections(std::move(sections));
}
......
......@@ -6,6 +6,7 @@
#include "stopoverutil_p.h"
#include "lineutil_p.h"
#include "timeutil_p.h"
#include <KPublicTransport/Stopover>
#include <KPublicTransport/StopoverRequest>
......@@ -39,21 +40,12 @@ bool StopoverUtil::timeEqual(const StopoverRequest &req, const Stopover &lhs, co
}
}
static QDateTime applyTimeZone(QDateTime dt, const QTimeZone &tz)
{
if (!dt.isValid() || dt.timeSpec() != Qt::LocalTime) {
return dt;
}
dt.setTimeZone(tz);
return dt;
}
void StopoverUtil::applyTimeZone(Stopover &dep, const QTimeZone &tz)
{
dep.setScheduledDepartureTime(applyTimeZone(dep.scheduledDepartureTime(), tz));
dep.setExpectedDepartureTime(applyTimeZone(dep.expectedDepartureTime(), tz));
dep.setScheduledArrivalTime(applyTimeZone(dep.scheduledArrivalTime(), tz));
dep.setExpectedArrivalTime(applyTimeZone(dep.expectedArrivalTime(), tz));
dep.setScheduledDepartureTime(TimeUtil::applyTimeZone(dep.scheduledDepartureTime(), tz));
dep.setExpectedDepartureTime(TimeUtil::applyTimeZone(dep.expectedDepartureTime(), tz));
dep.setScheduledArrivalTime(TimeUtil::applyTimeZone(dep.scheduledArrivalTime(), tz));
dep.setExpectedArrivalTime(TimeUtil::applyTimeZone(dep.expectedArrivalTime(), tz));
}
void StopoverUtil::applyMetaData(Stopover &dep, bool download)
......
/*
SPDX-FileCopyrightText: 2019-2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "timeutil_p.h"
#include <QDateTime>
#include <QTimeZone>
using namespace KPublicTransport;
QDateTime TimeUtil::applyTimeZone(QDateTime dt, const QTimeZone &tz)
{
if (!dt.isValid()) {
return dt;
}
switch (dt.timeSpec()) {
case Qt::LocalTime:
dt.setTimeZone(tz);
break;
case Qt::UTC:
dt = dt.toTimeZone(tz);
break;
default:
break;
}
return dt;
}
/*
SPDX-FileCopyrightText: 2019-2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPUBLICTRANSPORT_TIMEUTIL_P_H
#define KPUBLICTRANSPORT_TIMEUTIL_P_H
class QDateTime;
class QTimeZone;
namespace KPublicTransport {
/** Utilities for dealing with date/time values. */
namespace TimeUtil
{
QDateTime applyTimeZone(QDateTime dt, const QTimeZone &tz);
}
}
#endif // KPUBLICTRANSPORT_TIMEUTIL_P_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment