$(function(){
var note = $('#note'),
ts = new Date(2017, 0, 1),
newYear = true;
if((new Date()) > ts){
// The new year is here! Count towards something else.
// Notice the *1000 at the end - time must be in milliseconds
ts = (new Date()).getTime() + 30*24*60*60*1000;
newYear = false;
}
$('#countdown').countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " day" + ( days==1 ? '':'s' ) + ", ";
message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " <br />";
if(newYear){
message += "left until the new year!";
}
else {
message += "left to 10 days from now!";
}
note.html(message);
}
});
});
var nYrCo = (
function (){
//ts - timer stop, newYear -flag if it`s true that says , The new year is here
var ts = new Date(2018, 0, 1),
now = new Date(),
tshs=ts.toString().split(" "),
tds = now.toString().split(" "),
tsm=tshs[4].split(":"),
ths = tds[4].split(":");
newYear = false,
countdown = ({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
if(ts.getTime()-now.getTime()<0){
// The new year is here! Count towards something else.
// Notice the *1000 at the end - time must be in milliseconds
ts = (new Date()).getTime() + 30*24*60*60*1000;
newYear = true;
}
var message = " ";
message += days + " day" + ( days==1 ? '':'s' ) + ", ";
message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
message += minutes + " minute" + ( minutes==1 ? '':'s' ) ;
if(newYear){
message = " Congratulate! The new year has come! ";
}
else {
message += " later, will come New Year!";
}
return message
}(31-tds[2],24-tsm[0],60-tsm[1])
});
return countdown
}
);
nYrCo();