function updateTime(){
var clock = $("#clock");
var currentTime = moment().utcOffset('-05:00');
var startOfDay = moment("9:30am", "H:mmA").utcOffset('-05:00');
var endOfDay = moment("11:30pm", "H:mmA").utcOffset('-05:00');
if(currentTime > startOfDay && currentTime < endOfDay){
clock.show();
clock.html(endOfDay.countdown(currentTime).toString());
}else{
clock.html("Guessing is Closed");
clock.hide();
}
}
setInterval(updateTime, 1000);
I really enjoyed working with Moment.js, having an app in which the current time dictates other behavior is particularly intriguing.
Working with dates and times was something I had never considered doing with Javascript before.
I need to add to this function to account for the stock market being closed on Saturday and Sunday,
as well as making it so the 'predict' buttons are removed after the first two hours of market activity have passed.
It's currently set to 11:30'pm' just for demonstration purposes.