[Checkins] SVN: DateTime/trunk/ Avoid storing `_t` representing the time as a float in seconds since the epoch, as we already have `_micros` doing the same as a long. Memory use is down to about 300 bytes per DateTime instance.

Hanno Schlichting hannosch at hannosch.eu
Sun May 8 09:57:15 EDT 2011


Log message for revision 121594:
  Avoid storing `_t` representing the time as a float in seconds since the epoch, as we already have `_micros` doing the same as a long. Memory use is down to about 300 bytes per DateTime instance.
  

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 13:29:40 UTC (rev 121593)
+++ DateTime/trunk/CHANGES.txt	2011-05-08 13:57:15 UTC (rev 121594)
@@ -4,6 +4,10 @@
 3.0 (unreleased)
 ----------------
 
+- Avoid storing `_t` representing the time as a float in seconds since the
+  epoch, as we already have `_micros` doing the same as a long. Memory use is
+  down to about 300 bytes per DateTime instance.
+
 - Updated exception raising syntax to current style.
 
 - Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon`, `_pmon`, `_pmhour`

Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py	2011-05-08 13:29:40 UTC (rev 121593)
+++ DateTime/trunk/src/DateTime/DateTime.py	2011-05-08 13:57:15 UTC (rev 121594)
@@ -423,7 +423,6 @@
         '_second',
         '_nearsec',
         '_d',
-        '_t',
         '_micros',
         'time',
     )
@@ -839,7 +838,7 @@
         self._nearsec=math.floor(sc)
         self._year, self._month, self._day = yr, mo, dy
         self._hour, self._minute, self._second = hr, mn, sc
-        self.time, self._d, self._t, self._tz = s, d, t, tz
+        self.time, self._d, self._tz = s, d, tz
         # self._micros is the time since the epoch
         # in long integer microseconds.
         if microsecs is None:
@@ -1101,6 +1100,7 @@
         raise AttributeError(name)
 
     # Conversion and comparison methods
+
     def timeTime(self):
         """Return the date/time as a floating-point number in UTC,
         in the format used by the python time module.
@@ -1108,7 +1108,7 @@
         Note that it is possible to create date/time values with
         DateTime that have no meaningful value to the time module.
         """
-        return self._t
+        return self._micros / 1000000.0
 
     def toZone(self, z):
         """Return a DateTime with the value as the current
@@ -1225,7 +1225,7 @@
         long integer microseconds.
         """
         if isinstance(t, float):
-            return self._t > t
+            return self._micros > long(t * 1000000)
         return self._micros > t._micros
 
     __gt__ = greaterThan
@@ -1243,7 +1243,7 @@
         long integer microseconds.
         """
         if isinstance(t, float):
-            return self._t >= t
+            return self._micros >= long(t * 1000000)
         return self._micros >= t._micros
 
     __ge__ = greaterThanEqualTo
@@ -1260,7 +1260,7 @@
         long integer microseconds.
         """
         if isinstance(t, float):
-            return self._t == t
+            return self._micros == long(t * 1000000)
         return self._micros == t._micros
 
     def notEqualTo(self, t):
@@ -1302,7 +1302,7 @@
         long integer microseconds.
         """
         if isinstance(t, float):
-            return self._t < t
+            return self._micros < long(t * 1000000)
         return self._micros < t._micros
 
     __lt__ = lessThan
@@ -1319,7 +1319,7 @@
         long integer microseconds.
         """
         if isinstance(t, float):
-            return self._t <= t
+            return self._micros <= long(t * 1000000)
         return self._micros <= t._micros
 
     __le__ = lessThanEqualTo
@@ -1762,8 +1762,12 @@
     def __float__(self):
         """Convert to floating-point number of seconds since the epoch (gmt).
         """
-        return float(self._t)
+        return self.micros() / 1000000.0
 
+    @property
+    def _t(self):
+        return self._micros / 1000000.0
+
     def _parse_iso8601(self, s):
         # preserve the previously implied contract
         # who know where this could be used...



More information about the checkins mailing list