Skip to content

Instantly share code, notes, and snippets.

@AaronGoldsmith1
Last active November 28, 2016 23:34
Show Gist options
  • Save AaronGoldsmith1/351d230da89e946fb83ba6d40eb435e5 to your computer and use it in GitHub Desktop.
Save AaronGoldsmith1/351d230da89e946fb83ba6d40eb435e5 to your computer and use it in GitHub Desktop.
Countdown timer
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment