[Zope-CVS] SVN: psycopgda/trunk/ PostgreSQL can output intervals using 'mon' and 'mons' instead of 'month' and 'months'

Stuart Bishop stuart at stuartbishop.net
Mon Jan 24 05:06:15 EST 2005


Log message for revision 28917:
  PostgreSQL can output intervals using 'mon' and 'mons' instead of 'month' and 'months'

Changed:
  U   psycopgda/trunk/adapter.py
  U   psycopgda/trunk/tests.py

-=-
Modified: psycopgda/trunk/adapter.py
===================================================================
--- psycopgda/trunk/adapter.py	2005-01-23 01:59:08 UTC (rev 28916)
+++ psycopgda/trunk/adapter.py	2005-01-24 10:06:15 UTC (rev 28917)
@@ -184,7 +184,9 @@
         date_comp ::= 1 'day'
                    |  number 'days'
                    |  1 'month'
+                   |  1 'mon'
                    |  number 'months'
+                   |  number 'mons'
                    |  1 'year'
                    |  number 'years'
         time      ::= number ':' number
@@ -194,6 +196,10 @@
     years = months = days = 0
     hours = minutes = seconds = 0
     elements = s.split()
+    # Tests with 7.4.6 on Ubuntu 5.4 interval output returns 'mon' and 'mons'
+    # and not 'month' or 'months' as expected. I've fixed this and left
+    # the original matches there too in case this is dependant on
+    # OS or PostgreSQL release.
     for i in range(0, len(elements) - 1, 2):
         count, unit = elements[i:i+2]
         if unit == 'day' and count == '1':
@@ -202,8 +208,12 @@
             days += int(count)
         elif unit == 'month' and count == '1':
             months += 1
+        elif unit == 'mon' and count == '1':
+            months += 1
         elif unit == 'months':
             months += int(count)
+        elif unit == 'mons':
+            months += int(count)
         elif unit == 'year' and count == '1':
             years += 1
         elif unit == 'years':

Modified: psycopgda/trunk/tests.py
===================================================================
--- psycopgda/trunk/tests.py	2005-01-23 01:59:08 UTC (rev 28916)
+++ psycopgda/trunk/tests.py	2005-01-24 10:06:15 UTC (rev 28917)
@@ -138,6 +138,8 @@
         # cannot represent them accurately
         self.assertEquals(c('1 month'), '1 month')
         self.assertEquals(c('2 months'), '2 months')
+        self.assertEquals(c('1 mon'), '1 mon')
+        self.assertEquals(c('2 mons'), '2 mons')
         self.assertEquals(c('1 year'), '1 year')
         self.assertEquals(c('3 years'), '3 years')
         # Later we might be able to use



More information about the Zope-CVS mailing list