[Jython-checkins] jython: Fixes #2071 datetime.date.strftime support for %f.

jeff.allen jython-checkins at python.org
Mon Dec 2 21:31:02 CET 2013


http://hg.python.org/jython/rev/8b200f9ff1ea
changeset:   7165:8b200f9ff1ea
user:        Santoso Wijaya <santoso.wijaya at gmail.com>
date:        Sun Dec 01 21:18:48 2013 +0000
summary:
  Fixes #2071 datetime.date.strftime support for %f.

files:
  Lib/datetime.py           |  11 +++++++++--
  Lib/test/test_datetime.py |   1 -
  NEWS                      |   1 +
  3 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/Lib/datetime.py b/Lib/datetime.py
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -182,7 +182,7 @@
     return result
 
 # Correctly substitute for %z and %Z escapes in strftime formats.
-def _wrap_strftime(object, format, timetuple):
+def _wrap_strftime(object, format, timetuple, microsecond=0):
     year = timetuple[0]
     if year < 1900:
         raise ValueError("year=%d is before 1900; the datetime strftime() "
@@ -225,6 +225,9 @@
                                 # strftime is going to have at this: escape %
                                 Zreplace = s.replace('%', '%%')
                     newformat.append(Zreplace)
+                elif ch == 'f':
+                    us_string = '%.06d' % microsecond
+                    newformat.append(us_string)
                 else:
                     push('%')
                     push(ch)
@@ -1269,7 +1272,7 @@
         timetuple = (1900, 1, 1,
                      self.__hour, self.__minute, self.__second,
                      0, 1, -1)
-        return _wrap_strftime(self, fmt, timetuple)
+        return _wrap_strftime(self, fmt, timetuple, self.microsecond)
 
     # Timezone functions
 
@@ -1634,6 +1637,10 @@
         "Convert to string, for str()."
         return self.isoformat(sep=' ')
 
+    def strftime(self, fmt):
+        "Format using strftime()."
+        return _wrap_strftime(self, fmt, self.timetuple(), self.microsecond)
+
     def utcoffset(self):
         """Return the timezone offset in minutes east of UTC (negative west of
         UTC)."""
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -3353,7 +3353,6 @@
     if test_support.is_jython:
         del TestDate.test_format
         del TestDateTime.test_format
-        del TestDateTime.test_more_strftime
         del TestDateTime.test_strptime
         del TestTime.test_format
 
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@
     - [ 2033 ] test_strptime fails: test_mar1_comes_after_feb29_even_when_omitting_the_year
     - [ 2046 ] sys.stdin.readline() hangs when used interactively (JLine, Windows)
     - [ 2060 ] Thread ident missing
+    - [ 2071 ] datetime strftime %f does not work
     - [ 2082 ] Unexpected (Pdb) prompt during regression tests
 
 Jython 2.7b1

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list