Recognize the max. dayes in a month

old-version-gtk3
Zwerg12 2020-07-07 20:58:17 +02:00
rodzic 4a73a6d275
commit 08a7b9c594
1 zmienionych plików z 23 dodań i 2 usunięć

Wyświetl plik

@ -82,15 +82,35 @@ static int search(GtkWidget *widget, gpointer data)
static int correct_time (GtkWidget *widget, gpointer data){
const char *entry_day_string;
const char *entry_month_string;
const char *entry_year_string;
int max_days = 30;
entry_day_string = gtk_entry_get_text(entry_day);
entry_month_string = gtk_combo_box_get_active_id(entry_month);
entry_year_string = gtk_entry_get_text(entry_year);
switch (atoi(entry_month_string))
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
max_days = 31;
break;
case 2:
if ((atoi(entry_year_string)%4==0 && atoi(entry_year_string)%100!=0) || atoi(entry_year_string)%400==0) {
max_days = 29;
}
else{
max_days = 28;
}
break;
}
g_print("Day entry: %s\n", entry_day_string);
g_print("Month entry: %s\n", entry_month_string);
g_print("Month entry: %i\n", atoi(entry_month_string));
g_print("Max days: %i\n", max_days);
return 1;
}
@ -173,6 +193,7 @@ int main( int argc, char *argv[] )
g_signal_connect (button_now, "clicked", G_CALLBACK(set_time_now), NULL);
g_signal_connect (button_calculate, "clicked", G_CALLBACK (calculate), NULL);
g_signal_connect (entry_month, "changed", G_CALLBACK (correct_time), NULL);
g_signal_connect (entry_year, "changed", G_CALLBACK (correct_time), NULL);
gtk_widget_show (window);