GNOME Bugzilla – Bug 168513
gtk.Calendar.get_date() reports the month in a manner inconsistent to other reporting
Last modified: 2005-04-01 06:36:39 UTC
Distribution/Version: Ubuntu gtk.Calendar.get_date() returns a tuple containing the year, month, and date in the form of (Y, M, D). This is fine by nature, but consider what happens when I perform the get_date() when I have today selected. Today is 2005-02-25, where Y = 2005; M = 2; D = 25. print calendar.get_date() => (2005, 1, 25) This is inconsistent, because instead of returning (Y, M, D), it returns (Y, M-1, D). Take a look at this sample example: #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk def date_changed(cal): print cal.get_date() window = gtk.Window(gtk.WINDOW_TOPLEVEL) calendar = gtk.Calendar() window.add(calendar) calendar.connect("day-selected", date_changed) calendar.show() window.show() gtk.main()
I think is correct the way it work, if you look at the method gtk.Calendar.select_month the month is between 0 and 11. We can discuss if is better this way or 1 to 12 but I don't think this is a bug.
Due to basic API inconsistencies, perhaps this issue should be forwarded to the GTK+ development team. From http://developer.gnome.org/doc/API/2.0/gtk/GtkCalendar.html#gtk-calendar-select-month: gboolean gtk_calendar_select_month (GtkCalendar *calendar, guint month, guint year); calendar: a GtkCalendar. month: a month number between 0 and 11. year: the year the month is in. void gtk_calendar_select_day (GtkCalendar *calendar, guint day); Selects a day from the current month. calendar: a GtkCalendar. day: the day number between 1 and 31, or 0 to unselect the currently selected day. Do not get me wrong here, but such an inconsistency is absolutely outrageous on the part of the GTK+ developers. If everything is represented as (Y, M-1, D), then it should either be (Y, M, D) or (Y-1, M-1, D-1); I just cannot see a logical or justifiable reason to have such an exception. Yes, changing this behavior could mean going out and reverifying much code; but conversely, the change could be made now before the inconsistency propagates itself anymore than it has. I would strongly encourage changing the product of this bug to GTK+.
struct tm in Unix uses a tm_mon in the range [0, 11]. I guess GTK+ does the same for consistency, as quirky as it may be.
Created attachment 39453 [details] [review] the proposed patch There was a discussion on gtk-app-devel about this subject: http://mail.gnome.org/archives/gtk-app-devel-list/2005-March/msg00283.html at the end was pointed out this part of the API reference: http://developer.gimp.org/api/2.0/gtk/GtkCalendar.html#GtkCalendar-struct where you can see the note about how gtk_calendar works, maybe is better to include such a note also in pygtk reference manual? If John Finlay will approve this I have prepared a patch.
Should add to get_date() docs as well.
Created attachment 39530 [details] [review] revised patch
* pygtk-gtkcalendar.xml (Description, get_date): Add note about month value starting at zero. Patch by Gian Mario Tagliaretti.