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'