[Checkins] SVN: DateTime/trunk/ No longer store _pm and _pmhour

Hanno Schlichting hannosch at hannosch.eu
Sun May 8 08:46:11 EDT 2011


Log message for revision 121591:
  No longer store _pm and _pmhour
  

Changed:
  U   DateTime/trunk/CHANGES.txt
  U   DateTime/trunk/src/DateTime/DateTime.py

-=-
Modified: DateTime/trunk/CHANGES.txt
===================================================================
--- DateTime/trunk/CHANGES.txt	2011-05-08 12:32:20 UTC (rev 121590)
+++ DateTime/trunk/CHANGES.txt	2011-05-08 12:46:11 UTC (rev 121591)
@@ -4,9 +4,10 @@
 3.0 (unreleased)
 ----------------
 
-- Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon` and `_pmon` in
-  memory for every instance but look them up dynamically based on `_dayoffset`
-  and `_month`. This saves another 150 bytes of memory per DateTime instance.
+- Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon`, `_pmon`, `_pmhour`
+  and `_pm` in memory for every instance but look them up dynamically based on
+  `_dayoffset`, `_month` and `_hour`. This saves another 150 bytes of memory
+  per DateTime instance.
 
 - Moved various internal parsing related class variables to module constants.
 

Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py	2011-05-08 12:32:20 UTC (rev 121590)
+++ DateTime/trunk/src/DateTime/DateTime.py	2011-05-08 12:46:11 UTC (rev 121591)
@@ -414,8 +414,6 @@
     __slots__ = (
         '_timezone_naive',
         '_tz',
-        '_pm',
-        '_pmhour',
         '_dayoffset',
         '_year',
         '_month',
@@ -825,12 +823,6 @@
                 tz = self._calcTimezoneName(x, ms)
             s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)
 
-        if hr>12:
-            self._pmhour=hr-12
-            self._pm='pm'
-        else:
-            self._pmhour=hr or 12
-            self._pm= (hr==12) and 'pm' or 'am'
         self._dayoffset = int((_julianday(yr,mo,dy) + 2L) % 7)
         # Round to nearest microsecond in platform-independent way.  You
         # cannot rely on C sprintf (Python '%') formatting to round
@@ -1426,6 +1418,13 @@
         """Return the integer day of the week, where sunday is 1."""
         return self._dayoffset+1
 
+    @property
+    def _pmhour(self):
+        hr = self._hour
+        if hr > 12:
+            return hr - 12
+        return hr or 12
+
     def h_12(self):
         """Return the 12-hour clock representation of the hour."""
         return self._pmhour
@@ -1434,6 +1433,13 @@
         """Return the 24-hour clock representation of the hour."""
         return self._hour
 
+    @property
+    def _pm(self):
+        hr = self._hour
+        if hr >= 12:
+            return 'pm'
+        return 'am'
+
     def ampm(self):
         """Return the appropriate time modifier (am or pm)."""
         return self._pm



More information about the checkins mailing list