Skip to content

Instantly share code, notes, and snippets.

@leylaso
Created May 12, 2011 13:06
Show Gist options
  • Save leylaso/968450 to your computer and use it in GitHub Desktop.
Save leylaso/968450 to your computer and use it in GitHub Desktop.
Javascript function to show an element only during a specific time, depends on jQuery
// Initialize some variables - we will use GMT times
var checkDate = new Date();
var offTheHourStarts = 21;
var offTheHourEnds = 22;
// Adjust for Daylight savings
if ((checkDate.getMonth() < 2 && checkDate.getMonth() > 10) || (checkDate.getMonth() == 2 && checkDate.getDate()-checkDate.getDay() > 7 ) || (checkDate.getMonth() == 10 && checkDate.getDate()-checkDate.getDay() > 1)) {
offTheHourStarts--;
offTheHourEnds--;
}
/**
* Create a function to display the ckut stream if we are in the right hours
*/
function showCkutStream = function (context) {
var timeDate = new Date();
if (offTheHourStarts < timeDate.getHours()+timeDate.getTimezoneOffset()/60 > offTheHourEnds) {
$('#ckutStream').show();
}
else {
$('#ckutStream').hide();
}
};
/**
* Run the display function every minute
*/
$(document).ready( function() {
$(this).setInterval("showCkutStream()", 60000);
});
@AhoyIndieMedia
Copy link

Can this be used to showcase a certain video embed code at a certain hour - i.e 7pm EST? - should one replace '#ckutStream' - with such code?

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