Skip to content

Instantly share code, notes, and snippets.

@DannyDelott
Last active July 6, 2019 13:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DannyDelott/2b1583b70f9ad79ebbc5 to your computer and use it in GitHub Desktop.
Save DannyDelott/2b1583b70f9ad79ebbc5 to your computer and use it in GitHub Desktop.
Show time left until noon using Moment.js
var getTimeLeft = function(){
var now = moment();
var deadline = now.clone().hour(12).minute(0),second(0);
if(now.isAfter(deadline) {
// disable RSVP button here
return ‘Closed’;
}else {
// enable RSVP button here
// returns “in x hours”, “in x minutes”, “in a few seconds”
return deadline.from(now);
}
}
@dimanyc
Copy link

dimanyc commented Apr 12, 2018

comma in ... ,second(0) instead of a period. Very cool otherwise

@JohnForbes
Copy link

Also, missing a bracket on line 4, should be: if(now.isAfter(deadline)) {

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