var timer_markup = ""; var pax_times = [ { region: 'EventUS', shortcode: 'us', start: Date.parse("Friday, 6 January 2017 17:00:00 -0800"), end: Date.UTC(2014, 7, 26, 20, 00, 00), override: false }, { region: 'EventEU', shortcode: 'eu', start: Date.parse("Friday, 6 January 2017 17:00:00 +0100"), end: Date.UTC(2014, 7, 26, 20, 00, 00), override: false }, ] var weekdays = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'Nov.', 'December' ]; function countdown_tick() { var now = new Date(); var timestamp = now.getTime() + now.getTimezoneOffset() * 60; for(var iii=0;iiiFrostwyrm Lair is Live!'); } else if(maintenance_period.start > timestamp) { update_timer(timestamp, maintenance_period.start, '.paxeast-timer .timer.t-' + maintenance_period.shortcode); } else { $('.paxeast-timer .timer.t-' + maintenance_period.shortcode).html('LIVE!') } } } function pretty_date(start_ts, end_ts) { var start = new Date(start_ts); var end = new Date(end_ts); var result = ''; result += format_date(start); result += ' from '; result += format_time(start); if (end > start) { result += ' to '; if (start.toLocaleDateString() != end.toLocaleDateString()) { result += 'the ' result += end.getDate().toOrdinal(); result += ' at '; } result += format_time(end); } return result; } function format_date(date) { var result = ''; result += weekdays[date.getDay()]; //result += ', '; //result += months[date.getMonth()]; //result += ' '; //result += date.getDate().toOrdinal(); return result; } function format_time(date) { var result = ''; result += String(date.getHours()).leftPad(2); result += ':'; result += String(date.getMinutes()).leftPad(2); result = date.toLocaleTimeString(); result = result.replace(/\:00([^\:00]*)$/,'$1'); return result; } function update_timer(now, then, timer_element) { var remaining = Math.floor((then - now) / 1000); var days = Math.floor(remaining / (60 * 60 * 24)); remaining %= (60 * 60 * 24); var hours = Math.floor(remaining / (60 * 60)); hours = hours + days * 24; remaining %= (60 * 60); var minutes = Math.floor(remaining / 60); remaining %= 60; var seconds = remaining; console.log(days) if (days < 10) { days = "0" + hours.toString(); } if (hours < 10) { hours = "0" + hours.toString(); } if (minutes < 10) { minutes = "0" + minutes.toString(); } if (seconds < 10) { seconds = "0" + seconds.toString(); } $(timer_element + ' .group.days .counter').html(days); $(timer_element + ' .group.hours .counter').html(hours); $(timer_element + ' .group.minutes .counter').html(minutes); $(timer_element + ' .group.seconds .counter').html(seconds); } function countdown(now, then) { var remaining = Math.floor((then - now) / 1000); var days = Math.floor(remaining / (60 * 60 * 24)); remaining %= (60 * 60 * 24); var hours = Math.floor(remaining / (60 * 60)); remaining %= (60 * 60); var minutes = Math.floor(remaining / 60); remaining %= 60; var seconds = remaining; var values = new Array(); if (days > 0) values.push({ unit: "day", value: days }); if (hours > 0) values.push({ unit: "hr", value: hours }); if (minutes > 0) values.push({ unit: "min", value: minutes }); if ((seconds > 0) && (values.length < 2) && days < 1) values.push({ unit: "sec", value: seconds }); var result = ''; var last = values[values.length - 1]; for (var i = 0; i < values.length - 1; i++) { if (result.length > 0) result += ", "; result += values[i].value + " " + values[i].unit; if (values[i].value > 1) result += "s"; } if (result.length > 0) result += " and "; result += last.value + " " + last.unit; if (last.value > 1) result += "s"; return result; } countdown_tick(); window.setInterval(countdown_tick, 1000);