mirror of
https://github.com/python/cpython.git
synced 2025-09-11 03:07:01 +00:00
add %f format to datetime - issue 1158
This commit is contained in:
parent
75e51680f1
commit
fc070d2731
6 changed files with 181 additions and 80 deletions
|
@ -1507,11 +1507,12 @@ class TestDateTime(TestDate):
|
|||
self.failUnless(abs(from_timestamp - from_now) <= tolerance)
|
||||
|
||||
def test_strptime(self):
|
||||
import time
|
||||
import _strptime
|
||||
|
||||
string = '2004-12-01 13:02:47'
|
||||
format = '%Y-%m-%d %H:%M:%S'
|
||||
expected = self.theclass(*(time.strptime(string, format)[0:6]))
|
||||
string = '2004-12-01 13:02:47.197'
|
||||
format = '%Y-%m-%d %H:%M:%S.%f'
|
||||
result, frac = _strptime._strptime(string, format)
|
||||
expected = self.theclass(*(result[0:6]+(frac,)))
|
||||
got = self.theclass.strptime(string, format)
|
||||
self.assertEqual(expected, got)
|
||||
|
||||
|
@ -1539,9 +1540,9 @@ class TestDateTime(TestDate):
|
|||
|
||||
def test_more_strftime(self):
|
||||
# This tests fields beyond those tested by the TestDate.test_strftime.
|
||||
t = self.theclass(2004, 12, 31, 6, 22, 33)
|
||||
self.assertEqual(t.strftime("%m %d %y %S %M %H %j"),
|
||||
"12 31 04 33 22 06 366")
|
||||
t = self.theclass(2004, 12, 31, 6, 22, 33, 47)
|
||||
self.assertEqual(t.strftime("%m %d %y %f %S %M %H %j"),
|
||||
"12 31 04 000047 33 22 06 366")
|
||||
|
||||
def test_extract(self):
|
||||
dt = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
|
||||
|
@ -1814,7 +1815,7 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
|
|||
|
||||
def test_strftime(self):
|
||||
t = self.theclass(1, 2, 3, 4)
|
||||
self.assertEqual(t.strftime('%H %M %S'), "01 02 03")
|
||||
self.assertEqual(t.strftime('%H %M %S %f'), "01 02 03 000004")
|
||||
# A naive object replaces %z and %Z with empty strings.
|
||||
self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue