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 357945 - gtk_calendar_select_day does not validate the day properly
gtk_calendar_select_day does not validate the day properly
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-27 10:32 UTC by Iago Toral
Modified: 2018-02-10 03:36 UTC
See Also:
GNOME target: ---
GNOME version: 2.17/2.18


Attachments
Fixes the problem checking the day number against the month_length array (328 bytes, patch)
2006-09-28 10:42 UTC, Iago Toral
none Details | Review

Description Iago Toral 2006-09-27 10:32:58 UTC
Please describe the problem:
It is possible to set dates like 30th of February or 31th of June. This happens becasue the only check done in gtk_calendar_select_day is whether the day is lower than or equal to 31.

Steps to reproduce:
#include <gtk/gtk.h>

int main ()
{
  GtkCalendar *calendar;
  guint year = 2006;
  guint month = 1;
  guint day = 30;

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

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


Actual results:
Year=2006, month=1, day=30

Expected results:
The day should be clamped to 28 or not being modified at all.

Does this happen every time?
Yes

Other information:
Comment 1 Iago Toral 2006-09-28 10:42:03 UTC
Created attachment 73547 [details] [review]
Fixes the problem checking the day number against the month_length array
Comment 2 Björn Lindqvist 2008-03-23 16:55:36 UTC
The patch changes documented behavior so the api documentation needs to be updated. Then what should be done when a valid date is selected for the specified month and the month is then changed?

  // Goto 20080131
  gtk_calendar_select_month (cal, 0, 2008);
  gtk_calendar_select_day (cal, 31);
  // Goto 20080231 ... Ooops!
  gtk_calendar_select_month (cal, 1, 2008);

gtk_calendar_mark_day() and gtk_calendar_unmark_day() probably also should be updated to guard against invalid dates.
Comment 3 John 2009-03-02 17:47:06 UTC
I would suggest an atomic function which sets day, month, and year in one operation. If necessary, fields with -1 could be ignored to mimic the actual select functions:

gtk_calendar_set_date(GtkCalendar *calendar, guint day, guint month, guint year);

This way, a completer validation can be done - if setting the day causes a conflict, set month/year first then check day again. Else the problem exists
two ways:

calendar_invalidate_day_num runs through the days of the current month,
and check if the requested day exists.

So, if I'm in February, and set the day to (29,) 30, 31, I get an error,
if I understand this correctly.

But an error also occurs if I'm on March, 31th, and set the month/year
first to February.

John
Comment 4 Matthias Clasen 2018-02-10 03:36:46 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.