-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayground.js
50 lines (43 loc) · 1.13 KB
/
playground.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const prayers = [
{
name: "Fajr",
time: "02:37:00"
},
{
name: "Zuhr",
time: "11:44:00"
},
{
name: "Asr",
time: "15:33:00"
},
{
name: "Maghrib",
time: "19:01:00"
},
{
name: "Isha",
time: "20:34:00"
}
];
const now = new Date("2018-06-25T12:24:00");
// const now = new Date();
let nextPrayer = null;
for (let i = 0; i < prayers.length - 1; i++) {
const firstPrayer = prayers[i];
const secondPrayer = prayers[i + 1];
const firstTime = firstPrayer.time.split(":");
const firstPrayerDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), parseInt(firstTime[0]), parseInt(firstTime[1]), parseInt(firstTime[2]));
const secondTime = secondPrayer.time.split(":");
const secondPrayerDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), parseInt(secondTime[0]), parseInt(secondTime[1]), parseInt(secondTime[2]));
if (now >= firstPrayerDate && now <= secondPrayerDate) {
nextPrayer = secondPrayer;
break;
}
}
if (nextPrayer == null) {
nextPrayer = prayers[0];
}
console.log(
`${nextPrayer.name} prayer at ${nextPrayer.time}. The time now is ${now}`
);