mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-08 04:50:07 +01:00
Add some helper functions for converting to/from Python datetime objects similar to what is in Classic.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@70899 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -351,6 +351,30 @@ def run():
|
||||
bool operator!=(const wxTimeSpan &ts) const;
|
||||
"""))
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
# Convert to/from Python date objects
|
||||
module.addPyFunction('pydate2wxdate', '(date)',
|
||||
doc='Convert a Python date or datetime to a wx.DateTime object',
|
||||
body="""\
|
||||
import datetime
|
||||
assert isinstance(date, (datetime.datetime, datetime.date))
|
||||
return DateTime(date) # the built-in typemap will convert it for us
|
||||
""")
|
||||
|
||||
module.addPyFunction('wxdate2pydate', '(date)',
|
||||
doc='Convert a wx.DateTime object to a Python datetime.',
|
||||
body="""\
|
||||
import datetime
|
||||
assert isinstance(date, DateTime)
|
||||
if date.IsValid():
|
||||
return datetime.datetime(date.year, date.month+1, date.day,
|
||||
date.hour, date.minute, date.second, date.millisecond*1000)
|
||||
else:
|
||||
return None
|
||||
""")
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
tools.doCommonTweaks(module)
|
||||
|
||||
@@ -127,7 +127,16 @@ class datetime_Tests(wtc.WidgetTestCase):
|
||||
d2 = wx.DateTime()
|
||||
d2.ParseFormat(st, fmt)
|
||||
self.assertEqual(d, d2)
|
||||
|
||||
|
||||
def test_datetimeConvertHelpers(self):
|
||||
d1 = wx.DateTime(1, wx.DateTime.Mar, 2012, 8, 15, 45)
|
||||
pd = wx.wxdate2pydate(d1)
|
||||
d2 = wx.pydate2wxdate(pd)
|
||||
self.assertTrue(isinstance(pd, datetime.datetime))
|
||||
self.assertEqual(d1, d2)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user