-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateManager.js
More file actions
71 lines (58 loc) · 1.63 KB
/
Copy pathDateManager.js
File metadata and controls
71 lines (58 loc) · 1.63 KB
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
const DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
export default class DateManager {
constructor() {
this.date = new Date();
this.formattedDate = {};
this.time = {};
}
getCurrentDate() {
this.date = new Date();
}
getFormattedDay() {
return DAYS[this.date.getDay()];
}
getFormattedMonth() {
return MONTHS[this.date.getMonth()];
}
getFormattedDate() {
return this.formattedDate;
}
setFormattedDate() {
this.formattedDate = {
day: this.getFormattedDay(),
date: this.date.getDate(),
month: this.getFormattedMonth(),
year: this.date.getFullYear(),
};
}
getFormattedDateString() {
return `${this.formattedDate.day}, ${this.formattedDate.month} ${this.formattedDate.date}, ${this.formattedDate.year}`;
}
appendFormattedDateToDOM(element) {
element.innerHTML = `<p>${this.getFormattedDateString()}</p>`;
}
getFormattedHours() {
return (this.date.getHours() + 24) % 12 || 12;
}
getFormattedMinutes() {
const minutes = this.date.getMinutes();
if (minutes < 10) {
return "0" + minutes;
}
return minutes;
}
getTimeMeridiem() {
if (this.date.getHours() >= 12) {
return "PM";
} else {
return "AM";
}
}
getFormattedTime() {
return `${this.getFormattedHours()}:${this.getFormattedMinutes()}${this.getTimeMeridiem()}`;
}
appendFormattedTimeToDOM(element) {
element.innerHTML = `<p>${this.getFormattedTime()}</p>`;
}
}