From 7e98b92259f668723f94d3d95c5efabce2cc0c2d Mon Sep 17 00:00:00 2001 From: mma37 Date: Wed, 6 Jan 2021 20:19:19 +0400 Subject: [PATCH] Fixes #28 #9 Co-authored-by: Farhan Alvi Co-authored-by: flxp49 --- PrayerWindow/view.js | 17 +++++++++++++---- app.js | 12 ++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/PrayerWindow/view.js b/PrayerWindow/view.js index b48e50d..442f48a 100644 --- a/PrayerWindow/view.js +++ b/PrayerWindow/view.js @@ -21,14 +21,23 @@ export function startUpdating(currentTimestamp, currentDayPrayerData, arr) { // console.log(`${waqt}: ${currentDayPrayerData[`${waqt}`]}`) } + // Displaying the current and next prayers $("#first-prayer").text(getKeyByValue(currentDayPrayerData, currentPrayerTime)) $("#second-prayer").text(`left until ${getKeyByValue(currentDayPrayerData, nextPrayerTime)}`) - let hourInMs = nextPrayerTime.getHours() * 60 * 60 * 1000 - currentHour * 60 * 60 * 1000 - let minInMs = nextPrayerTime.getMinutes() * 60 * 1000 - currentMinute * 60 * 1000 + // getting the time in ms and taking account of 0 hour value + let nextPrayerTimeHour = nextPrayerTime.getHours() == 0 ? 24 : nextPrayerTime.getHours() + let nextPrayerTimeinMs = nextPrayerTimeHour * 60 * 60 * 1000 + nextPrayerTime.getMinutes() * 60 * 1000 + let currentTimeinMs = currentHour * 60 * 60 * 1000 + currentMinute * 60 * 1000 - let hoursDifference = Math.floor(hourInMs / 1000 / 60 / 60) - let minutesDifference = Math.floor(minInMs / 1000 / 60) + //calculating the final time in ms + let finalTimeInMs = nextPrayerTimeinMs - currentTimeinMs + + // getting the final hour and minutes + let hoursDifference = Math.floor(finalTimeInMs / 1000 / 60 / 60) + let minutesDifference = Math.floor(finalTimeInMs / 1000 / 60) - hoursDifference * 60 + + // Displaying the time left $("#time-left").text(`${hoursDifference}h${minutesDifference}m`) }, 1000) diff --git a/app.js b/app.js index c6a852d..28118e1 100644 --- a/app.js +++ b/app.js @@ -1,13 +1,13 @@ -import { initPrayerModel } from "./PrayerWindow/model"; -import { initPrayerView } from "./PrayerWindow/processing"; +import { initPrayerModel } from "./PrayerWindow/model" +import { initPrayerView } from "./PrayerWindow/processing" document.addEventListener( "deviceready", function () { // update the file system - initPrayerModel(); - // update the frontend - setTimeout(initPrayerView, 100); + initPrayerModel() + // update the frontend after a delay to let I/O complete + setTimeout(initPrayerView, 50) }, false -); +)