After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 358116 - gtk_calendar_select_month does not update the month day when needed
gtk_calendar_select_month does not update the month day when needed
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkCalendar
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-09-28 11:03 UTC by Iago Toral
Modified: 2018-02-10 03:45 UTC
See Also:
GNOME target: ---
GNOME version: 2.17/2.18


Attachments
When the number of days of the newly selected month is lower than selected_day, sets selected_day to the number of days of the month (837 bytes, patch)
2006-09-28 11:05 UTC, Iago Toral
none Details | Review
Same patch, but adding notification on the day property when needed (1.19 KB, patch)
2006-09-28 11:35 UTC, Iago Toral
none Details | Review

Description Iago Toral 2006-09-28 11:03:10 UTC
Please describe the problem:
gtk_calendar_select_month can be used to move month selection to a month with a lower number of days (for example from January to February), but it does not check if currently selected day is valid for the newly selected month. This can result in an invalid date (for example 31th of February).

Steps to reproduce:

#include <gtk/gtk.h>

int main ()
{
  GtkCalendar *calendar;
  guint year = 2006;
  guint month = 0;
  guint day = 31;

  gtk_init (0, NULL);

  calendar = GTK_CALENDAR (gtk_calendar_new ());

  gtk_calendar_select_month (calendar, month, year);
  gtk_calendar_select_day (calendar, day);
  gtk_calendar_get_date (calendar, &year, &month, &day);

  g_print ("\nYear=%d, month=%d, day=%d\n", year, month, day);

  year = 2006;
  month = 1;

  gtk_calendar_select_month (calendar, month, year);
  gtk_calendar_get_date (calendar, &year, &month, &day);

  g_print ("\nYear=%d, month=%d, day=%d\n", year, month, day);

  gtk_widget_destroy (GTK_WIDGET (calendar));
  return 0;
}



Actual results:
Year=2006, month=0, day=31
Year=2008, month=1, day=31 -> Invalid date


Expected results:
Year=2006, month=0, day=31
Year=2006, month=1, day=28

Does this happen every time?
Yes

Other information:
Comment 1 Iago Toral 2006-09-28 11:05:54 UTC
Created attachment 73550 [details] [review]
When the number of days of the newly selected month is lower than selected_day, sets selected_day to the number of days of the month
Comment 2 Iago Toral 2006-09-28 11:35:47 UTC
Created attachment 73551 [details] [review]
Same patch, but adding notification on the day property when needed

Fixes the previous patch by adding g_object_notify for "day" property when needed.
Comment 3 Matthias Clasen 2006-10-02 01:34:12 UTC
Not sure that this is really the expected behaviour.
It means for instance that switching from January to February and back can change the selected day.
Comment 4 Iago Toral 2006-10-02 07:29:47 UTC
Mmm... yes, you are right. However, if I would have to select a behavior I'd prefer the calendar to be consistent (never provide an invalid date) than maintaining the day between to month selections.

In order to solve the problem you point out I guess it would be possible to store the day number. For example, if I have 31th Jan and switch the month to Feb, I can detect that I have to fix the day and save the old valid day number (31). Then, when a selection of a month with 31 days happens, I can set the day number back to 31.

A complete example would be like this:

31th Jan -> 28th Feb -> 28/30th Apr -> 31th Jan
         (1)         (2)           (3)

(1) saved=31, fixed=28
(2) Month has more days than last fixed month, so try to set day number back again. However this month has 30 days, not 31, should we set day number to 30 or leave it be 28?
(3) Month has more days than last fixed month and the saved number of days fits in it, so we can set day number back.
Comment 5 Matthias Clasen 2018-02-10 03:45:37 UTC
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and
still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue
for it.