Posted: Fri Jun 29, 2012 12:25 pm
Or we could just redirect back to the server with the appropriate TZ. A second load shouldn't be an issue for something like this.
Space battles since 2000
https://www.freeallegiance.org/forums/
Code: Select all
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<!-- BT - Added to support user's local timezone.
http://www.pageloom.com/automatic-timezone-detection-with-javascript -->
<script type="text/javascript" src="http://cdn.bitbucket.org/pellepim/jstimezonedetect/downloads/jstz.min.js"></script>
<!-- BT - Added to support display of user's local timezone. -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
// BT - Date shift chart data to user's local timezone.
function fixTimezone(timezoneOffsetMinutes, dataArray) {
var timezoneOffsetHours = Math.round(timezoneOffsetMinutes / 60) * -1;
var shiftHours = timezoneOffsetHours;
var output = new Array();
output[0] = dataArray[0];
if(timezoneOffsetHours < 0)
timezoneOffsetHours = 23 + timezoneOffsetHours;
for(var i = 0; i < 24; i++) {
var currentHour = timezoneOffsetHours + i;
if(currentHour > 23)
currentHour -= 24;
dataArray[currentHour + 1][0] = i+':00';
output[i + 1] = dataArray[currentHour + 1];
}
return output;
}
function drawChart(timezoneName, timezoneOffsetMinutes)
{
$("#chart_div").empty();
weekendLabel1 = "Saturday Avg";
weekendLabel2 = "Sunday Avg";
// Once squad game time crosses midnight local time, shift the labels up a day.
if(timezoneOffsetMinutes / 60 >= 4)
{
weekendLabel1 = "Sunday Avg";
weekendLabel2 = "Monday Avg";
}
// BT - Added fixTimezone function to dateshift the chart data.
var data = google.visualization.arrayToDataTable(fixTimezone(timezoneOffsetMinutes, [
['Hour','Weekday Avg',weekendLabel1,weekendLabel2],
['0:00',8.7,3.2,9.8],['1:00',11.2,7.8,13.8],['2:00',11.3,11.8,15.5],['3:00',11.1,13.5,13.5],['4:00',8.0,11.0,9.8],['5:00',5.1,10.5,9.0],['6:00',2.0,7.2,8.5],['7:00',0.8,5.0,7.5],['8:00',0.6,2.0,6.5],['9:00',0.4,1.2,1.8],['10:00',0.8,1.2,2.2],['11:00',1.2,2.2,2.5],['12:00',1.7,3.8,4.0],['13:00',2.3,6.0,4.5],['14:00',2.4,6.0,7.2],['15:00',2.8,6.8,8.8],['16:00',3.3,8.8,9.0],['17:00',4.8,13.2,11.2],['18:00',6.6,13.0,13.5],['19:00',6.4,13.5,23.0],['20:00',7.9,10.8,19.5],['21:00',7.8,8.5,10.8],['22:00',5.9,11.2,11.5],['23:00',7.2,8.2,7.5]
]));
var options = {
curveType: 'function',
backgroundColor: {fill:'transparent'},
title: 'Allegiance Player Playing Patterns (past 30 days)',
vAxis: {title: '# of players', textPosition: 'none'},
// BT - Added user's local timezone name.
hAxis: {title: 'Hour (' + timezoneName + ')', gridlines: {color: '#333', count: 24}, slantedText: true, slantedTextAngle: 90, showTextEvery: 1, textStyle: {color: 'black', fontName: 'Arial', fontSize: 12} }
}
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
// BT - Determine next squad game time in user's local timezone.
$(document).ready(function()
{
var currentTimezoneName = jstz.determine().name();
var currentTimezoneOffsetMinutes = new Date().getTimezoneOffset();
// BT: Add timezone selection dropdown.
var $ddlTimezone = $("#ddlTimezone");
$.each(jstz.olson.timezones, function(offsetMinutesList, zoneName)
{
var offsetMinutes = parseInt(offsetMinutesList.split(",")[0]);
// Ignore any .5 timezones, they will just have to pick a neighbor timezone.
// .5 timezones messes up the date shifter, and the graph legend, etc.
if(offsetMinutes % 60 == 0)
{
// If the local machine is obeying DST, and the timezone has an olson DST start date
// we'll pretend that the timezone should be shown with the DST offset.
var isDST = false;
if(jstz.olson.dst_start_dates[zoneName] != null && jstz.date_is_dst(new Date()) == true)
{
offsetMinutes += 60;
isDST = true;
}
var offsetHours = offsetMinutes / 60;
var offsetString = "UTC";
if(offsetHours >= 0)
offsetString += "+"
offsetString += offsetHours;
var currentStringLength = offsetString.length;
for(var i = 0; i < (10 - currentStringLength); i++)
offsetString += " ";
var selected = "";
if(currentTimezoneName == zoneName)
selected = "selected"
var isDSTString = "";
if(isDST == true)
isDSTString = " (DST}"
$ddlTimezone.append($("<option " + selected + " />").val(offsetMinutes).html(offsetString + zoneName + isDSTString));
$("#ddlTimezone option:last-child").attr("timezoneName", zoneName);
}
});
$ddlTimezone.change(function()
{
var offset = $("#ddlTimezone option:selected").val();
var timezoneName = $("#ddlTimezone option:selected").attr("timezoneName");
drawChart(timezoneName, offset);
updateSquadgameTime(offset, timezoneName);
});
$ddlTimezone.trigger("change");
});
function updateSquadgameTime(timezoneOffsetMinutes, timezoneName)
{
var squadGameTime = new Date();
for(var i = squadGameTime.getUTCDay(); i != 0; i = squadGameTime.getUTCDay())
squadGameTime.setUTCDate(squadGameTime.getUTCDate() + 1);
squadGameTime.setUTCHours(19 + (timezoneOffsetMinutes / 60));
squadGameTime.setUTCMilliseconds(0);
squadGameTime.setUTCMinutes(0);
squadGameTime.setUTCSeconds(0);
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
var squadGameHours = squadGameTime.getUTCHours ( );
var squadGameMonth = month[squadGameTime.getUTCMonth()];
var squadGameDay = squadGameTime.getUTCDate ( );
var squadGameYear = squadGameTime.getUTCFullYear ( );
$("#spanSquadGameTime").html(
squadGameMonth + " " +
squadGameDay + ", " +
squadGameYear + " " + squadGameHours + ":00:00 (" + timezoneName + ")");
}
</script>
</head>
<body>
<!-- BT: Cause the select to be centered. -->
<div style="display: inline-block; text-align: center;">
<div id="chart_div" style="width: 1100px; height: 500px;"></div>
<select id="ddlTimezone" style="font-family: monospace"></select>
</div>
<h3>Next Squad Game Time: <span id="spanSquadGameTime"></span></h3>
<pre>
Special thanks to these contributors:
BackTrak - client side timezone shifting
and all the folks who provided feedback (and convinced me to graph it) on this <a href="http://www.freeallegiance.org/forums/index.php?showtopic=66568">thread</a>
older versions of this program
<a href="http://spathiwa.com/cgi-bin/pp.pl">version 1</a> (only shows 1 week's worth of data)
<a href="http://spathiwa.com/cgi-bin/gpp.pl">version 2</a> (only shows 1 week's worth of data)
<a href="http://spathiwa.com/cgi-bin/spp.pl">version 3</a> (only shows 1 week's worth of data)
<a href="http://spathiwa.com/cgi-bin/mpp.pl">version 4</a> (uses monthly set of data)
</pre>
</body>
</html>Code: Select all
<html>
<head>
<script type="text/javascript">
var timezoneOffsetHours = new Date().getTimezoneOffset() / 60;
var url;
if(timezoneOffsetHours > 0){
url = 'http://spathiwa.com/cgi-bin/tz_mpp3.pl?-'+timezoneOffsetHours;
}else{
url = 'http://spathiwa.com/cgi-bin/tz_mpp3.pl?'+Math.abs(timezoneOffsetHours);
}
this.document.location.href = url;
</script>
</html>Code: Select all
if(timezoneOffsetHours > 0){
url = 'http://spathiwa.com/cgi-bin/tz_mpp3.pl?-'+timezoneOffsetHours;
}else{
url = 'http://spathiwa.com/cgi-bin/tz_mpp3.pl?'+Math.abs(timezoneOffsetHours);
}Code: Select all
url = 'http://spathiwa.com/cgi-bin/tz_mpp3.pl?'+ (timezoneOffsetHours * -1);