Commit 93c61f50 authored by Volker Krause's avatar Volker Krause

Use proper duration formatting

parent bb5b112f
......@@ -22,7 +22,7 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX ITINERARY VERSION_HEADER itinerary_ver
# build-time dependencies
find_package(Qt5 5.10 REQUIRED COMPONENTS Test Quick)
find_package(Qt5 CONFIG QUIET OPTIONAL_COMPONENTS QuickCompiler)
find_package(KF5 REQUIRED COMPONENTS I18n)
find_package(KF5 REQUIRED COMPONENTS I18n CoreAddons)
find_package(KF5Holidays 5.49.0 CONFIG QUIET)
find_package(KF5Notifications 5.49.0 CONFIG QUIET)
find_package(KF5Contacts CONFIG REQUIRED)
......
......@@ -61,6 +61,7 @@ target_include_directories(itinerary-app PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(itinerary-app PRIVATE
itinerary
KF5::Contacts
KF5::CoreAddons
KPublicTransport
)
if (TARGET KF5::Notifications)
......
......@@ -31,16 +31,6 @@ Kirigami.ScrollablePage {
Component.onCompleted: _journeyQueryController.queryJourney(batchId);
// TODO localize and move to C++
function displayDuration(dur)
{
if (dur < 60)
return "<1min";
if (dur < 3600)
return Math.floor(dur/60) + "min";
return Math.floor(dur/3600) + ":" + Math.floor((dur % 3600)/60)
}
Component {
id: sectionDelegate
Item {
......@@ -118,13 +108,13 @@ Kirigami.ScrollablePage {
text: {
switch (modelData.mode) {
case JourneySection.PublicTransport:
return modelData.route.line.modeString + " " + modelData.route.line.name + " " + displayDuration(modelData.duration);
return modelData.route.line.modeString + " " + modelData.route.line.name + " " + Localizer.formatDuration(modelData.duration);
case JourneySection.Walking:
return "Walk " + displayDuration(modelData.duration)
return "Walk " + Localizer.formatDuration(modelData.duration)
case JourneySection.Transfer:
return "Transfer " + displayDuration(modelData.duration)
return "Transfer " + Localizer.formatDuration(modelData.duration)
case JourneySection.Waiting:
return "Wait " + displayDuration(modelData.duration)
return "Wait " + Localizer.formatDuration(modelData.duration)
return "???";
}}
}
......@@ -180,7 +170,7 @@ Kirigami.ScrollablePage {
}
QQC2.Label {
text: displayDuration(journey.duration)
text: Localizer.formatDuration(journey.duration)
}
}
}
......
......@@ -94,3 +94,8 @@ QString Localizer::formatDateTime(const QVariant& obj, const QString& propertyNa
}
return s;
}
QString Localizer::formatDuration(int seconds) const
{
return KFormat().formatDuration(seconds * 1000, KFormat::HideSeconds);
}
......@@ -37,6 +37,7 @@ public:
Q_INVOKABLE QString formatAddress(const QVariant &obj) const;
Q_INVOKABLE QString formatTime(const QVariant &obj, const QString &propertyName) const;
Q_INVOKABLE QString formatDateTime(const QVariant &obj, const QString &propertyName) const;
Q_INVOKABLE QString formatDuration(int seconds) const;
};
#endif // LOCALIZER_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