Scheduling Engine
A javascript engine for scheduling alerts and content with built in auto-display/removal logic.
HTML
<script type="text/javascript">
function scheduleEngine(sDate, eDate) {
// Declaring Variables
var d = new Date(); // Pulls current date/time
var s = new Date(sDate); // User entered start date/time
var e = new Date(eDate); // User entered end date/time
var dateCheck = 0;
// Checks for the current date
if (d >= s && d <= e) {
dateCheck++;
}
return dateCheck;
}
window.onload = function(){
// Set the start and end dates/times (MM/DD/YY & HH/MM/SS)
dateCheck = scheduleEngine("January 1, 2019 11:59:00", "January 1, 2019 12:00:00");
// Identifies the target DOM element where the message should be appended
var id = 'alert';
// Message to be displayed
var message = document.createTextNode("This is a test message.");
// Expiration message to be displayed
var expirationMessage = document.createTextNode("This message has expired.");
// Checks for condition to be true
if (dateCheck == 1) {
document.getElementById(id).appendChild(message); // Set ID to the targeted element
} else {
document.getElementById(id).appendChild(expirationMessage); // Set ID to the targeted element
}
};
</script>
<div id="alert"></div>
JavaScript
/*
@name Scheduling Engine
@author Peter Burdette
@version 1.0
@license Released under the MIT license.
*/
/* scheduleEngine function would be included in an external file */