Improved the logic used to determine when a calendar
authorArt Cancro <ajc@citadel.org>
Wed, 15 Oct 2008 15:17:19 +0000 (15:17 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 15 Oct 2008 15:17:19 +0000 (15:17 +0000)
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

index cf5ab1a0836ce52959aa943440f6da26bf2621f0..f982945e1750620422ae43622cee169146e26c9a 100644 (file)
@@ -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("<tr>");
-                       }
+       localtime_r(&thetime, &tm);
+        for (i = 0; i<42; ++i) {
 
-                       wprintf("<td class=\"cal%s\"><div class=\"day\">",
-                               ((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("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
-                               "%d</a></div>",
-                               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("<tr>");
+               }
 
-                       wprintf("</td>");
+               wprintf("<td class=\"cal%s\"><div class=\"day\">",
+                       ((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("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
+                       "%d</a></div>",
+                       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("</tr>\n");
-                       }
+               wprintf("</td>");
 
+               /* After displaying the last day of the week, end the row */
+               if ((i % 7) == 6) {
+                       wprintf("</tr>\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("</table>"                      /* end of inner table */