wx.calendar issue with month number returned by GetDate()

If this is the wrong place to post bug reports, please let me know the right
place.

wx.calendar.GenericCalendarCtrl and wx.adv.CalendarCtrl both return the
incorrect month number from the GetDate() function.
Both appear to be using a Zero based month list.
When clicking on the 31st December 2017, after calling GetDate() the year
will be 2017 the day will be 31 and the month will be 11.
When clicking on the 1st January 2017, after calling GetDate() the year will
be 2017 the day will be 1 and the month will be 0.

#py3
import wx.adv
#py2
#import wx
#import wx.calendar

class MainFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title='Calendar',size=(300,200))
        self.panel = wx.Panel(self)
        #py3
        self.datepick = wx.adv.CalendarCtrl(self.panel,-1)
        self.datepick.Bind(wx.adv.EVT_CALENDAR, self.OnAction)
        #py2
        #self.datepick = wx.calendar.GenericCalendarCtrl(self.panel,-1)
        #self.datepick.Bind(wx.calendar.EVT_CALENDAR, self.OnAction)
        self.Show()

    def OnAction(self,event):
        inp_date = self.datepick.GetDate()
        print ("Year Number", inp_date.GetYear())
        print ("Month Number", inp_date.GetMonth(),"Month Name",
inp_date.GetMonthName(inp_date.GetMonth()))
        print ("Day Numer", inp_date.GetDay())

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame()
    app.MainLoop()

Running this results in:
<http://wxpython-users.1045709.n5.nabble.com/file/t340556/Screenshot_at_2017-10-20_16-47-32.png>

Is it just me, or does this seem a bit odd?
Regards
Rolf

···

--
Sent from: http://wxpython-users.1045709.n5.nabble.com/

Yes, it’s odd, but it is what it is. In C++ the month is actually an enum where January happens to have an integer value of zero. In Python those enum values map to and from integers transparently, so it’s easy to get confused. But if you just use the symbolic names instead of the numbers then it becomes easier to understand and it would work even if January had a value of 27 :wink:

You can access the enum value names as attributes of the wx.DateTime class, like wx.DateTime.Jan, wxDateTime.Feb, etc.

Robin

···

On Sunday, October 22, 2017 at 9:08:08 AM UTC-7, rolfofsaxony wrote:

If this is the wrong place to post bug reports, please let me know the right

place.

wx.calendar.GenericCalendarCtrl and wx.adv.CalendarCtrl both return the

incorrect month number from the GetDate() function.

Both appear to be using a Zero based month list.

When clicking on the 31st December 2017, after calling GetDate() the year

will be 2017 the day will be 31 and the month will be 11.

When clicking on the 1st January 2017, after calling GetDate() the year will

be 2017 the day will be 1 and the month will be 0.

#py3

import wx.adv

#py2

#import wx

#import wx.calendar

class MainFrame(wx.Frame):

def __init__(self):

    wx.Frame.__init__(self, None, title='Calendar',size=(300,200))

    self.panel = wx.Panel(self)

    #py3

    self.datepick = wx.adv.CalendarCtrl(self.panel,-1)

    self.datepick.Bind(wx.adv.EVT_CALENDAR, self.OnAction)

    #py2

    #self.datepick = wx.calendar.GenericCalendarCtrl(self.panel,-1)

    #self.datepick.Bind(wx.calendar.EVT_CALENDAR, self.OnAction)

    self.Show()





def OnAction(self,event):

    inp_date = self.datepick.GetDate()

    print ("Year Number",  inp_date.GetYear())

    print ("Month Number", inp_date.GetMonth(),"Month Name",

inp_date.GetMonthName(inp_date.GetMonth()))

    print ("Day Numer",   inp_date.GetDay())

if name == ‘main’:

app = wx.App()

frame = MainFrame()

app.MainLoop()

Running this results in:

<http://wxpython-users.1045709.n5.nabble.com/file/t340556/Screenshot_at_2017-10-20_16-47-32.png>

Is it just me, or does this seem a bit odd?

Regards

Rolf

Sent from: http://wxpython-users.1045709.n5.nabble.com/

Robin Dunn wrote:

Yes, it's odd, but it is what it is. In C++ the month is actually an
enum where January happens to have an integer value of zero.

This was one of the huge mistakes of the original designers of Unix and
C. The localtime and gmtime functions, which convert the "number of
seconds" time value to a broken out "struct tm", sets the month value in
tm_mon from 0 to 11. Huge mistake, and programmers have been paying for
it ever since.

The other mistake, which Kernigan has publicly admitted, was naming the
file creation function "creat" instead of "create"...

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.