From cf2663dc7410333254b5e1af2f48bc2e205bcb01 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 15 Oct 2008 15:17:19 +0000 Subject: [PATCH] Improved the logic used to determine when a calendar month view needs to display 42 boxes instead of 35. Some months were displaying a spurious fifth row containing only the next month or, even worse, a row with a single box for the last day of the month. --- webcit/calendar_view.c | 81 +++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index cf5ab1a08..f982945e1 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -475,7 +475,6 @@ void calendar_month_view(int year, int month, int day) { time_t colheader_time; struct tm colheader_tm; char colheader_label[32]; - int chg_month = 0; long weekstart = 0; /* @@ -554,56 +553,50 @@ void calendar_month_view(int year, int month, int day) { /* Now do 35 or 42 days */ - for (i = 0; i < 42; ++i) { - localtime_r(&thetime, &tm); - - if ((i < 35) || (chg_month == 0)) { - - if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) { - chg_month = 1; - } - if (i > 35) { - chg_month = 0; - } - - /* Before displaying the first day of the week, start a new row */ - if ((i % 7) == 0) { - wprintf(""); - } + localtime_r(&thetime, &tm); + for (i = 0; i<42; ++i) { - wprintf("
", - ((tm.tm_mon != month-1) ? "out" : - ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" : - "day")) - ); - if ((i==0) || (tm.tm_mday == 1)) { - wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm); - wprintf("%s ", colheader_label); - } - wprintf("" - "%d
", - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday, - tm.tm_mday); - - /* put the data here, stupid */ - calendar_month_view_display_events( - tm.tm_year + 1900, - tm.tm_mon + 1, - tm.tm_mday - ); + /* Before displaying the first day of the week, start a new row */ + if ((i % 7) == 0) { + wprintf(""); + } - wprintf(""); + wprintf("
", + ((tm.tm_mon != month-1) ? "out" : + ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" : + "day")) + ); + if ((i==0) || (tm.tm_mday == 1)) { + wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm); + wprintf("%s ", colheader_label); + } + wprintf("" + "%d
", + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday, + tm.tm_mday); + + /* put the data here, stupid */ + calendar_month_view_display_events( + tm.tm_year + 1900, + tm.tm_mon + 1, + tm.tm_mday + ); - /* After displaying the last day of the week, end the row */ - if ((i % 7) == 6) { - wprintf("\n"); - } + wprintf(""); + /* After displaying the last day of the week, end the row */ + if ((i % 7) == 6) { + wprintf("\n"); } thetime += (time_t)86400; /* ahead 24 hours */ + localtime_r(&thetime, &tm); + + if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) { + i = 100; /* break out of the loop */ + } } wprintf("" /* end of inner table */ -- 2.30.2