[pypy-svn] r58813 - in pypy/branch/2.5-merge/pypy/lib: . app_test
iko at codespeak.net
iko at codespeak.net
Wed Oct 8 14:11:51 CEST 2008
Author: iko
Date: Wed Oct 8 14:11:50 2008
New Revision: 58813
Modified:
pypy/branch/2.5-merge/pypy/lib/app_test/test_datetime.py
pypy/branch/2.5-merge/pypy/lib/datetime.py
Log:
(iko, cfbolz)
Add strptime to datetime.datetime
Modified: pypy/branch/2.5-merge/pypy/lib/app_test/test_datetime.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/lib/app_test/test_datetime.py (original)
+++ pypy/branch/2.5-merge/pypy/lib/app_test/test_datetime.py Wed Oct 8 14:11:50 2008
@@ -5,3 +5,13 @@
print datetime
expected = "datetime.datetime(1, 2, 3, 0, 0)"
assert repr(datetime.datetime(1,2,3)) == expected
+
+def test_strptime():
+ import time
+
+ string = '2004-12-01 13:02:47'
+ format = '%Y-%m-%d %H:%M:%S'
+ expected = datetime.datetime(*(time.strptime(string, format)[0:6]))
+ got = datetime.datetime.strptime(string, format)
+ assert expected == got
+
Modified: pypy/branch/2.5-merge/pypy/lib/datetime.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/lib/datetime.py (original)
+++ pypy/branch/2.5-merge/pypy/lib/datetime.py Wed Oct 8 14:11:50 2008
@@ -1576,6 +1576,11 @@
"Convert to string, for str()."
return self.isoformat(sep=' ')
+ @classmethod
+ def strptime(cls, date_string, format):
+ 'string, format -> new datetime parsed from a string (like time.strptime()).'
+ return cls(*_time.strptime(date_string, format)[0:6])
+
def utcoffset(self):
"""Return the timezone offset in minutes east of UTC (negative west of
UTC)."""
More information about the Pypy-commit
mailing list