I have this code that does the calculation to find the localized UTC time. Based on this UTC time, there is another function that will calculate the next date and time of the event for me. If the time is between Sunday @ 12 and Wednesday @ 8, it will give me the date of the event due to the intrusion, otherwise it will give me the next date of the event on Sunday. Then I take this settlement date, separate it and pass it as a parameter to the countdown timer.
I am wondering if there is a more optimized way to do this, especially with conditional statements, and where do I divide the time into parameters.
$(function () {
function calcLocalizedTime() {
var d = new Date();
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000 * -5));
return nd;
}
function calcNextWebCast(date) {
var localizedTime = new Date(date||new Date());
var nextDate = new Date(date||new Date());
var today = localizedTime.getDay() + '' + localizedTime.getHours();
if (today >= 012 && today <=320 ) {
nextDate.setDate(nextDate.getDate() + (3 - 1 - nextDate.getDay() + 7) % 7 + 1);
nextDate.setHours(20,0,0,0);
} else {
nextDate.setDate(nextDate.getDate() + (3 - 4 - nextDate.getDay() + 7) % 7 + 1);
nextDate.setHours(12,0,0,0);
}
return nextDate;
}
var localizedTime = calcLocalizedTime();
var nextWebCast = calcNextWebCast(localizedTime);
var m = nextWebCast.getMonth() + 1;
var d = nextWebCast.getDate();
var y = nextWebCast.getFullYear();
var hh = nextWebCast.getHours();
var mm = nextWebCast.getMinutes();
$('#defaultCountdown').countdown({until: $.countdown.UTCDate(-5, y, m-1, d, hh, mm)});
});