diff --git a/crans_utils.py b/crans_utils.py index 6317907..ac0e78d 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -352,8 +352,7 @@ def datetime_from_generalized_time_format(gtf): tz = '+0000' the_date = datetime.datetime.strptime(date, "%Y%m%d%H%M%S") if pytz is not None: - tz_dict = build_tz_dict() - the_timezone = tz_dict.get(tz, pytz.utc) + the_timezone = pytz.FixedOffset(int(tz[0:-2])*60 + int(tz[-2:])) the_date = the_timezone.localize(the_date) the_date = the_timezone.normalize(the_date) return the_date @@ -364,27 +363,7 @@ def datetime_to_generalized_time_format(datetime_obj): if datetime_obj.utcoffset() is None: if pytz is not None: datetime_obj = pytz.utc.localize(datetime_obj) - datetime_obj = pytz.utc.normalize(datetime_obj) else: to_append = "Z" mostly_gtf = datetime.datetime.strftime(datetime_obj, "%Y%m%d%H%M%S%z") return mostly_gtf.replace('+0000', "Z") + to_append - -def build_tz_dict(): - """Crappy way to define a dict containing all timezones that - pytz can handle. - - It seems there is no way to get a tz object from the offset - with pytz. - - """ - tz_dict = {} - for tz in pytz.common_timezones: - mytz = pytz.timezone(tz) - d = datetime.datetime.now(mytz).utcoffset().total_seconds() - hours = int(d)/3600 - minutes = int(float(int(d) % 3600)/60) - fmt = "%+03d%02d" % (hours, minutes) - if fmt not in tz_dict: - tz_dict[fmt] = mytz - return tz_dict