-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
44 lines (38 loc) · 1.46 KB
/
events.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
const months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
export const createEvent = (event) => {
const eventTime = new Date(event.time);
const eventListing = document.createElement('article');
eventListing.id = event.title;
eventListing.className = "event";
const eventImg = document.createElement('img');
const eventTitle = document.createElement('h3');
const eventLocation = document.createElement('p');
const eventTimeElement = document.createElement('p');
const eventDesc = document.createElement('p');
eventTitle.innerText = event.title;
eventLocation.innerText = event.location;
eventTimeElement.innerText = formateTime(eventTime);
eventDesc.innerText = event.desc.slice(0, 45) + "...";
eventImg.src = event.image;
eventImg.alt = event.title;
eventListing.append(eventImg, eventTitle, eventTimeElement, eventLocation, eventDesc);
return eventListing;
}
const formateTime = (time) => {
let timeString = "";
if (time.getHours() > 12) {
timeString += (time.getHours() - 12);
if (time.getMinutes() != 0){
timeString += ":" + time.getMinutes();
}
timeString += " PM";
} else {
timeString += time.getHours();
if (time.getMinutes() != 0){
timeString += ":" + time.getMinutes();
}
timeString += " AM";
}
timeString += " " + months[time.getMonth()] + " " + time.getDate() + " " + time.getFullYear();
return timeString;
}