[Commits] (donn) Updated parsing for Calendar Events in the Detail View

commits at osafoundation.org commits at osafoundation.org
Mon Sep 27 13:09:10 PDT 2004


Commit by: donn
Modified files:
chandler/parcels/osaf/framework/blocks/detail/Detail.py 1.38 1.39

Log message:
Updated parsing for Calendar Events in the Detail View
------------------------------------------------------
* Changed the parsing of the duration field (bug 1970)
   - now non-sense values don't turn into 12:00
   - now has short form (HH:MM) and long form (DD:HH:MM:SS)
* Changed the parsing of the Start Time field (bug 2018)
   - now 12:00 PM works
* Added default formats for stamped CalendarEvents

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/detail/Detail.py.diff?r1=text&tr1=1.38&r2=text&tr2=1.39

Index: chandler/parcels/osaf/framework/blocks/detail/Detail.py
diff -u chandler/parcels/osaf/framework/blocks/detail/Detail.py:1.38 chandler/parcels/osaf/framework/blocks/detail/Detail.py:1.39
--- chandler/parcels/osaf/framework/blocks/detail/Detail.py:1.38	Fri Sep 24 16:52:53 2004
+++ chandler/parcels/osaf/framework/blocks/detail/Detail.py	Mon Sep 27 13:09:09 2004
@@ -1,5 +1,5 @@
-__version__ = "$Revision: 1.38 $"
-__date__ = "$Date: 2004/09/24 23:52:53 $"
+__version__ = "$Revision: 1.39 $"
+__date__ = "$Date: 2004/09/27 20:09:09 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -71,16 +71,16 @@
             try:
                 # process from the children up
                 for child in block.childrenBlocks:
-                    notify = reNotifyInside (child, item)
-                    notifyParent = notifyParent or notify
+                    notifyParent = reNotifyInside (child, item) or notifyParent
             except AttributeError:
                 pass
             try:
-                notify = block.synchronizeItemDetail(item)
-                notifyParent = notifyParent or notify
+                syncMethod = block.synchronizeItemDetail
             except AttributeError:
                 if notifyParent:
                     block.synchronizeWidget()
+            else:
+                notifyParent = syncMethod(item) or notifyParent
             return notifyParent
 
         children = self.childrenBlocks
@@ -846,11 +846,18 @@
         calendarMixinKind = Calendar.CalendarParcel.getCalendarEventMixinKind()
         return item.isItemOf (calendarMixinKind)
 
-    def saveAttributeFromWidget(self, item, widget):
-        """"
-          Update the attribute from the user edited string in the widget.
-        """
-        dateString = widget.GetValue().strip('?')
+    def parseDateTime (self, dateString):
+        theDate = None
+        # work around a problem when using hour of 12
+        # @@@DLD Check if this date parsing bug is fixed yet - due in version 2.1
+        if DateTime.__version__ < '2.1':
+            try:
+                twelveLocation = dateString.upper().index('12:')
+            except ValueError:
+                pass
+            else:
+                dateString = dateString[:twelveLocation]\
+                             + '00:' + dateString[twelveLocation+3:]
         try:
             # convert to Date/Time
             theDate = DateTime.Parser.DateTimeFromString (dateString)
@@ -858,13 +865,17 @@
             pass
         except DateTime.RangeError:
             pass
+        return theDate
+
+    def saveAttributeFromWidget(self, item, widget):
+        """"
+          Update the attribute from the user edited string in the widget.
+        """
+        dateString = widget.GetValue().strip('?')
+        theDate = self.parseDateTime (dateString)
         try:
-            # save the new Date/Time
-            whichTimeAttribute = self.whichAttribute()
-            if 'start' in whichTimeAttribute:
-                item.ChangeStart (theDate)
-            else:
-                item.setAttributeValue(whichTimeAttribute, theDate)
+            # save the new Date/Time into the startTime attribute
+            item.ChangeStart (theDate)
         except:
             # DLDTBD figure out reasonable exceptions to catch during conversion
             dateString = dateString + '?'
@@ -882,7 +893,7 @@
         try:
             dateTime = item.getAttributeValue(self.whichAttribute())
         except AttributeError:
-            value = ''
+            value = 'yyyy-mm-dd HH:MM'
         else:
             value = dateTime.strftime (self.timeFormat)
         widget.SetValue (value)
@@ -905,7 +916,10 @@
     An attribute-based edit field for Duration Values
     Our parent block knows which attribute we edit.
     """
-    durationFormat = '%I:%M'
+    durationFormatShort = '%H:%M'
+    durationFormatLong = '%d:%H:%M:%S'
+    zeroDays = DateTime.DateTimeDelta (0)
+    hundredDays = DateTime.DateTimeDelta (100)
     def shouldShow (self, item):
         # only shown for CalendarEventMixin kinds
         calendarMixinKind = Calendar.CalendarParcel.getCalendarEventMixinKind()
@@ -921,14 +935,14 @@
             theDuration = DateTime.Parser.DateTimeDeltaFromString (durationString)
         except ValueError: 
             pass
-        try:
+
+        # if we got a value different from the default
+        if self.hundredDays > theDuration > self.zeroDays:
             # save the new duration
             item.duration = theDuration
-        except:
-            # DLDTBD figure out reasonable exceptions to catch during conversion
-            durationString = dateString + '?'
-        else:
-            durationString = theDuration.strftime (self.durationFormat)
+
+        # get the newly formatted string
+        durationString = self.formattedDuration (theDuration, durationString)
 
         # redisplay the processed Date/Time in the widget
         widget.SetValue(durationString)
@@ -943,7 +957,24 @@
         except AttributeError:
             value = '?'
         else:
-            value = theDuration.strftime (self.durationFormat)
+            if theDuration is not None:
+                value = self.formattedDuration (theDuration, '')
+            else:
+                value = 'hh:mm'
         widget.SetValue (value)
 
+    def formattedDuration (self, aDuration, originalString):
+        """
+          Return a string containing the formatted duration.
+        """
+        # if we got a value different from the default
+        if self.hundredDays > aDuration > self.zeroDays:
+            if aDuration.day == 0 and aDuration.second == 0:
+                format = self.durationFormatShort
+            else:
+                format = self.durationFormatLong
+            return aDuration.strftime (format)
+        else:
+            # show that we didn't understand the input
+            return originalString + '?'
 



More information about the Commits mailing list