Add duration entry dialog
[harbour-pedalo.git] / qml / pages / AddJourney.qml
index 9d7a436..a9124ae 100644 (file)
@@ -79,8 +79,9 @@ Dialog {
                 onClicked: {
                     var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: time.getHours(), minute: time.getMinutes()})
                     dialog.accepted.connect(function() {
-                        time = new Date(0, 0, 0, dialog.hour, dialog.minute)
-                        duration = ((endTime.time.getHours() - start.getHours()) * 60) + (endTime.time.getMinutes() - start.getMinutes()) * 60
+                        // We have to hack around the fact that % in Javascript is 'remainder' and not 'mod' (hence will happpily return negative numbers)
+                        duration = ((((((dialog.hour - start.getHours()) * 60) + (dialog.minute - start.getMinutes())) * 60) % 86400) + 86400) % 86400
+                        // Updating the duration will automatically trigger the end time to be udpated
                     })
                 }
                 onTimeChanged: {
@@ -94,7 +95,7 @@ Dialog {
                 value: Qt.formatTime(new Date(0, 0, 0, 0, parseInt(duration / 60)), 'hh:mm')
                 width: parent.width
                 onClicked: {
-                    var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: parseInt(duration / (60 * 60)), minute: parseInt(duration / 60) % 60})
+                    var dialog = pageStack.push("DurationEditDialog.qml", { hour: parseInt(duration / (60 * 60)), minute: parseInt(duration / 60) % 60})
                     dialog.accepted.connect(function() {
                         duration = ((dialog.hour * 60) + dialog.minute) * 60
                     })