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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

rolfofsaxony
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/

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Robin Dunn

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 ;-)

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:
<<a href="http://wxpython-users.1045709.n5.nabble.com/file/t340556/Screenshot_at_2017-10-20_16-47-32.png" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwxpython-users.1045709.n5.nabble.com%2Ffile%2Ft340556%2FScreenshot_at_2017-10-20_16-47-32.png\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFAZQ05231d7rIeL4bBHCA58Sx45Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwxpython-users.1045709.n5.nabble.com%2Ffile%2Ft340556%2FScreenshot_at_2017-10-20_16-47-32.png\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFAZQ05231d7rIeL4bBHCA58Sx45Q&#39;;return true;">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: <a href="http://wxpython-users.1045709.n5.nabble.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwxpython-users.1045709.n5.nabble.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGwU_VyCKXCOe_gRYAG28IMARnUFA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwxpython-users.1045709.n5.nabble.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGwU_VyCKXCOe_gRYAG28IMARnUFA&#39;;return true;">http://wxpython-users.1045709.n5.nabble.com/

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Tim Roberts
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, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.