wx.DateTime <> python datetime

The wx.DatePickerCtrl returns a wx.DateTime value and doesn't appear to
have a PyGetDate method (or did I miss that). Is there a simple way to
get a python datetime from a wx.DateTime, other than brute force:

d = datetime(wx.DateTime.Year (wx.DateTime.Month + 1) % 12,
wx.DateTime.Day)

(wx.DateTime months appear to go from 0 .. 11)

Mark

def Cvt_wxDateTime_To_date( mwxDateTime):
#CConverts a value wx.DateTime into a datetime.date
return datetime.date(int(mwxDateTime.GetYear()),
int(mwxDateTime.GetMonth() + 1), int(mwxDateTime.GetDay
()))

In fact, wx.DateTime months goes from 0 to 11.

···

2008/1/13, Mark Erbaugh mark@microenh.com:

The wx.DatePickerCtrl returns a wx.DateTime value and doesn’t appear to
have a PyGetDate method (or did I miss that). Is there a simple way to
get a python datetime from a wx.DateTime, other than brute force:

d = datetime(wx.DateTime.Year (wx.DateTime.Month + 1) % 12,
wx.DateTime.Day)

(wx.DateTime months appear to go from 0 … 11)

Mark


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

Ours goes to eleven… seems we’ve gone from Python to Spinal Tap?

···

On Jan 13, 2008 12:37 PM, Raffaello Barella <barbarossa.platz@gmail.com > wrote:

def Cvt_wxDateTime_To_date( mwxDateTime):
#CConverts a value wx.DateTime
into a datetime.date
return datetime.date(int(mwxDateTime.GetYear()),
int(mwxDateTime.GetMonth() + 1), int(mwxDateTime.GetDay
()))

In fact, wx.DateTime months goes from 0 to 11.

2008/1/13, Mark Erbaugh mark@microenh.com:

The wx.DatePickerCtrl returns a wx.DateTime value and doesn’t appear to
have a PyGetDate method (or did I miss that). Is there a simple way to
get a python datetime from a wx.DateTime, other than brute force:

d = datetime(wx.DateTime.Year (wx.DateTime.Month + 1) % 12,
wx.DateTime.Day)

(wx.DateTime months appear to go from 0 … 11)

Mark


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:

wxPython-users-help@lists.wxwidgets.org


www.fsrtechnologies.com

Mark Erbaugh wrote:

The wx.DatePickerCtrl returns a wx.DateTime value and doesn't appear to
have a PyGetDate method (or did I miss that). Is there a simple way to
get a python datetime from a wx.DateTime, other than brute force:

You can use the same helper functions used in the wx.calendar module to implement Py[SG]etDate. They're implemented like this:

def _pydate2wxdate(date):
     import datetime
     assert isinstance(date, (datetime.datetime, datetime.date))
     tt = date.timetuple()
     dmy = (tt[2], tt[1]-1, tt[0])
     return wx.DateTimeFromDMY(*dmy)

def _wxdate2pydate(date):
     import datetime
     assert isinstance(date, wx.DateTime)
     if date.IsValid():
         ymd = map(int, date.FormatISODate().split('-'))
         return datetime.date(*ymd)
     else:
         return None

I'll go ahead and move those to a common module and add similar methods to wx.DatePickerCtrl too.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!