Here's a working patch to make formatting of a DateTime instance work as
generally expected, when you use

  <dtml-var "_.DateTime()" fmt="%d %G %z">

or whatever.

It could be made more efficient by compiling the two regex (regexes?
regexen? regular expressions :-) ) into class attributes.

Here's the method I changed:

      def strftime(self, format):
          diff=_tzoffset(self._tz, self._t)
          format = ts_regex.gsub('\(^\|[^%]\)%Z', '\\1'+self._tz,
format)
          format = ts_regex.gsub('\(^\|[^%]\)%z', '\\1%+05d' %
(diff/36), format)
          return strftime(format, gmtime(self.timeTime()+diff))
  
Instead of just calling gmtime with the time as held in the DateTime
instace, it subverts time.strftime into formatting the time shifted
according to the instance's timezone.

Because time.strftime won't format the timezone information correctly,
this is done using regular expressions before the format specification
string is passed to time.strftime.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net
*** lib/python/DateTime/DateTime.old.py Sun Jul 23 20:03:04 2000
--- lib/python/DateTime/DateTime.py     Mon Jul 24 14:01:37 2000
***************
*** 1376,1382 ****
          return millis
  
      def strftime(self, format):
!         return strftime(format, gmtime(self.timeTime()))
  
      # General formats from previous DateTime
      def Date(self):
--- 1376,1385 ----
          return millis
  
      def strftime(self, format):
!         diff=_tzoffset(self._tz, self._t)
!         format = ts_regex.gsub('\(^\|[^%]\)%Z', '\\1'+self._tz, format)
!         format = ts_regex.gsub('\(^\|[^%]\)%z', '\\1%+05d' % (diff/36), format)
!         return strftime(format, gmtime(self.timeTime()+diff))
  
      # General formats from previous DateTime
      def Date(self):

Reply via email to