When determining the week start day for the rendering
authorArt Cancro <ajc@citadel.org>
Tue, 5 Aug 2008 16:55:58 +0000 (16:55 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 5 Aug 2008 16:55:58 +0000 (16:55 +0000)
of a monthly calendar, check to see if the weekstart value from
preferences is higher than 6.  If so, use a value of 0 (Sunday)
instead of actively looping forever in a futile search for an
invalid wday.

webcit/calendar_view.c

index 4796713174648eb902be7ac40616ca46f5a92efb..3dcd91652654db03e65d716cdf45314580a3519d 100644 (file)
@@ -26,9 +26,10 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
 
        snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
 
-       /* Determine what day to start.
+       /* Determine what day to start.  If an impossible value is found, start on Sunday.
        */
        get_pref_long("weekstart", &weekstart, 17);
+       if (weekstart > 6) weekstart = 0;
 
        /*
        * Now back up to the 1st of the month...
@@ -481,9 +482,10 @@ void calendar_month_view(int year, int month, int day) {
        long weekstart = 0;
 
        /*
-        * Determine what day to start
+        * Determine what day to start.  If an impossible value is found, start on Sunday.
         */
        get_pref_long("weekstart", &weekstart, 17);
+       if (weekstart > 6) weekstart = 0;
 
        /*
         * Now back up to the 1st of the month...
@@ -509,7 +511,9 @@ void calendar_month_view(int year, int month, int day) {
        localtime_r(&thetime, &tm);
        while (tm.tm_wday != weekstart) {
                thetime = thetime - (time_t)86400;      /* go back 24 hours */
+               lprintf(9, "Subtracting a day, thetime is now %d - %s", thetime, ctime(&thetime));
                localtime_r(&thetime, &tm);
+               lprintf(9, "tm.tm_wday is %d, weekstart is %d\n", tm.tm_wday, weekstart);
        }
 
        /* Outer table (to get the background color) */