]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add localized time support (on hover).
authorAnt Zucaro <azucaro@gmail.com>
Tue, 11 Sep 2012 02:01:54 +0000 (22:01 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 11 Sep 2012 02:01:54 +0000 (22:01 -0400)
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.

xonstat/models.py
xonstat/templates/base.mako
xonstat/templates/game_info.mako
xonstat/templates/main_index.mako
xonstat/templates/map_index.mako
xonstat/templates/map_info.mako
xonstat/templates/player_index.mako
xonstat/templates/player_info.mako
xonstat/templates/search.mako
xonstat/templates/server_index.mako
xonstat/templates/server_info.mako

index b6ebca1b145c212170c0a287df654c3440b42bab..bbf8bf416009a1bedea531fcb3fbd0690a65cf1c 100644 (file)
@@ -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):
index 03865330cc194c4b41134cf7b526ee2d7414fbae..3d6af2dc01da957f4c0e2e10f4465ea2ca49bd4a 100644 (file)
       </%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']);
index 19234e9ec42aa41f516d24d55d623872bdc349e2..141f3a9c65826cd435ff4068094a5f3e42b22fe3 100644 (file)
@@ -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 />
index 64cca8919bd504bc9bc15976ab51481330c2098a..ca165e46c6fd3c80243831ad02411b649a27a293 100644 (file)
@@ -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>
index 49a97c6a9ada0f295673b66466ea0991e23eccf2..ba5f5945cf393e1d0d333c7a031b0349a7977c52 100644 (file)
@@ -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
index 21b85896fbd86f827c998555ce5deff6f016d696..a16e92087385e8192371d9e18ab1e9d6f009ff0a 100644 (file)
@@ -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>
index 78848d73ae46b3b25625cf5783fff5abbcee8c04..320437b8e3bbb8af3a3c1f9aae501173a0457960 100644 (file)
@@ -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>
index f1237d0a5adbde244ddcd8f7c154ea0405ff724a..3149228e486c7b5c168efd5d4f43486818ba715f 100644 (file)
@@ -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>
index 45223b25f2e9adb44a18ba5451c2b11bc2043e4c..2b9fb0c9d92150fc19fd4e1d05e0e27380082029 100644 (file)
@@ -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>
index 755994739adfd8494e846476c41dd5ae6a0880a6..3a64f2f3d8fb72e84fa9da2e3b36d4096f34a2ba 100644 (file)
@@ -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>
index 96875ca0315f86f50614d7fd505d5a2b44fb0687..04bf6b455d37065478b019c560e0a286ad698a60 100644 (file)
@@ -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>