Commit 66e471dc authored by Volker Krause's avatar Volker Krause
Browse files

Prepare for removal of the explicit train station timezone column

parent debbe6c2
......@@ -103,26 +103,26 @@ private Q_SLOTS:
{
auto station = KnowledgeDb::stationForIbnr(IBNR{1234567});
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForIbnr({});
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForIbnr(IBNR{8011160});
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Berlin"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Berlin"));
QCOMPARE(station.country, CountryId{"DE"});
station = KnowledgeDb::stationForIbnr(IBNR{8501687});
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Zurich"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Zurich"));
QCOMPARE(station.country, CountryId{"CH"});
// Aachen West, very close to the NL border, should be in DE timezone
station = KnowledgeDb::stationForIbnr(IBNR{8000404});
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Berlin"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Berlin"));
QCOMPARE(station.country, CountryId{"DE"});
}
......@@ -130,15 +130,15 @@ private Q_SLOTS:
{
auto station = KnowledgeDb::stationForUic(UICStation{1234567});
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForUic({});
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForUic(UICStation{1001332});
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Helsinki"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Helsinki"));
QCOMPARE(station.country, CountryId{"FI"});
}
......@@ -146,27 +146,27 @@ private Q_SLOTS:
{
auto station = KnowledgeDb::stationForSncfStationId({});
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForSncfStationId(SncfStationId{"XXXXX"});
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForSncfStationId(SncfStationId{"FRAES"});
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Paris"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Paris"));
QCOMPARE(station.country, CountryId{"FR"});
station = KnowledgeDb::stationForSncfStationId(SncfStationId{QStringLiteral("FRXYT")});
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Paris"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Paris"));
QCOMPARE(station.country, CountryId{"FR"});
station = KnowledgeDb::stationForSncfStationId(SncfStationId{"CHGVA"});
QEXPECT_FAIL("", "Wikidata does not supply ids for non-French stations yet", Continue);
QVERIFY(station.coordinate.isValid());
QEXPECT_FAIL("", "Wikidata does not supply ids for non-French stations yet", Continue);
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Zurich"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Zurich"));
QEXPECT_FAIL("", "Wikidata does not supply ids for non-French stations yet", Continue);
QCOMPARE(station.country, CountryId{"CH"});
}
......@@ -248,6 +248,12 @@ private Q_SLOTS:
QCOMPARE(countryForTimezone(Tz::Asia_Ho_Chi_Minh), CountryId{"VN"});
}
void testTimezoneForCoordinate()
{
using namespace KnowledgeDb;
KnowledgeDb::compareTrainTimezones();
}
void testTimezoneForLocation()
{
using namespace KnowledgeDb;
......@@ -347,27 +353,27 @@ private Q_SLOTS:
{
auto station = KnowledgeDb::stationForIndianRailwaysStationCode(QString());
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
station = KnowledgeDb::stationForIndianRailwaysStationCode(QStringLiteral("NDLS"));
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Asia/Kolkata"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Asia/Kolkata"));
QCOMPARE(station.country, CountryId{"IN"});
station = KnowledgeDb::stationForIndianRailwaysStationCode(QStringLiteral("ndls"));
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
}
void testFinishStationCodeLookup()
{
auto station = KnowledgeDb::stationForVRStationCode(VRStationCode(QStringLiteral("HKI")));
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone("Europe/Helsinki"));
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Helsinki"));
station = KnowledgeDb::stationForVRStationCode(VRStationCode(QStringLiteral("BLÄ")));
QVERIFY(!station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone), QTimeZone());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone());
}
};
......
......@@ -284,10 +284,10 @@ QDateTime ExtractorPostprocessorPrivate::processTrainTripTime(QDateTime dt, cons
QTimeZone tz;
if (station.identifier().startsWith(QLatin1String("sncf:"))) {
const auto record = KnowledgeDb::stationForSncfStationId(KnowledgeDb::SncfStationId{station.identifier().mid(5)});
tz = KnowledgeDb::toQTimeZone(record.timezone);
tz = KnowledgeDb::toQTimeZone(record.timezone());
} else if (station.identifier().startsWith(QLatin1String("ibnr:"))) {
const auto record = KnowledgeDb::stationForIbnr(KnowledgeDb::IBNR{station.identifier().mid(5).toUInt()});
tz = KnowledgeDb::toQTimeZone(record.timezone);
tz = KnowledgeDb::toQTimeZone(record.timezone());
} else if (!station.address().addressCountry().isEmpty()) {
tz = KnowledgeDb::toQTimeZone(KnowledgeDb::timezoneForCountry(KnowledgeDb::CountryId{station.address().addressCountry()}));
}
......
......@@ -35,6 +35,11 @@ static_assert(trainstation_table_size < (1 << (sizeof(TrainStationIndex) * 8)),
}
}
Tz TrainStation::timezone() const
{
return m_timezone;
}
SncfStationId::SncfStationId(const QString& id)
{
if (id.size() != 5) {
......
......@@ -57,8 +57,10 @@ struct TrainStationIdIndex {
*/
struct TrainStation {
Coordinate coordinate;
Tz timezone;
Tz m_timezone;
CountryId country;
KITINERARY_EXPORT Tz timezone() const;
};
/** IBNR station id.
......
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