[Zope-Checkins] SVN: Zope/trunk/ #1416: Allow construction of a DateTime instance from a given

Andreas Jung andreas at andreas-jung.com
Fri Jul 30 05:32:52 EDT 2004


Log message for revision 26843:
  #1416: Allow construction of a DateTime instance from a given
  DateTime instance
  


Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/DateTime/DateTime.py


-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2004-07-30 08:57:27 UTC (rev 26842)
+++ Zope/trunk/doc/CHANGES.txt	2004-07-30 09:32:52 UTC (rev 26843)
@@ -26,6 +26,9 @@
 
     Features added
 
+     - DateTime: new DateTime instance can be constructed from a given
+       DateTime instance: d_new = DateTime(d_old)
+
      - ZCatalog: added a new configuration option in the "Advanced" tab
        to provide optional logging of the progress of long running 
        reindexing or recataloging operations.

Modified: Zope/trunk/lib/python/DateTime/DateTime.py
===================================================================
--- Zope/trunk/lib/python/DateTime/DateTime.py	2004-07-30 08:57:27 UTC (rev 26842)
+++ Zope/trunk/lib/python/DateTime/DateTime.py	2004-07-30 09:32:52 UTC (rev 26843)
@@ -593,6 +593,10 @@
             the gmt value of the time.time() float represented in
             the local machine's timezone.
 
+          - If the DateTime function is invoked with a single
+            argument that is a DateTime instane, a copy of the 
+            passed object will be created.
+
           - If the function is invoked with two numeric arguments,
             then the first is taken to be an integer year and the
             second argument is taken to be an offset in days from
@@ -688,7 +692,17 @@
             if arg=='':
                 raise SyntaxError, arg
 
-            if isinstance(arg, (unicode, str)) and arg.lower() in self._tzinfo._zidx:
+            if isinstance(arg, DateTime):
+                """ Construct a new DateTime instance from a given DateTime instance """
+                t = arg.timeTime()
+                lt = safelocaltime(t)
+                tz = self.localZone(lt)
+                ms = (t - math.floor(t))
+                s,d = _calcSD(t)
+                yr,mo,dy,hr,mn,sc=lt[:6]
+                sc=sc+ms
+
+            elif isinstance(arg, (unicode, str)) and arg.lower() in self._tzinfo._zidx:
                 # Current time, to be displayed in specified timezone
                 t,tz=time(),self._tzinfo._zmap[arg.lower()]
                 ms=(t-math.floor(t))



More information about the Zope-Checkins mailing list