Commits

jomae  committed 5ce15c8

0.12.3dev: Adds `normalize` method to `FixedOffset` and `LocalTimezone` to use simply it and removes checking for the existance.

  • Participants
  • Parent commits 6c2835a
  • Branches 0.12-stable

Comments (0)

Files changed (2)

File trac/prefs/templates/prefs_datetime.html

 
       <!-- This currently crashes Genshi's extractor if you add i18n:msg -->
       <p class="hint" py:with="now = datetime.now(utc);
-                               nowtz = now.astimezone(selected_tz);
-                               nowtz = hasattr(selected_tz, 'normalize') and selected_tz.normalize(nowtz) or nowtz"
+                               nowtz = selected_tz.normalize(now.astimezone(selected_tz))"
                       py:choose="">
         <i18n:msg params="time">Example: The current time is <strong>${format_time(now, 'iso8601', tzinfo=utc)}</strong> (UTC).</i18n:msg>
         <br />

File trac/util/datefmt.py

             raise ValueError('Not naive datetime (tzinfo is already set)')
         return dt.replace(tzinfo=self)
 
+    def normalize(self, dt, is_dst=False):
+        if dt.tzinfo is None:
+            raise ValueError('Naive time (no tzinfo set)')
+        return dt
+
 
 STDOFFSET = timedelta(seconds=-time.timezone)
 if time.daylight:
             raise ValueError('Not naive datetime (tzinfo is already set)')
         return dt.replace(tzinfo=self)
 
+    def normalize(self, dt, is_dst=False):
+        if dt.tzinfo is None:
+            raise ValueError('Naive time (no tzinfo set)')
+        return dt
+
 
 utc = FixedOffset(0, 'UTC')
 utcmin = datetime.min.replace(tzinfo=utc)