-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.js
120 lines (114 loc) · 3.74 KB
/
ui.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class Ui{
constructor(){
this.date = document.getElementById('date');
this.time = document.getElementById('time');
this.location = document.getElementById('loc-name');
this.weather = document.getElementById('weather');
this.temp = document.getElementById('temp');
this.feelLike = document.getElementById('feel-like');
this.weatherIcon = document.getElementById('weather-icon');
this.humidity = document.getElementById('humidity');
this.description = document.getElementById('Description');
this.wind = document.getElementById('wind');
this.pressure = document.getElementById('pressure');
}
showData(data){
this.location.innerText = data.name;
this.temp.innerText = `${data.main.temp} ° C` ;
this.feelLike.innerText = `Feels Like : ${data.main.feels_like} ° C` ;
this.humidity.innerText = `${data.main.humidity} %`;
this.description.innerText = data.weather[0].description;
this.pressure.innerText = `${data.main.pressure} hPa`;
this.wind.innerText = `${(parseFloat(data.wind.speed) * 1.609).toPrecision(2)} Kmph`;
const iconUrl = `http://openweathermap.org/img/w/${data.weather[0].icon}.png`;
this.weather.innerText = data.weather[0].main;
this.weatherIcon.setAttribute('src',iconUrl);
const date = new Date;
let month = '';
switch (date.getMonth()) {
case 0:
month = 'Jan';
break;
case 1:
month = 'Feb';
break;
case 2:
month = 'Mar';
break;
case 3:
month = 'April';
break;
case 4:
month = 'May';
break;
case 5:
month = 'June';
break;
case 6:
month = 'July';
break;
case 7:
month = 'Aug';
break;
case 8:
month = 'Sept';
break;
case 9:
month = 'Oct';
break;
case 10:
month = 'Nov';
break;
case 11:
month = 'Dec';
break;
default:
break;
}
let hours = date.getHours(),
suffix = '',
minutes = '';
switch (date.getHours()) {
case 13:
hours = '01';
break;
case 14:
hours = '02';
break;
case 15:
hours = '03';
break;
case 16:
hours = '04';
break;
case 17:
hours = '05';
break;
case 18:
hours = '06';
break;
case 19:
hours = '07';
break;
case 20:
hours = '08';
break;
case 21:
hours = '09';
break;
case 22:
hours = '10';
break;
case 23:
hours = '11';
break;
case 24:
hours = '12';
break;
}
(date.getHours() > 12) ? suffix = 'pm' : suffix = 'am';
(date.getMinutes() < 10) ? minutes = '0' + date.getMinutes() : minutes = date.getMinutes();
this.date.innerHTML = `<span>${month} </span> <span>${date.getDate()} </span> `;
this.time.innerHTML = `<span>${hours} :</span> <span>${minutes} </span> <span>${suffix}</span> `;
}
}