2012-03-31 15:55:42 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from genshi.builder import tag
|
|
|
|
from genshi import Markup
|
|
|
|
from trac.wiki.macros import WikiMacroBase
|
|
|
|
from trac.util.translation import _
|
|
|
|
from trac.web.chrome import add_script
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from pkg_resources import resource_filename
|
|
|
|
|
|
|
|
class CountDownMacro(WikiMacroBase):
|
|
|
|
|
|
|
|
"""Renders an overview of active RendezVouses"""
|
|
|
|
|
|
|
|
revision = "$Rev$"
|
|
|
|
url = "$URL$"
|
|
|
|
def expand_macro(self, formatter, name, content):
|
|
|
|
try:
|
|
|
|
event_datetime = datetime(*tuple(time.strptime("2010, 07, 16", "%Y, %m, %d"))[:3])
|
|
|
|
except Exception:
|
|
|
|
return ""
|
2012-04-25 05:30:22 +00:00
|
|
|
dt = event_datetime - datetime.utcnow()
|
2012-03-31 15:55:42 +00:00
|
|
|
hours = "%d:%d" % (dt.seconds / 3600, (dt.seconds % 3600) / 60)
|
|
|
|
days = str(dt.days)
|
|
|
|
return Markup("""
|
|
|
|
<script type='text/javascript'>
|
|
|
|
<!--
|
|
|
|
var now = new Date();
|
|
|
|
var year = now.getYear();
|
|
|
|
if (year < 1900) {
|
|
|
|
year += 1900;
|
|
|
|
}
|
|
|
|
var end = new Date(2009, 6, 17, 17, 0, 0);
|
|
|
|
|
|
|
|
function toSt2(n) {
|
|
|
|
s = "";
|
|
|
|
if (n < 10) s += "0";
|
|
|
|
return (s + n).toString();
|
|
|
|
}
|
|
|
|
function toSt3(n) {
|
|
|
|
s = "";
|
|
|
|
if (n < 10) s += "00";
|
|
|
|
else if (n < 100) s += "0";
|
|
|
|
return (s + n).toString();
|
|
|
|
}
|
|
|
|
function countdown() {
|
|
|
|
d = new Date();
|
|
|
|
count = Math.floor(end.getTime() - d.getTime());
|
|
|
|
if(count > 0) {
|
|
|
|
miliseconds = toSt3(count%%1000); count = Math.floor(count/1000);
|
|
|
|
seconds = toSt2(count%%60); count = Math.floor(count/60);
|
|
|
|
minutes = toSt2(count%%60); count = Math.floor(count/60);
|
|
|
|
hours = toSt2(count%%24); count = Math.floor(count/24);
|
|
|
|
days = count;
|
|
|
|
document.getElementById('c1').innerHTML = days + ' TAGE';
|
|
|
|
document.getElementById('c2').innerHTML = hours + ':' + minutes + ':' + seconds + '.' + miliseconds + '';
|
|
|
|
setTimeout("countdown()", 50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//-->
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div style="border:2px solid #fff;padding:10px;-moz-border-radius:17px;-khtml-border-radius:17px;-webkit-border-radius:17px;text-align:center;display:inline-block;">
|
|
|
|
<h2>CountDown</h2>
|
|
|
|
<span id="c1" style="font: bold 30px arial; border:1px solid #000; color:#fff;margin:5px;"> %s Tage</span>
|
|
|
|
<span id="c2" style="font: bold 25px arial; border:1px solid #000; color:#fff;margin:5px;"> %s </span>
|
|
|
|
<script language="javascript" type="text/javascript">countdown();</script>
|
|
|
|
</div>""" % (days, hours))
|