timezone related fixes

This commit is contained in:
Stefan Kögl 2012-04-24 12:25:53 +02:00
parent 512dcd24e4
commit c7febbd642
15 changed files with 45 additions and 41 deletions

View File

@ -133,21 +133,14 @@ def time_parse(arg):
def datetime_parse(arg, tzinfo=utc):
"""converts a datetime string of form dd.mm.yyyy MM:HH into a
"""converts a datetime string of form dd.mm.yyyy MM:HH into a localized
datetime.datetime obj"""
# get real tzinfo for the date taking dst into account
arg = datetime.strptime(arg, "%d.%m.%Y %H:%M").replace(tzinfo=tzinfo)
return local_to_utc(arg, tzinfo)
astimezone = tzinfo.localize(datetime.strptime(arg, "%d.%m.%Y %H:%M")).astimezone(utc)
return astimezone
def local_to_utc(arg, tzinfo=utc):
"""converts local datetime to utc datetime"""
real_tz = tzinfo.fromutc(arg).tzinfo
return datetime(arg.year, arg.month, arg.day, arg.hour, arg.minute,
arg.second, tzinfo=real_tz).astimezone(utc)
def get_tz(session_tzname):
"""returns the timezone name and the timezone of the actual trac session"""

View File

@ -17,7 +17,7 @@ def add_doc(global_event, selected_tz, f):
#f.write(u".. header::\n")
#f.write(u" ###Page###\n")
#f.write(u" ###Title###\n")
dt = selected_tz.fromutc(datetime.now(utc)).strftime("%d.%m.%Y %H:%M")
dt = utc.localize(datetime.utcnow()).strftime("%d.%m.%Y %H:%M")
d = u"Erstellt am: %s\n\n" % dt
f.write(d)

View File

@ -37,8 +37,8 @@ a.existing_occurence, a.existing-occurence:visited {color:#00f;}
if hasattr(event, "followups"):
l = []
for ev in event.followups:
local_time_begin = selected_tz.fromutc(ev.time_begin)
local_time_end = selected_tz.fromutc(ev.time_end)
local_time_begin = ev.time_begin.astimezone(selected_tz)
local_time_end = ev.time_end.astimezone(selected_tz)
link_label = "%s %s - %s %s" % (local_time_begin.strftime("%d.%m.%Y %H:%M"), local_time_begin.tzinfo.tzname(None), local_time_end.strftime("%d.%m.%Y %H:%M"), local_time_end.tzinfo.tzname(None))
link = "events/%s/%s" % (event.e_id, ev.time_begin.strftime("%Y-%m-%d"))
if WikiSystem(self.env).has_page(link):
@ -217,8 +217,8 @@ table.wiki-calendar :link,table.wiki-calendar :visited {color: #000 !important;f
session_tzname, selected_tz = get_tz(formatter.req.session.get('tz', self.env.config.get("trac", "default_timezone") or None))
def _f(t):
assert type(t) == Event
real_begin = selected_tz.fromutc(t.time_begin)
real_end = selected_tz.fromutc(t.time_end)
real_begin = t.time_begin.astimezone(selected_tz)
real_end = t.time_end.astimezone(selected_tz)
return u'<li><a href="%s" title="%s - %s %s">%s:<br/>%s</a></li>' % (formatter.href.event(t.e_id), real_begin.strftime("%d.%m.%Y %H:%M"), real_end.strftime("%d.%m.%Y %H:%M"), real_begin.tzinfo.tzname(None), unicode(t.location.name), unicode(t.name))
for week in calendar.monthcalendar(year, month):
buff.append(u'\n<tr>')

View File

@ -25,7 +25,7 @@
<input py:if="event.e_id != 0" type="hidden" name="event_id" value="${event.e_id}"/>
<fieldset id="properties">
<legend>${event.e_id and 'Edit Event' or 'Add Event'}</legend>
<table class="event-wizard" py:with="mydt = selected_tz.fromutc(event.time_begin);dt2 = selected_tz.fromutc(event.time_end)">
<table class="event-wizard" py:with="mydt = event.time_begin.astimezone(selected_tz);dt2 = event.time_end.astimezone(selected_tz)">
<tr><th><label for="name">Title:</label></th><td><input id="name" type="text" size="60" maxlength="200" name="name" value="${event.name}"/></td></tr>
<tr><th><label for="time_begin">Date begin:</label></th><td><input id="date_begin" type="text" size="10" maxlength="10" name="date_begin" value="${mydt.strftime('%d.%m.%Y')}"/>
<input id="time_begin" type="text" size="5" maxlength="5" name="time_begin" value="${mydt.strftime('%H:%M')}"/> ${mydt.tzinfo.tzname(None)}</td>

View File

@ -19,7 +19,7 @@
<tfoot><tr><th py:for="h in headers">&nbsp;</th></tr></tfoot>
<tbody>
<tr py:for="ix,row in enumerate(table)" class="upcoming">
<td class="daytext">${selected_tz.fromutc(row[0]).strftime(format)}</td>
<td class="daytext">${selected_tz.localize(row[0]).strftime(format)}</td>
<py:for each="eventlist in row[1:]">
<td py:if="eventlist != False" class="${isinstance(eventlist, list) and 'upcoming-event' or 'upcoming'}" rowspan="${eventlist.rowspan and eventlist.rowspan or None}">
<py:if test="eventlist != True">

View File

@ -3,7 +3,7 @@
xmlns:xi="http://www.w3.org/2001/XInclude">
<py:def function="render_event(event, with_day=False)">
<h2>${event.name}<span py:if="'EVENTS_MODIFY' in perm" class="edit"><a style="color:#f00;" href="${href.event('edit', event.e_id)}">edit</a></span></h2>
<table py:with="dt = selected_tz.fromutc(event.time_begin);dt2 = selected_tz.fromutc(event.time_end)">
<table py:with="dt = event.time_begin.astimezone(selected_tz);dt2 = event.time_end.astimezone(selected_tz)">
<tr>
<td >${with_day and dt.strftime('%Y.%m.%d')} ${dt.strftime('%H:%M')} - ${with_day and dt2.strftime('%Y.%m.%d')} ${dt2.strftime('%H:%M')}</td>
<!-- <td >${dt.strftime('%H:%M')} ${dt.tzinfo.tzname(None)} - ${dt2.strftime('%H:%M')} ${dt2.tzinfo.tzname(None)}</td> -->

View File

@ -25,7 +25,7 @@
<input py:if="event.e_id != 0" type="hidden" name="event_id" value="${event.e_id}"/>
<fieldset id="properties">
<legend>${event.e_id and 'Edit Event' or 'Add Event'}</legend>
<table class="event-wizard" py:with="mydt = selected_tz.fromutc(event.time_begin);dt2 = selected_tz.fromutc(event.time_end)">
<table class="event-wizard" py:with="mydt = event.time_begin.astimezone(selected_tz);dt2 = event.time_end.astimezone(selected_tz)">
<tr><th><label for="name">Title:</label></th><td><input id="name" type="text" size="60" maxlength="200" name="name" value="${event.name}"/></td></tr>
<tr><th><label for="time_begin">Date begin:</label></th><td><input id="date_begin" type="text" size="10" maxlength="10" name="date_begin" value="${mydt.strftime('%d.%m.%Y')}"/>
<input id="time_begin" type="text" size="5" maxlength="5" name="time_begin" value="${mydt.strftime('%H:%M')}"/> ${mydt.tzinfo.tzname(None)}</td>

View File

@ -16,7 +16,7 @@
<div py:for="ix,event in enumerate(events)"
id="event:${event.e_id}" class="event-item">
<py:choose test=""><div py:when="event.periodic() or event.initial_e_id==True" class="recurring">C<br/>I<br/>R<br/>C<br/>U<br/>L<br/>A<br/>R</div>
<div py:otherwise="" class="unique">S<br/>I<br/>N<br/>G<br/>U<br/>L<br/>A<br/>R</div>
<div py:otherwise="" class="unique">E<br/>I<br/>N<br/>Z<br/>E<br/>L<br/>T<br/>E<br/>R<br/>M<br/>I<br/>N</div>
</py:choose>
<div class="event-intern">
${render_event(event, True)}

View File

@ -51,8 +51,8 @@
<body>
<div id="content">
<h1>Recurrency Options for event '${event.name}'</h1>
<h2 py:with="dt = selected_tz.fromutc(event.time_begin);
dt2 = selected_tz.fromutc(event.time_end)">${dt.strftime("%A, %d.%m.%Y %H:%M")} ${dt.tzinfo.tzname(None)} - ${dt2.strftime("%A, %d.%m.%Y %H:%M")} ${dt2.tzinfo.tzname(None)}</h2>
<h2 py:with="dt = event.time_begin.astimezone(selected_tz);
dt2 = event.time_end.astimezone(selected_tz)">${dt.strftime("%A, %d.%m.%Y %H:%M")} ${dt.tzinfo.tzname(None)} - ${dt2.strftime("%A, %d.%m.%Y %H:%M")} ${dt2.tzinfo.tzname(None)}</h2>
<form name="recurrence" id='recurrence' uri="" method="post" mime-type="text/plain" action="">
<fieldset>
<div class="mybuttons">

View File

@ -32,7 +32,7 @@ from tractags.api import TagSystem, ITagProvider
from tracrendezvous.location.model import ItemLocation
from tracrendezvous.event.model import Event, EventRRule, EventRDate
#from tracrendezvous.event.parse_ical import parse_ical
from ctdotools.utils import gen_wiki_page, validate_id, time_parse, datetime_parse, date_parse, get_tz, local_to_utc
from ctdotools.utils import gen_wiki_page, validate_id, time_parse, datetime_parse, date_parse, get_tz
from trac.util.translation import domain_functions
@ -602,7 +602,7 @@ class EventModule(Component):
del req.session["deleted"]
req.session.save()
myenv = self.env
date_now = datetime.now(utc)
date_now = utc.localize(datetime.utcnow())
session_tzname, selected_tz = get_tz(req.session.get('tz', self.config.get("trac", "default_timezone") or None))
if req.args.has_key("e_id"):
@ -617,10 +617,10 @@ class EventModule(Component):
pi = req.path_info
crap, new_date = pi.split("new/", 1)
year, month, day = re.match("(\d{4})-(\d{1,2})-(\d{1,2})", new_date).groups()
new_date = datetime(int(year), int(month), int(day), 17, tzinfo=utc)
new_date = utc.localize(datetime(int(year), int(month), int(day), 17, tzinfo=selected_tz))
except ValueError:
new_date = date_now
event = Event(myenv, 0, "", req.authname, date_now, date_now, new_date, new_date + timedelta(0,10800), 1)
event = Event(myenv, 0, "", req.authname, date_now, date_now, new_date, selected_tz.normalize(new_date + timedelta(0, 10800)), 1)
add_ctxtnav(req, _('Events Overview'), req.href.event())
add_ctxtnav(req, _('Upcoming Events'), req.href.event("upcoming"))
@ -645,12 +645,14 @@ class EventModule(Component):
try:
event.old_time_begin = event.time_begin
event.time_begin = datetime_parse("%s %s" % (req.args["date_begin"], req.args["time_begin"]), selected_tz)
print "time_begin", event.time_begin, req.args["time_begin"]
except Exception:
add_warning(req, _("Wrong format in 'Date begin'."))
is_valid = False
try:
event.old_time_end = event.time_end
event.time_end = datetime_parse("%s %s" % (req.args["date_end"], req.args["time_end"]), selected_tz)
print "time_end", event.time_end, req.args["time_end"]
except Exception, e:
add_warning(req, _("Wrong format in 'Date end'."))
is_valid = False
@ -699,11 +701,20 @@ class EventModule(Component):
add_warning(req, str(e))
raise
else:
event.time_modified = datetime.now(utc)
event.time_modified = utc.localize(datetime.utcnow())
event.update()
req.session["edited"] = True
req.session.save()
req.redirect(req.href.event("edit", event.e_id))
print
print "selected_tz", type(selected_tz)
print "session_tzname", type(session_tzname)
print "vars", selected_tz.__dict__
print "vars", vars(event.time_begin.tzinfo)
print "time_begin", event.time_begin.astimezone(selected_tz)
print "time_end", event.time_end.astimezone(selected_tz)
return "event_edit.html", {"event" : event,
"session_tzname" : session_tzname,
"selected_tz" : selected_tz,
@ -987,8 +998,8 @@ class EventModule(Component):
"FROM events WHERE e_id=%s", (num,))
session_tzname, selected_tz = get_tz(formatter.req.session.get("tz", self.env.config.get("trac", "default_timezone") or None))
for name, time_begin, time_end in cursor:
time_begin = selected_tz.fromutc(datetime.fromtimestamp(time_begin, utc))
time_end = selected_tz.fromutc(datetime.fromtimestamp(time_end, utc))
time_begin = utc.localize(datetime.fromtimestamp(time_begin, utc)).astimezone(selected_tz)
time_end = utc.localize(datetime.datetime.fromtimestamp(time_end, utc)).astimezone(selected_tz)
title = "%s (%s - %s %s)" % (name,
time_begin.strftime('%d.%m.%Y %H:%M'),
time_end.strftime('%d.%m.%Y %H:%M'), time_begin.tzinfo.tzname(None))

View File

@ -36,8 +36,8 @@
</tr>
</thead>
<py:for each="date in dates">
<tr py:with="dt = selected_tz.fromutc(date.time_begin);
dt2 = selected_tz.fromutc(date.time_end)">
<tr py:with="dt = date.time_begin.astimezone(selected_tz);
dt2 = date.time_end.astimezone(selected_tz)">
<td>${date.author}</td>
<td><input type="text" size="25" name="email:${date.date_id}" value="${date.email}"/></td>
<td><input type="text" size="10" maxlength="10" name="date_begin:${date.date_id}" value="${date.time_begin.strftime('%d.%m.%Y')}"/></td>
@ -59,8 +59,8 @@
<input type="hidden" name="rendezvous_id" value="$rendezvous.rendezvous_id"/>
<fieldset id="properties">
<legend>New Date</legend>
<table class="rendezvous-wizard" py:with="dt = selected_tz.fromutc(new_date.time_begin);
dt2 = selected_tz.fromutc(new_date.time_end)">
<table class="rendezvous-wizard" py:with="dt = new_date.time_begin.astimezone(selected_tz);
dt2 = new_date.time_end.astimezone(selected_tz)">
<tr><th><label for="nd_email">Email:</label></th><td><input id="nd_email" type="text" size="24" maxlength="25" name="email"/></td></tr>
<tr><th><label for="nd_date_begin">Date begin:</label></th><td><input id="nd_date_begin" type="text" size="10" maxlength="10" name="date_begin" value="${new_date.time_begin.strftime('%d.%m.%Y')}"/>
<input id="nd_time_begin" type="text" size="5" maxlength="5" name="time_begin" value="${dt.strftime('%H:%M')}"/> ${dt.tzinfo.tzname(None)}</td></tr>

View File

@ -49,7 +49,7 @@
<thead>
<tr class="rendezvous-matrix"><th class="rendezvous-matrix">Date proposals -></th>
<py:for each="date in rendezvous.dates">
<th class="rendezvous-matrix" py:with="dt_begin = selected_tz.fromutc(date.time_begin); dt_end = selected_tz.fromutc(date.time_end)">
<th class="rendezvous-matrix" py:with="dt_begin = date.time_begin.astimezone(selected_tz); dt_end = date.time_end.astimezone(selected_tz)">
<div py:if="date.elected" class="scheduled"><img src="${href.chrome('/hw/images/selected.png')}"/>scheduled</div>
<a py:strip="('RENDEZVOUS_DATE_VIEW' not in perm and date.author != authname) or 'RENDEZVOUS_ADMIN' not in perm" href="${href.date(rendezvous.rendezvous_id)}">${dt_begin.strftime('%d.%m.%Y %H:%M')} ${dt_begin.tzinfo.tzname(None)} - ${dt_end.strftime('%d.%m.%Y %H:%M')} ${dt_end.tzinfo.tzname(None)}</a>
</th>

View File

@ -34,7 +34,7 @@
<input py:if="rendezvous.rendezvous_id != 0" type="hidden" name="rendezvous_id" value="${rendezvous.rendezvous_id}"/>
<fieldset id="properties">
<legend>${title}</legend>
<table class="rendezvous-wizard" py:with="dt = selected_tz.fromutc(rendezvous.schedule_deadline)">
<table class="rendezvous-wizard" py:with="dt = rendezvous.schedule_deadline.astimezone(selected_tz)">
<tr><th><label for="name">Title</label></th><td><input id="name" type="text" size="50" maxlength="50" name="name" value="${rendezvous.name}"/></td></tr>
<tr><th><label for="author">Author</label></th><td>
<py:choose test="">

View File

@ -38,7 +38,7 @@
</tr>
</thead>
<tbody py:choose="">
<tr py:when="canModify and canDelete" py:for="vote in votes" py:with="dt = selected_tz.fromutc(vote.time_begin);dt2 = selected_tz.fromutc(vote.time_end)">
<tr py:when="canModify and canDelete" py:for="vote in votes" py:with="dt = vote.time_begin.astimezone(selected_tz);dt2 = vote.time_end.astimezone(selected_tz)">
<td>${vote.user}</td>
<td><input type="text" size="40" name="email:${vote.vote_id}" value="${vote.email}"/></td>
<td><input type="text" size="8" id="time_begin:${vote.vote_id}" name="date_begin:${vote.vote_id}" value="${dt.strftime('%d.%m.%Y')}" />
@ -47,7 +47,7 @@
<input type="text" size="5" name="time_end:${vote.vote_id}" value="${dt2.strftime('%H:%M')}"/> ${dt2.tzinfo.tzname(None)}</td>
<td><input type="checkbox" name="delete" value="${vote.vote_id}" /></td>
</tr>
<tr py:when="not canModify and canDelete" py:for="vote in votes" py:with="dt = selected_tz.fromutc(vote.time_begin);dt2 = selected_tz.fromutc(vote.time_end)">
<tr py:when="not canModify and canDelete" py:for="vote in votes" py:with="dt = vote.time_begin.astimezone(selected_tz);dt2 = vote.time_end.astimezone(selected_tz)">
<td>${vote.user}</td>
<td>${vote.mail}</td>
<td>${dt.strftime('%d.%m.%Y')}
@ -56,7 +56,7 @@
${dt2.strftime('%H:%M')} ${dt2.tzinfo.tzname(None)}</td>
<td><input type="checkbox" name="delete" value="${vote.vote_id}"/></td>
</tr>
<tr py:when="canModify and not canDelete" py:for="vote in votes" py:with="dt = selected_tz.fromutc(vote.time_begin);dt2 = selected_tz.fromutc(vote.time_end)">
<tr py:when="canModify and not canDelete" py:for="vote in votes" py:with="dt = vote.time_begin.astimezone(selected_tz);dt2 = vote.time_end.astimezone(selected_tz)">
<td><input type="text" size="40" name="email:${vote.vote_id}" value="${vote.email}" /></td>
<td><input type="text" size="8" id="time_begin:${vote.vote_id}" name="date_begin:${vote.vote_id}" value="${dt.strftime('%d.%m.%Y')}" />
<input type="text" size="5" name="time_begin:${vote.vote_id}" value="${dt.strftime('%H:%M')}"/> ${dt.tzinfo.tzname(None)}</td>
@ -91,12 +91,12 @@
<th><label for="dv_email">Email:</label></th>
<td><input id="dv_email" type="text" name="email" /></td>
</tr>
<tr class="field" py:with="dt = selected_tz.fromutc(rdate.time_begin)">
<tr class="field" py:with="dt = rdate.time_begin.astimezone(selected_tz)">
<th><label for="dv_date_begin">Date Begin:</label></th>
<td><input id="rdate_begin" type="text" name="date_begin" value="${dt.strftime('%d.%m.%Y')}"/>
<input type="text" name="time_begin" value="${dt.strftime('%H:%M')}"/> ${dt.tzinfo.tzname(None)}</td>
</tr>
<tr class="field" py:with="dt = selected_tz.fromutc(rdate.time_end)">
<tr class="field" py:with="dt = rdate.time_end.astimezone(selected_tz)">
<th><label for="dv_date_end">Date End:</label></th>
<td><input id="rdate_end" type="text" name="date_end" value="${dt.strftime('%d.%m.%Y')}"/>
<input type="text" name="time_end" value="${dt.strftime('%H:%M')}"/> ${dt.tzinfo.tzname(None)}</td>

View File

@ -364,7 +364,7 @@ class RendezVousModule(Component):
if RendezVousDate.exists(self.env, dates[date_id].time_begin, dates[date_id].time_end):
raise TracError("RendezVousDate already exists")
d.update()
real_tz = selected_tz.fromutc(d.time_begin).tzinfo
real_tz = selected_tz.normalize(selected_tz.astimezone(d.time_begin)).tzinfo
update_votes_graph("", d.votes, path, [sizex, sizey], real_tz)
except Exception, err:
add_warning(req, str(err))