[Zope-dev] DateTime Patch

Casey Duncan cduncan@kaivo.com
Mon, 12 Feb 2001 09:56:32 -0700


This is a multi-part message in MIME format.
--------------1F38A174B9E38D2213CD4382
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have concluded that DateTime has bugs in its isCurrent* methods.

Basically isCurrentMinute, isCurrentHour, isCurrentDay and
isCurrentMonth all would return true at inappropriate times. For
instance, isCurrentDay will currently return true if the day number of
the date is equal to the current day number regardless of current month
or year. The others behave in a similar manner.

Attached is a patch for DateTime.py that fixes the above. I am also
submitting it to the collector.

Enjoy.
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>
--------------1F38A174B9E38D2213CD4382
Content-Type: text/plain; charset=us-ascii;
 name="DateTime.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="DateTime.patch"

*** DateTime.py.old	Mon Feb 12 08:40:23 2001
--- DateTime.py	Mon Feb 12 09:40:22 2001
***************
*** 1153,1180 ****
             that falls within the current month, in the context
             of this object\'s timezone representation"""
          t=time()
!         return safegmtime(t+_tzoffset(self._tz, t))[1]==self._month
  
      def isCurrentDay(self):
          """Return true if this object represents a date/time
             that falls within the current day, in the context
             of this object\'s timezone representation"""
          t=time()
!         return safegmtime(t+_tzoffset(self._tz, t))[2]==self._day
  
      def isCurrentHour(self):
          """Return true if this object represents a date/time
             that falls within the current hour, in the context
             of this object\'s timezone representation"""
          t=time()
!         return safegmtime(t+_tzoffset(self._tz, t))[3]==self._hour
  
      def isCurrentMinute(self):
          """Return true if this object represents a date/time
             that falls within the current minute, in the context
             of this object\'s timezone representation"""
          t=time()
!         return safegmtime(t+_tzoffset(self._tz, t))[4]==self._minute
  
      def earliestTime(self):
          """Return a new DateTime object that represents the earliest
--- 1153,1186 ----
             that falls within the current month, in the context
             of this object\'s timezone representation"""
          t=time()
!         gmt=safegmtime(t+_tzoffset(self._tz, t))
!         return gmt[0]==self._year and gmt[1]==self._month
  
      def isCurrentDay(self):
          """Return true if this object represents a date/time
             that falls within the current day, in the context
             of this object\'s timezone representation"""
          t=time()
!         gmt=safegmtime(t+_tzoffset(self._tz, t))
!         return gmt[0]==self._year and gmt[1]==self._month and gmt[2]==self._day
! 
  
      def isCurrentHour(self):
          """Return true if this object represents a date/time
             that falls within the current hour, in the context
             of this object\'s timezone representation"""
          t=time()
!         gmt=safegmtime(t+_tzoffset(self._tz, t))
!         return gmt[0]==self._year and gmt[1]==self._month and gmt[2]==self._day and gmt[3]==self._hour
  
      def isCurrentMinute(self):
          """Return true if this object represents a date/time
             that falls within the current minute, in the context
             of this object\'s timezone representation"""
          t=time()
!         gmt=safegmtime(t+_tzoffset(self._tz, t))
!         return gmt[0]==self._year and gmt[1]==self._month and gmt[2]==self._day and gmt[3]==self._hour and gmt[4]==self._minute
! 
  
      def earliestTime(self):
          """Return a new DateTime object that represents the earliest

--------------1F38A174B9E38D2213CD4382--