From c7febbd6424c84ea36df79aa9611bf57d6045cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Tue, 24 Apr 2012 12:25:53 +0200 Subject: [PATCH] timezone related fixes --- CTDOTools/ctdotools/utils.py | 13 +++------- TracBooking/tracbooking/report.py | 2 +- TracRendezVous/tracrendezvous/event/macros.py | 8 +++--- .../event/templates/alarm_edit.html | 2 +- .../event/templates/event_details.html | 2 +- .../event/templates/event_display.html | 2 +- .../event/templates/event_edit.html | 2 +- .../event/templates/event_list.html | 2 +- .../event/templates/recur_edit.html | 4 +-- TracRendezVous/tracrendezvous/event/web_ui.py | 25 +++++++++++++------ .../rendezvous/templates/date.html | 8 +++--- .../rendezvous/templates/rendezvous.html | 2 +- .../rendezvous/templates/rendezvous_edit.html | 2 +- .../rendezvous/templates/vote.html | 10 ++++---- .../tracrendezvous/rendezvous/web_ui.py | 2 +- 15 files changed, 45 insertions(+), 41 deletions(-) diff --git a/CTDOTools/ctdotools/utils.py b/CTDOTools/ctdotools/utils.py index 2c35c57..4dc4dfd 100644 --- a/CTDOTools/ctdotools/utils.py +++ b/CTDOTools/ctdotools/utils.py @@ -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""" diff --git a/TracBooking/tracbooking/report.py b/TracBooking/tracbooking/report.py index 17f4300..3fd9c9d 100644 --- a/TracBooking/tracbooking/report.py +++ b/TracBooking/tracbooking/report.py @@ -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) diff --git a/TracRendezVous/tracrendezvous/event/macros.py b/TracRendezVous/tracrendezvous/event/macros.py index be9d550..4ceb94f 100644 --- a/TracRendezVous/tracrendezvous/event/macros.py +++ b/TracRendezVous/tracrendezvous/event/macros.py @@ -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'
  • %s:
    %s
  • ' % (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') diff --git a/TracRendezVous/tracrendezvous/event/templates/alarm_edit.html b/TracRendezVous/tracrendezvous/event/templates/alarm_edit.html index 0e63e2b..447dea7 100644 --- a/TracRendezVous/tracrendezvous/event/templates/alarm_edit.html +++ b/TracRendezVous/tracrendezvous/event/templates/alarm_edit.html @@ -25,7 +25,7 @@
    ${event.e_id and 'Edit Event' or 'Add Event'} - +
    diff --git a/TracRendezVous/tracrendezvous/event/templates/event_details.html b/TracRendezVous/tracrendezvous/event/templates/event_details.html index 81459a9..057e337 100644 --- a/TracRendezVous/tracrendezvous/event/templates/event_details.html +++ b/TracRendezVous/tracrendezvous/event/templates/event_details.html @@ -19,7 +19,7 @@ - +
    ${mydt.tzinfo.tzname(None)}
     
    ${selected_tz.fromutc(row[0]).strftime(format)}${selected_tz.localize(row[0]).strftime(format)} diff --git a/TracRendezVous/tracrendezvous/event/templates/event_display.html b/TracRendezVous/tracrendezvous/event/templates/event_display.html index 433965b..526da3b 100644 --- a/TracRendezVous/tracrendezvous/event/templates/event_display.html +++ b/TracRendezVous/tracrendezvous/event/templates/event_display.html @@ -3,7 +3,7 @@ xmlns:xi="http://www.w3.org/2001/XInclude">

    ${event.name}edit

    - +
    diff --git a/TracRendezVous/tracrendezvous/event/templates/event_edit.html b/TracRendezVous/tracrendezvous/event/templates/event_edit.html index 00bb04b..71682ac 100644 --- a/TracRendezVous/tracrendezvous/event/templates/event_edit.html +++ b/TracRendezVous/tracrendezvous/event/templates/event_edit.html @@ -25,7 +25,7 @@
    ${event.e_id and 'Edit Event' or 'Add Event'} -
    ${with_day and dt.strftime('%Y.%m.%d')} ${dt.strftime('%H:%M')} - ${with_day and dt2.strftime('%Y.%m.%d')} ${dt2.strftime('%H:%M')}
    +
    diff --git a/TracRendezVous/tracrendezvous/event/templates/event_list.html b/TracRendezVous/tracrendezvous/event/templates/event_list.html index 2dbbecf..7db8793 100644 --- a/TracRendezVous/tracrendezvous/event/templates/event_list.html +++ b/TracRendezVous/tracrendezvous/event/templates/event_list.html @@ -16,7 +16,7 @@
    C
    I
    R
    C
    U
    L
    A
    R
    -
    S
    I
    N
    G
    U
    L
    A
    R
    +
    E
    I
    N
    Z
    E
    L
    T
    E
    R
    M
    I
    N
    ${render_event(event, True)} diff --git a/TracRendezVous/tracrendezvous/event/templates/recur_edit.html b/TracRendezVous/tracrendezvous/event/templates/recur_edit.html index f227c7e..5b4f57e 100644 --- a/TracRendezVous/tracrendezvous/event/templates/recur_edit.html +++ b/TracRendezVous/tracrendezvous/event/templates/recur_edit.html @@ -51,8 +51,8 @@

    Recurrency Options for event '${event.name}'

    -

    ${dt.strftime("%A, %d.%m.%Y %H:%M")} ${dt.tzinfo.tzname(None)} - ${dt2.strftime("%A, %d.%m.%Y %H:%M")} ${dt2.tzinfo.tzname(None)}

    +

    ${dt.strftime("%A, %d.%m.%Y %H:%M")} ${dt.tzinfo.tzname(None)} - ${dt2.strftime("%A, %d.%m.%Y %H:%M")} ${dt2.tzinfo.tzname(None)}

    diff --git a/TracRendezVous/tracrendezvous/event/web_ui.py b/TracRendezVous/tracrendezvous/event/web_ui.py index be918de..f11bc64 100644 --- a/TracRendezVous/tracrendezvous/event/web_ui.py +++ b/TracRendezVous/tracrendezvous/event/web_ui.py @@ -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)) diff --git a/TracRendezVous/tracrendezvous/rendezvous/templates/date.html b/TracRendezVous/tracrendezvous/rendezvous/templates/date.html index e947da9..d142033 100644 --- a/TracRendezVous/tracrendezvous/rendezvous/templates/date.html +++ b/TracRendezVous/tracrendezvous/rendezvous/templates/date.html @@ -36,8 +36,8 @@
    - + @@ -59,8 +59,8 @@
    New Date -
    ${mydt.tzinfo.tzname(None)}
    ${date.author}
    +
    diff --git a/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous.html b/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous.html index 831c6dc..7f708ed 100644 --- a/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous.html +++ b/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous.html @@ -49,7 +49,7 @@ - diff --git a/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous_edit.html b/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous_edit.html index 9e36bb2..8b219c9 100644 --- a/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous_edit.html +++ b/TracRendezVous/tracrendezvous/rendezvous/templates/rendezvous_edit.html @@ -34,7 +34,7 @@
    ${title} -
    ${dt.tzinfo.tzname(None)}
    Date proposals -> +
    scheduled
    ${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)}
    +
    - + - + - + @@ -91,12 +91,12 @@ - + - + diff --git a/TracRendezVous/tracrendezvous/rendezvous/web_ui.py b/TracRendezVous/tracrendezvous/rendezvous/web_ui.py index 63b46f6..d4cc357 100644 --- a/TracRendezVous/tracrendezvous/rendezvous/web_ui.py +++ b/TracRendezVous/tracrendezvous/rendezvous/web_ui.py @@ -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))
    diff --git a/TracRendezVous/tracrendezvous/rendezvous/templates/vote.html b/TracRendezVous/tracrendezvous/rendezvous/templates/vote.html index 0cd25b6..5f5e4ec 100644 --- a/TracRendezVous/tracrendezvous/rendezvous/templates/vote.html +++ b/TracRendezVous/tracrendezvous/rendezvous/templates/vote.html @@ -38,7 +38,7 @@
    ${vote.user} @@ -47,7 +47,7 @@ ${dt2.tzinfo.tzname(None)}
    ${vote.user} ${vote.mail} ${dt.strftime('%d.%m.%Y')} @@ -56,7 +56,7 @@ ${dt2.strftime('%H:%M')} ${dt2.tzinfo.tzname(None)}
    ${dt.tzinfo.tzname(None)}
    ${dt.tzinfo.tzname(None)}
    ${dt.tzinfo.tzname(None)}