diff --git a/qml/pages/PlotDataPage.qml b/qml/pages/PlotDataPage.qml index 4c4afba..e69b03e 100644 --- a/qml/pages/PlotDataPage.qml +++ b/qml/pages/PlotDataPage.qml @@ -22,6 +22,7 @@ import Sailfish.Share 1.0 import "../modules/GraphData" Page { + id: plotDataPage property var startTime: pageStack.pop().startTime property var endTime: pageStack.pop().endTime @@ -34,15 +35,9 @@ Page { property var humidityData: [] property var pressureData: [] - function calculateUnixTimestamp(day, month, year, start) { + function calculateUnixTimestamp(minute, hour, day, month, year) { var date = new Date(year, month - 1, day); - if (start) { - // Set the time to the start of the day (00:00:00) - date.setHours(0, 0, 0, 0); - } else { - // Set the time to the end of the day (23:59:59) - date.setHours(23, 59, 59, 999); - } + date.setHours(hour, minute, 0, 0); var unixTimestamp = Math.floor(date.getTime() / 1000); return unixTimestamp; } @@ -250,22 +245,29 @@ Page { anchors.top: parent.top width: parent.width - leftMargin - rightMargin anchors.horizontalCenter: parent.horizontalCenter - text: "Start date" + text: "Start time" property bool clicked: false onClicked: { - var dialog = pageStack.push(startPicker, {}) - dialog.accepted.connect(function() { - startDateButton.text = "Start date: " + dialog.dateText - startTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, true) - startDateButton.clicked = true + var startDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {}) + startDatePicker.accepted.connect(function() { + // Ask for time + var startTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", { + hourMode: DateTime.TwentyFourHours, + hour: 0, + minute: 0 + }) + // Set plotDataPage as return destination on accept, + // otherwise we will return to datepicker + startTimePicker.acceptDestinationAction = PageStackAction.Pop + startTimePicker.acceptDestination = plotDataPage + startTimePicker.accepted.connect(function() { + startDateButton.text = "Start time: " + startDatePicker.dateText + " " + startTimePicker.timeText + startTime = calculateUnixTimestamp(startTimePicker.minute, startTimePicker.hour, startDatePicker.day, startDatePicker.month, startDatePicker.year) + startDateButton.clicked = true + }) }) } - - Component { - id: startPicker - DatePickerDialog {} - } } // Whitespace inbetween buttons @@ -281,22 +283,27 @@ Page { anchors.top: whiteSpace.bottom width: parent.width - leftMargin - rightMargin anchors.horizontalCenter: parent.horizontalCenter - text: "End date" + text: "End time" property bool clicked: false onClicked: { - var dialog = pageStack.push(endPicker, {}) - dialog.accepted.connect(function() { - endDateButton.text = "End date: " + dialog.dateText - endTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, false) - endDateButton.clicked = true + var endDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {}) + endDatePicker.accepted.connect(function() { + // Ask for time + var endTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", { + hourMode: DateTime.TwentyFourHours, + hour: 23, + minute: 59 + }) + endTimePicker.acceptDestinationAction = PageStackAction.Pop + endTimePicker.acceptDestination = plotDataPage + endTimePicker.accepted.connect(function() { + endDateButton.text = "End time: " + endDatePicker.dateText + " " + endTimePicker.timeText + endTime = calculateUnixTimestamp(endTimePicker.minute, endTimePicker.hour, endDatePicker.day, endDatePicker.month, endDatePicker.year) + endDateButton.clicked = true + }) }) } - - Component { - id: endPicker - DatePickerDialog {} - } } } }