-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.js
49 lines (42 loc) · 1.32 KB
/
script.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
let clockTimer = setInterval(() => {
let now = new Date();
let hr = now.getHours();
hr = hr % 12 || 12;
let mins = now.getMinutes() + "";
if (mins.length === 1) mins = "0" + mins;
document.getElementById("clock").innerHTML = toNpNumber(hr) + ":" + toNpNumber(mins);
}, 1000);
const renderGreeting = () => {
var prefix = "शुभ";
var translations = {
morning: "प्रभात",
noon: "मध्यान्ह",
evening: "सन्ध्या",
night: "रात्री",
};
let trans;
let hourNow = new Date().getHours();
if (hourNow >= 1 && hourNow <= 12) trans = translations.morning;
else if (hourNow > 12 && hourNow <= 16) trans = translations.noon;
else if (hourNow > 16 && hourNow <= 19) trans = translations.evening;
else if (hourNow > 19 && hourNow <= 24) trans = translations.night;
document.getElementById("greeting").innerHTML = prefix + " " + trans;
}
renderGreeting();
const toNpNumber = (number) => {
if (!number) return null;
let dict = {
0: '०',
1: '१',
2: '२',
3: '३',
4: '४',
5: '५',
6: '६',
7: '७',
8: '८',
9: '९',
};
let strNum = number + '';
return strNum.split('').map(n => dict[n] || n).join('');
}