wxDateTime.SetYear(...) fails on WinXP

Robin Dunn wrote:

sashan wrote:

The following fails in windows XP with wxWidgets 2.4.2 and wxPython 2.4

dt = wxDateTime
dt.SetYear(2003)

fails on Windows XP with the following error:
...datetime.cpp (1466) assert "IsValid()" failed....

I don't think this happens on Linux. I'm going to reboot and check.

If you are running this from the Interactive Interpreter then the problem is that SetYear returns a copy of the datetime object, and the interpreter is trying to print it. The __str__ method calls Format which is raising the exception.

Returning the instance lets you do silly things like this:

    dt.SetYear(2003).SetMonth(wx.DateTime.Mar).SetDay(6)

If I understand correctly then running this from the interpreter:

>>> dt = wxDateTime()
>>> ret = dt.SetYear(2003)

should be ok. However I get the same assertion
    c:\PROJECTS\wx\src\common\datetime.cpp(1466): assert "IsValid()" failed: invalid wxDateTime

So I tried checking if the datetime object is valid on construction:
>>> dt = wxDateTime()
>>> dt.IsValid()
0

As you can see, it returns 0 (i.e. invalid).

I can work around it like by explicitly setting the time.

now = time.localtime()
dt = wxDateTimeFromDMY(now[2], now[1], now[0], now[3], now[4], now[5])

ยทยทยท

--
sashan
http://www.cs.auckland.ac.nz/~sgov008/