From: Ant Zucaro <azucaro@gmail.com> Date: Tue, 11 Sep 2012 02:01:54 +0000 (-0400) Subject: Add localized time support (on hover). X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7c5316b773629190d25089000b95c9e6ad6517a0;p=xonotic%2Fxonstat.git Add localized time support (on hover). Without Javascript people will see the UTC time. With Javascript all of those UTC times will be changed to localtime (accounting for DST) via the epoch time of the object. --- diff --git a/xonstat/models.py b/xonstat/models.py index b6ebca1..bbf8bf4 100644 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -39,6 +39,9 @@ class Player(object): def to_dict(self): return {'player_id':self.player_id, 'name':self.nick.encode('utf-8')} + def epoch(self): + return timegm(self.create_dt.timetuple()) + class GameType(object): def __repr__(self): diff --git a/xonstat/templates/base.mako b/xonstat/templates/base.mako index 0386533..3d6af2d 100644 --- a/xonstat/templates/base.mako +++ b/xonstat/templates/base.mako @@ -47,8 +47,20 @@ </%block> <%block name="js"> + <script src="/static/js/jquery-1.7.1.min.js"></script> </%block> + <!-- RELATIVE TIME CONVERSION --> + <script type="text/javascript"> + $('.abstime').each(function(i,e){ + var epoch = e.getAttribute('data-epoch'); + var d = new Date(0); + d.setUTCSeconds(epoch); + e.setAttribute('title', d.toDateString() + ' ' + d.toTimeString()); + }); + </script> + + <!-- GOOGLE ANALYTICS --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-30391685-1']); diff --git a/xonstat/templates/game_info.mako b/xonstat/templates/game_info.mako index 19234e9..141f3a9 100644 --- a/xonstat/templates/game_info.mako +++ b/xonstat/templates/game_info.mako @@ -31,7 +31,7 @@ Game Information <div class="span6"> <h2>Game Detail</h2> <p> - Played: ${game.fuzzy_date()} (${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')})<br /> + Played: <span class="abstime" data-epoch="${game.epoch()}" title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span><br /> Game Type: ${game.game_type_cd}<br /> Server: <a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for ${server.name}">${server.name}</a><br /> Map: <a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for ${map.name}">${map.name}</a><br /> diff --git a/xonstat/templates/main_index.mako b/xonstat/templates/main_index.mako index 64cca89..ca165e4 100644 --- a/xonstat/templates/main_index.mako +++ b/xonstat/templates/main_index.mako @@ -225,7 +225,7 @@ Leaderboard <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td> <td><a href="${request.route_url('server_info', id=server.server_id)}" title="Go to the detail page for this server">${server.name}</a></td> <td><a href="${request.route_url('map_info', id=map.map_id)}" title="Go to the map detail page for this map">${map.name}</a></td> - <td><span title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> <td> % if pgstat.player_id > 2: <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a></td> diff --git a/xonstat/templates/map_index.mako b/xonstat/templates/map_index.mako index 49a97c6..ba5f594 100644 --- a/xonstat/templates/map_index.mako +++ b/xonstat/templates/map_index.mako @@ -29,7 +29,7 @@ Map Index % for map in maps: <tr> <td><a href="${request.route_url("map_info", id=map.map_id)}" title="Go to this map's info page">${map.name}</a></th> - <td><span title="${map.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${map.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${map.epoch()}" title="${map.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${map.fuzzy_date()}</span></td> </td> </tr> % endfor diff --git a/xonstat/templates/map_info.mako b/xonstat/templates/map_info.mako index 21b8589..a16e920 100644 --- a/xonstat/templates/map_info.mako +++ b/xonstat/templates/map_info.mako @@ -21,7 +21,7 @@ ${parent.title()} % else: <h2>${gmap.name}</h2> <p> - Added <span title="${gmap.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${gmap.fuzzy_date()}</span> + Added <span class="abstime" data-epoch="${gmap.epoch()}" title="${gmap.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${gmap.fuzzy_date()}</span> </p> <div class="row"> <div class="span4"> @@ -126,7 +126,7 @@ ${parent.title()} <tr> <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">View</a></td> <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td> - <td><span title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> <td> % if pgstat.player_id > 2: <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a> diff --git a/xonstat/templates/player_index.mako b/xonstat/templates/player_index.mako index 78848d7..320437b 100644 --- a/xonstat/templates/player_index.mako +++ b/xonstat/templates/player_index.mako @@ -29,7 +29,7 @@ Player Index % for player in players: <tr> <td><a href="${request.route_url("player_info", id=player.player_id)}" title="Go to this player's info page">${player.nick_html_colors()|n}</a></th> - <td><span title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${player.joined_pretty_date()}</span></th> + <td><span class="abstime" data-epoch="${player.epoch()}" title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${player.joined_pretty_date()}</span></th> </tr> % endfor </table> diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index f1237d0..3149228 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -182,7 +182,7 @@ Player Information <p> Member Since: <small>${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')} </small><br /> - Last Seen: <small><span title="${recent_games[0][1].create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${recent_games[0][1].fuzzy_date()}</span> </small><br /> + Last Seen: <small><span class="abstime" data-epoch="${recent_games[0][1].epoch()}" title="${recent_games[0][1].create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${recent_games[0][1].fuzzy_date()}</span> </small><br /> Playing Time: <small>${total_stats['alivetime']} </small><br /> @@ -402,7 +402,7 @@ Player Information % endif % endif </td> - <td><span title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> </tr> % endfor </tbody> diff --git a/xonstat/templates/search.mako b/xonstat/templates/search.mako index 45223b2..2b9fb0c 100644 --- a/xonstat/templates/search.mako +++ b/xonstat/templates/search.mako @@ -47,7 +47,7 @@ % for player in results: <tr> <td><a href="${request.route_url("player_info", id=player.player_id)}" name="Player info page for player #${player.player_id}">${player.nick_html_colors()|n}</a></td> - <td><span title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${player.joined_pretty_date()}</span></td> + <td><span class="abstime" data-epoch="${player.epoch()}" title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${player.joined_pretty_date()}</span></td> </tr> % endfor </table> @@ -63,7 +63,7 @@ % for server in results: <tr> <td><a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for server #${server.server_id}">${server.name}</a></td> - <td><span title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${server.epoch()}" title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span></td> </tr> % endfor </table> @@ -79,7 +79,7 @@ % for map in results: <tr> <td><a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for map #${map.map_id}">${map.name}</a></td> - <td><span title="${map.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${map.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${map.epoch()}" title="${map.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${map.fuzzy_date()}</span></td> </tr> % endfor </table> @@ -99,7 +99,7 @@ <td><a class="btn btn-primary btn-small" href="${request.route_url("game_info", id=game.game_id)}" name="Game info page for game #${game.game_id}">View</a></td> <td><a href="${request.route_url("map_info", id=gmap.map_id)}" name="Map info page for map #${gmap.map_id}">${gmap.name}</a></td> <td><a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for server #${server.server_id}">${server.name}</a></td> - <td><span title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> </tr> % endfor </table> diff --git a/xonstat/templates/server_index.mako b/xonstat/templates/server_index.mako index 7559947..3a64f2f 100644 --- a/xonstat/templates/server_index.mako +++ b/xonstat/templates/server_index.mako @@ -29,7 +29,7 @@ Server Index % for server in servers: <tr> <td><a href="${request.route_url("server_info", id=server.server_id)}" title="Go to this server's info page">${server.name}</a></th> - <td><span title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${server.epoch()}" title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span></td> </tr> % endfor </table> diff --git a/xonstat/templates/server_info.mako b/xonstat/templates/server_info.mako index 96875ca..04bf6b4 100644 --- a/xonstat/templates/server_info.mako +++ b/xonstat/templates/server_info.mako @@ -22,7 +22,7 @@ Server Information <p> IP Address: ${server.ip_addr} <br /> Revision: ${server.revision} <br /> - Added <span title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span> <br /> + Added <span class="abstime" data-epoch="${server.epoch()}" title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span> <br /> </p> </div> </div> @@ -139,7 +139,7 @@ Server Information <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">View</a></td> <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td> <td><a href="${request.route_url('map_info', id=map.map_id)}" title="Go to the map detail page for this map">${map.name}</a></td> - <td><span title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> + <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td> <td> % if pgstat.player_id > 2: <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a>