Skip to content

Instantly share code, notes, and snippets.

@pthrasher
Created September 12, 2011 19:19
Show Gist options
  • Save pthrasher/1212109 to your computer and use it in GitHub Desktop.
Save pthrasher/1212109 to your computer and use it in GitHub Desktop.
figures out the date for next sunday, and then runs the counter off of that.
<script language="javascript" type="text/javascript">
function nextSunday(){
var d = new Date(),
day = 86400000;
var dayMult = 0,
currDay = d.getDay();
if (currDay < 1) {
// it's sunday
// is it past 8:55am?
if (d.getHours() > 8 || (d.getHours() == 8 && d.getMinutes() >= 55)) {
//we need to look for next sunday
dayMult = 7
} else {
dayMult = 1
}
} else {
dayMult = 7 - currDay;
}
d.setHours(8);
d.setMinutes(55);
var realDate = new Date(d.getTime() + (day * dayMult));
return {
day: realDate.getUTCDate(),
month: realDate.getUTCMonth() + 1,
year: realDate.getUTCFullYear(),
hour: 12 + (-(realDate.getTimezoneOffset()/60)),
min: 55,
sec: 0
}
}
function counter(el){
var self = $(el),
_el = el,
d = nextSunday();
self.countDown({
targetDate: {
'day': d.day,
'month': d.month,
'year': d.year,
'hour': d.hour,
'min': d.min,
'sec': d.sec
},
// onComplete function
onComplete: function() {
self.stopCountDown();
counter(_el);
}
});
}
jQuery(document).ready(function() {
counter("#countdown_dashboard");
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment