forked from extern/the-glorious-startpage
ae6e1254ea
* fix paddings on screen * fix test Variable Assigned to Object Injection Sink * fix parse int missing base * fix security issues(regex not included) * fix missing base * fixes padding * minor fixes * regex * cleanup * minor cleanup in webmenu * cleanups * cleanups spaces to tab * cleanups * spacing tabs fixes test * cleanup * cleanup * multitransition new line * cleanup * cleanup * cleanup * cleanup * readme * comments * cleanup * Avoid assignments in operands * cleanup
61 lines
1.2 KiB
JavaScript
61 lines
1.2 KiB
JavaScript
class GreeterDateMessage {
|
|
|
|
constructor() {
|
|
this._greeterMessage = document.querySelector('#greeterMessage');
|
|
this._dateMessage = document.querySelector('#dateMessage');
|
|
|
|
this._monthsArr = [
|
|
'January',
|
|
'February',
|
|
'March',
|
|
'April',
|
|
'May',
|
|
'June',
|
|
'July',
|
|
'August',
|
|
'September',
|
|
'October',
|
|
'November',
|
|
'December'
|
|
];
|
|
|
|
this._daysArr = [
|
|
'Sunday',
|
|
'Monday',
|
|
'Tuesday',
|
|
'Wednesday',
|
|
'Thursday',
|
|
'Friday',
|
|
'Saturday'
|
|
];
|
|
|
|
this._updateGreeterDateMessage();
|
|
}
|
|
|
|
_getDayOrdinal = (day) => {
|
|
return day + (day > 0 ? ['th', 'st', 'nd', 'rd'][(day > 3 && day < 21) ||
|
|
day % 10 > 3 ? 0 : day % 10] : '');
|
|
}
|
|
|
|
_updateGreeterDateMessage = () => {
|
|
|
|
const date = new Date();
|
|
const hour = date.getHours();
|
|
let greeterSuffix = '';
|
|
|
|
if (hour >= 6 && hour < 12) {
|
|
greeterSuffix = 'Morning';
|
|
|
|
} else if (hour >= 12 && hour < 18) {
|
|
greeterSuffix = 'Afternoon';
|
|
|
|
} else {
|
|
greeterSuffix = 'Evening';
|
|
}
|
|
|
|
this._greeterMessage.innerText = `Good\n${greeterSuffix}!`;
|
|
this._dateMessage.innerText = `Today's the ${this._getDayOrdinal(date.getDate())} of ` +
|
|
`${this._monthsArr[date.getMonth()]}, and it's ${this._daysArr[date.getDay()]}.`;
|
|
}
|
|
|
|
} |