Author: juha
Date: 2006-09-04 19:19:40 +0000 (Mon, 04 Sep 2006)
New Revision: 23080

Modified:
   xfcalendar/trunk/libical/src/libical/icalduration.c
   xfcalendar/trunk/libical/src/libical/icalmime.c
   xfcalendar/trunk/libical/src/libical/icalrecur.c
   xfcalendar/trunk/libical/src/libical/icalrecur.h
   xfcalendar/trunk/libical/src/libical/icaltime.c
   xfcalendar/trunk/libical/src/libical/icaltime.h
Log:
Fixes to libical:
1) start of weekday fix. Monday is now default (like the standard says) instead
   of Sunday and it can be defined as any day (=WKST now works).
2) minor fixes for string handling here and there
3) monthday processing fix (although orage does not (yet?) allow to define it.
These fixes came from libical SVN, but they were modified a little since we had
some fixes already, which are not in SVN.


Modified: xfcalendar/trunk/libical/src/libical/icalduration.c
===================================================================
--- xfcalendar/trunk/libical/src/libical/icalduration.c 2006-09-04 19:18:10 UTC 
(rev 23079)
+++ xfcalendar/trunk/libical/src/libical/icalduration.c 2006-09-04 19:19:40 UTC 
(rev 23080)
@@ -40,9 +40,11 @@
 #include "icalmemory.h"
 #include "icalvalue.h"
 
+#ifdef WIN32
+#define snprintf _snprintf
+#endif
 
 
-
 /* From Seth Alves,  <[EMAIL PROTECTED]>   */
 struct icaldurationtype icaldurationtype_from_int(int t)
 {
@@ -183,14 +185,13 @@
     return icaldurationtype_bad_duration();
 }
 
-#define TMP_BUF_SIZE 1024
 static
 void append_duration_segment(char** buf, char** buf_ptr, size_t* buf_size, 
                             char* sep, unsigned int value) {
 
-    char temp[TMP_BUF_SIZE];
+    char temp[32];
 
-    sprintf(temp,"%d",value);
+    snprintf(temp,sizeof(temp),"%d",value);
 
     icalmemory_append_string(buf, buf_ptr, buf_size, temp);
     icalmemory_append_string(buf, buf_ptr, buf_size, sep);

Modified: xfcalendar/trunk/libical/src/libical/icalmime.c
===================================================================
--- xfcalendar/trunk/libical/src/libical/icalmime.c     2006-09-04 19:18:10 UTC 
(rev 23079)
+++ xfcalendar/trunk/libical/src/libical/icalmime.c     2006-09-04 19:19:40 UTC 
(rev 23080)
@@ -199,7 +199,7 @@
            minor = parts[i].header.minor_text;
        }
        
-       sprintf(mimetype,"%s/%s",major,minor);
+       snprintf(mimetype,sizeof(mimetype),"%s/%s",major,minor);
 
        comp = icalcomponent_new(ICAL_XLICMIMEPART_COMPONENT);
 
@@ -209,9 +209,13 @@
        }
 
        if(parts[i].header.error!=SSPM_NO_ERROR){
-           char *str = NULL;
-           char* temp[256];
+           char *str = "Unknown error";
+           char temp[256];
 
+           if(parts[i].header.error==SSPM_MALFORMED_HEADER_ERROR){
+               str = "Malformed header, possibly due to input not in MIME 
format";
+           }
+
            if(parts[i].header.error==SSPM_UNEXPECTED_BOUNDARY_ERROR){
                str = "Got an unexpected boundary, possibly due to a MIME 
header for a MULTIPART part that is missing the Content-Type line";
            }
@@ -231,16 +235,16 @@
            }
 
            if(parts[i].header.error_text != 0){
-               snprintf((char*)temp,256,
+               snprintf(temp,sizeof(temp),
                         "%s: %s",str,parts[i].header.error_text);
            } else {
-               strcpy((char*)temp,str);
+               strcpy(temp,str);
            }
 
            icalcomponent_add_property
                (comp,
                 icalproperty_vanew_xlicerror(
-                    (char*)temp,
+                    temp,
                     icalparameter_new_xlicerrortype(
                         ICAL_XLICERRORTYPE_MIMEPARSEERROR),
                     0));  

Modified: xfcalendar/trunk/libical/src/libical/icalrecur.c
===================================================================
--- xfcalendar/trunk/libical/src/libical/icalrecur.c    2006-09-04 19:18:10 UTC 
(rev 23079)
+++ xfcalendar/trunk/libical/src/libical/icalrecur.c    2006-09-04 19:19:40 UTC 
(rev 23080)
@@ -4,7 +4,7 @@
   CREATOR: eric 16 May 2000
   
   $Id$
-  $Locker$
+  $Locker:  $
     
 
  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
@@ -19,6 +19,9 @@
 
     The Mozilla Public License Version 1.0. You may obtain a copy of
     the License at http://www.mozilla.org/MPL/
+
+    2006-09-04 week start day fixes **Juha
+        based on CVS code
 */
 
 /**
@@ -138,6 +141,12 @@
 #include <stdint.h>
 #endif
 
+#ifndef HAVE_INTPTR_T
+#ifdef WIN32
+typedef long intptr_t;
+#endif
+#endif
+
 #include "icalrecur.h"
 
 #include "icalerror.h"
@@ -149,6 +158,10 @@
 #include <assert.h>
 #include <stddef.h> /* For offsetof() macro */
 
+#ifdef WIN32
+#define snprintf _snprintf
+#endif
+
 #include "pvl.h"
 
 /** This is the last year we will go up to, since 32-bit time_t values
@@ -300,6 +313,38 @@
 
 }
 
+/*
+ * Days in the BYDAY rule are expected by the code to be sorted, and while
+ * this may be the common case, the RFC doesn't actually mandate it. This
+ * function sorts the days taking into account the first day of week.
+ */
+static void
+sort_bydayrules(struct icalrecur_parser *parser)
+{
+    short *array;
+    int week_start, one, two, i, j;
+
+    array = parser->rt.by_day;
+    week_start = parser->rt.week_start;
+
+    for (i=0;
+        i<ICAL_BY_DAY_SIZE && array[i] != ICAL_RECURRENCE_ARRAY_MAX;
+        i++) {
+       for (j=0; j<i; j++) {
+           one = icalrecurrencetype_day_day_of_week(array[j]) - week_start;
+           if (one < 0) one += 7;
+           two = icalrecurrencetype_day_day_of_week(array[i]) - week_start;
+           if (two < 0) two += 7;
+
+           if (one > two) {
+               short tmp = array[j];
+               array[j] = array[i];
+               array[i] = tmp;
+           }
+       }
+    }
+}
+
 void icalrecur_add_bydayrules(struct icalrecur_parser *parser, const char* 
vals)
 {
 
@@ -358,6 +403,7 @@
 
     free(vals_copy);
 
+    sort_bydayrules(parser);
 }
 
 
@@ -396,40 +442,41 @@
            return parser.rt;
        }
 
-       if (strcmp(name,"FREQ") == 0){
+       if (strcasecmp(name,"FREQ") == 0){
            parser.rt.freq = icalrecur_string_to_freq(value);
-       } else if (strcmp(name,"COUNT") == 0){
+       } else if (strcasecmp(name,"COUNT") == 0){
            parser.rt.count = atoi(value);
-       } else if (strcmp(name,"UNTIL") == 0){
+       } else if (strcasecmp(name,"UNTIL") == 0){
            parser.rt.until = icaltime_from_string(value);
-       } else if (strcmp(name,"INTERVAL") == 0){
+       } else if (strcasecmp(name,"INTERVAL") == 0){
            parser.rt.interval = (short)atoi(value);
-       } else if (strcmp(name,"WKST") == 0){
+       } else if (strcasecmp(name,"WKST") == 0){
            parser.rt.week_start = icalrecur_string_to_weekday(value);
-       } else if (strcmp(name,"BYSECOND") == 0){
+           sort_bydayrules(&parser);
+       } else if (strcasecmp(name,"BYSECOND") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_second,
                                  ICAL_BY_SECOND_SIZE,value);
-       } else if (strcmp(name,"BYMINUTE") == 0){
+       } else if (strcasecmp(name,"BYMINUTE") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_minute,
                                  ICAL_BY_MINUTE_SIZE,value);
-       } else if (strcmp(name,"BYHOUR") == 0){
+       } else if (strcasecmp(name,"BYHOUR") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_hour,
                                  ICAL_BY_HOUR_SIZE,value);
-       } else if (strcmp(name,"BYDAY") == 0){
+       } else if (strcasecmp(name,"BYDAY") == 0){
            icalrecur_add_bydayrules(&parser,value);
-       } else if (strcmp(name,"BYMONTHDAY") == 0){
+       } else if (strcasecmp(name,"BYMONTHDAY") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_month_day,
                                  ICAL_BY_MONTHDAY_SIZE,value);
-       } else if (strcmp(name,"BYYEARDAY") == 0){
+       } else if (strcasecmp(name,"BYYEARDAY") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_year_day,
                                  ICAL_BY_YEARDAY_SIZE,value);
-       } else if (strcmp(name,"BYWEEKNO") == 0){
+       } else if (strcasecmp(name,"BYWEEKNO") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_week_no,
                                  ICAL_BY_WEEKNO_SIZE,value);
-       } else if (strcmp(name,"BYMONTH") == 0){
+       } else if (strcasecmp(name,"BYMONTH") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_month,
                                  ICAL_BY_MONTH_SIZE,value);
-       } else if (strcmp(name,"BYSETPOS") == 0){
+       } else if (strcasecmp(name,"BYSETPOS") == 0){
            icalrecur_add_byrules(&parser,parser.rt.by_set_pos,
                                  ICAL_BY_SETPOS_SIZE,value);
        } else {
@@ -497,13 +544,13 @@
     }
 
     if(recur->count != 0){
-       sprintf(temp,"%d",recur->count);
+       snprintf(temp,sizeof(temp),"%d",recur->count);
        icalmemory_append_string(&str,&str_p,&buf_sz,";COUNT=");
        icalmemory_append_string(&str,&str_p,&buf_sz, temp);
     }
 
-    if(recur->interval != 0){
-       sprintf(temp,"%d",recur->interval);
+    if(recur->interval != 1){
+       snprintf(temp,sizeof(temp),"%d",recur->interval);
        icalmemory_append_string(&str,&str_p,&buf_sz,";INTERVAL=");
        icalmemory_append_string(&str,&str_p,&buf_sz, temp);
     }
@@ -530,12 +577,12 @@
                    if (pos == 0)
                        icalmemory_append_string(&str,&str_p,&buf_sz,daystr);
                    else {
-                       sprintf(temp,"%d%s",pos,daystr);
+                       snprintf(temp,sizeof(temp),"%d%s",pos,daystr);
                        icalmemory_append_string(&str,&str_p,&buf_sz,temp);
                    }                  
                    
                } else {
-                   sprintf(temp,"%d",array[i]);
+                   snprintf(temp,sizeof(temp),"%d",array[i]);
                    icalmemory_append_string(&str,&str_p,&buf_sz, temp);
                }
                
@@ -544,9 +591,17 @@
                    icalmemory_append_char(&str,&str_p,&buf_sz,',');
                }
            }    
-       }   
+       }
     }
 
+    /* Monday is the default, so no need to write that out */
+    if ( recur->week_start != ICAL_MONDAY_WEEKDAY ) {
+       const char *daystr = icalrecur_weekday_to_string(
+               icalrecurrencetype_day_day_of_week( recur->week_start ));
+       icalmemory_append_string(&str,&str_p,&buf_sz,";WKST=");
+       icalmemory_append_string(&str,&str_p,&buf_sz,daystr);
+    }
+
     return  str;
 }
 
@@ -689,7 +744,6 @@
     return passes;
 } 
 
-#if 0
 static int count_byrules(icalrecur_iterator* impl)
 {
     int count = 0;
@@ -703,7 +757,6 @@
 
     return count;
 }
-#endif
 
 
 static void setup_defaults(icalrecur_iterator* impl, 
@@ -722,7 +775,7 @@
        impl->by_ptrs[byrule][0] = (short)deftime;
     }
 
-    /* Initialize the first occurence */
+    /* Initialize the first occurrence */
     if( freq != req && expand_map[freq].map[byrule] != CONTRACT){
        *timepart = impl->by_ptrs[byrule][0];
     }
@@ -861,7 +914,7 @@
 
     /* Rewrite some of the rules and set up defaults to make later
        processing easier. Primarily, t involves copying an element
-       from the start time into the coresponding BY_* array when the
+       from the start time into the corresponding BY_* array when the
        BY_* array is empty */
 
 
@@ -902,18 +955,14 @@
             monday. Otherwise, jumping to the next week ( jumping 7
             days ahead ) will skip over some occurrences in the
             second week. */
-         
-         /* This is probably a HACK. There should be some more
-             general way to solve this problem */
 
+         /* This depends on impl->by_ptrs[BY_DAY] being correctly sorted by
+          * day. This should probably be abstracted to make such assumption
+          * more explicit. */
          short dow = 
(short)(impl->by_ptrs[BY_DAY][0]-icaltime_day_of_week(impl->last));
-
-         if(dow < 0) {
-             /* initial time is after first day of BY_DAY data */
-
-             impl->last.day += dow;
-             impl->last = icaltime_normalize(impl->last);
-         }
+         if (dow > impl->rule.week_start-1) dow -= 7;
+         impl->last.day += dow;
+         impl->last = icaltime_normalize(impl->last);
       }
       
 
@@ -943,55 +992,57 @@
     /* If this is a monthly interval with by day data, then we need to
        set the last value to the appropriate day of the month */
 
-    if(impl->rule.freq == ICAL_MONTHLY_RECURRENCE &&
-       has_by_data(impl,BY_DAY)) {
+    if(impl->rule.freq == ICAL_MONTHLY_RECURRENCE)
+       if (has_by_data(impl,BY_DAY)) {
 
-       int dow = icalrecurrencetype_day_day_of_week(
-           impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]);  
-       int pos =  icalrecurrencetype_day_position(
-           impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]);  
-       
-       int poscount = 0;
-       int days_in_month = 
-            icaltime_days_in_month(impl->last.month, impl->last.year); 
-       
-        if(pos >= 0){
-            /* Count up from the first day pf the month to find the
-               pos'th weekday of dow ( like the second monday. ) */
+           int dow = icalrecurrencetype_day_day_of_week(
+               impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]);  
+           int pos =  icalrecurrencetype_day_position(
+               impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]);  
+           
+           int poscount = 0;
+           int days_in_month = 
+               icaltime_days_in_month(impl->last.month, impl->last.year); 
+           
+           if(pos >= 0){
+               /* Count up from the first day pf the month to find the
+                  pos'th weekday of dow ( like the second monday. ) */
 
-            for(impl->last.day = 1;
-                impl->last.day <= days_in_month;
-                impl->last.day++){
-                
-                if(icaltime_day_of_week(impl->last) == dow){
-                    if(++poscount == pos || pos == 0){
-                        break;
-                    }
-                }
-            }
-        } else {
-            /* Count down from the last day pf the month to find the
-               pos'th weekday of dow ( like the second to last monday. ) */
-            pos = -pos;
-            for(impl->last.day = days_in_month;
-                impl->last.day != 0;
-                impl->last.day--){
-                
-                if(icaltime_day_of_week(impl->last) == dow){
-                    if(++poscount == pos ){
-                        break;
-                    }
-                }
-            }
-        }
+               for(impl->last.day = 1;
+                   impl->last.day <= days_in_month;
+                   impl->last.day++){
+                   
+                   if(icaltime_day_of_week(impl->last) == dow){
+                       if(++poscount == pos || pos == 0){
+                           break;
+                       }
+                   }
+               }
+           } else {
+               /* Count down from the last day pf the month to find the
+                  pos'th weekday of dow ( like the second to last monday. ) */
+               pos = -pos;
+               for(impl->last.day = days_in_month;
+                   impl->last.day != 0;
+                   impl->last.day--){
+                   
+                   if(icaltime_day_of_week(impl->last) == dow){
+                       if(++poscount == pos ){
+                           break;
+                       }
+                   }
+               }
+           }
 
 
-       if(impl->last.day > days_in_month || impl->last.day == 0){
-           icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-           return 0;
+           if(impl->last.day > days_in_month || impl->last.day == 0){
+               icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+               return 0;
+           }
+       
+       } else if (has_by_data(impl,BY_MONTH_DAY)) {
+           impl->last = icaltime_normalize(impl->last);
        }
-       
-    }
 
 
 
@@ -1323,7 +1374,6 @@
 }
 
 
-#if 0
 static int next_yearday(icalrecur_iterator* impl)
 {
 
@@ -1356,7 +1406,6 @@
   return end_of_data;
 
 }
-#endif
 
 
 /* Returns the day of the month for the current month of t that is the
@@ -1540,7 +1589,7 @@
        */
 
   } else if (has_by_data(impl,BY_MONTH_DAY)) {
-      int day;
+      int day, days_in_month;
 
       assert( BYMDPTR[0]!=ICAL_RECURRENCE_ARRAY_MAX);
 
@@ -1553,16 +1602,41 @@
           increment_month(impl);          
       }
       
+      days_in_month = icaltime_days_in_month(impl->last.month,
+                                                   impl->last.year);
+
       day = BYMDPTR[BYMDIDX];
       
       if (day < 0) {
           day = icaltime_days_in_month(impl->last.month, impl->last.year) + 
day + 1;
       }
-      
+
+      if ( day > days_in_month){
+          impl->last.day = 1;
+
+          /* Did moving to the next month put us on a valid date? if
+             so, note that the new data is valid, if, not, mark it
+             invalid */
+
+          if(is_day_in_byday(impl,impl->last)){
+              data_valid = 1;
+          } else {
+              data_valid = 0; /* signal that impl->last is invalid */
+          }
+      }
+
       impl->last.day = day;
 
   } else {
+      int days_in_month;
+
       increment_month(impl);
+
+      days_in_month = icaltime_days_in_month(impl->last.month,
+                                                   impl->last.year);
+      if (impl->last.day > days_in_month){
+          data_valid = 0; /* signal that impl->last is invalid */
+      }
   }
 
   return data_valid;
@@ -1584,10 +1658,9 @@
       return 1;
   }
 
-  /* If we get here, we need to step to tne next day */
+  /* If we get here, we need to step to the next day */
 
   for (;;) {
-      struct icaltimetype tt = icaltime_null_time();
       BYDAYIDX++; /* Look at next elem in BYDAY array */
       
       /* Are we at the end of the BYDAY array? */
@@ -1600,14 +1673,11 @@
         that to get the next day */
       /* ignore position of dow ("4FR"), only use dow ("FR")*/
       dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[BYDAYIDX]); 
-      tt.year = impl->last.year;
-      tt.day = impl->last.day;
-      tt.month = impl->last.month;
+      dow -= impl->rule.week_start; /* Set Sunday to be 0 */
+      if (dow < 0) dow += 7;
 
-      start_of_week = icaltime_start_doy_of_week(tt);
+      start_of_week = icaltime_start_doy_week(impl->last, 
impl->rule.week_start);
       
-      dow--; /* Set Sunday to be 0 */
-      
       if(dow+start_of_week <1){
           /* The selected date is in the previous year. */
           if(!end_of_data){    
@@ -1705,9 +1775,8 @@
     
     for(i = 0; BYDAYPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){
         /* This is 1 (Sun) to 7 (Sat). */
-        int dow = 
-            icalrecurrencetype_day_day_of_week(BYDAYPTR[i]);  
-        int pos =  icalrecurrencetype_day_position(BYDAYPTR[i]);
+        int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[i]);  
+        int pos = icalrecurrencetype_day_position(BYDAYPTR[i]);
         
         if(pos == 0){
             /* The day was specified without a position -- it is just
@@ -2308,7 +2377,7 @@
     int i;
 
     for (i=0; wd_map[i].wd  != ICAL_NO_WEEKDAY; i++) {
-       if ( strcmp(str,wd_map[i].str) == 0){
+       if ( strcasecmp(str,wd_map[i].str) == 0){
            return wd_map[i].wd;
        }
     }
@@ -2349,7 +2418,7 @@
     int i;
 
     for (i=0; freq_map[i].kind != ICAL_NO_RECURRENCE ; i++) {
-       if ( strcmp(str,freq_map[i].str) == 0){
+       if ( strcasecmp(str,freq_map[i].str) == 0){
            return freq_map[i].kind;
        }
     }

Modified: xfcalendar/trunk/libical/src/libical/icalrecur.h
===================================================================
--- xfcalendar/trunk/libical/src/libical/icalrecur.h    2006-09-04 19:18:10 UTC 
(rev 23079)
+++ xfcalendar/trunk/libical/src/libical/icalrecur.h    2006-09-04 19:19:40 UTC 
(rev 23080)
@@ -16,6 +16,9 @@
 
     The Mozilla Public License Version 1.0. You may obtain a copy of
     the License at http://www.mozilla.org/MPL/
+
+    2006-09-04 week start day fixes  **Juha
+        based on CVS code
 */
 
 /**
@@ -179,6 +182,7 @@
 /** 0 == any of day of week. 1 == first, 2 = second, -2 == second to last, etc 
*/
 int icalrecurrencetype_day_position(short day);
 
+icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str);
 
 /** Recurrance rule parser */
 

Modified: xfcalendar/trunk/libical/src/libical/icaltime.c
===================================================================
--- xfcalendar/trunk/libical/src/libical/icaltime.c     2006-09-04 19:18:10 UTC 
(rev 23079)
+++ xfcalendar/trunk/libical/src/libical/icaltime.c     2006-09-04 19:19:40 UTC 
(rev 23080)
@@ -22,6 +22,8 @@
  The Original Code is eric. The Initial Developer of the Original
  Code is Eric Busboom
 
+ 2006-09-04 Added support for WKST = weekstart day **Juha
+       based on CVS code
 
  ======================================================================*/
 
@@ -251,9 +253,14 @@
     /* Copy the icaltimetype to a struct tm. */
     memset (&stm, 0, sizeof (struct tm));
 
-    stm.tm_sec = tt.second;
-    stm.tm_min = tt.minute;
-    stm.tm_hour = tt.hour;
+    if (icaltime_is_date(tt)) {
+       stm.tm_sec = stm.tm_min = stm.tm_hour = 0;
+    } else {
+       stm.tm_sec = tt.second;
+       stm.tm_min = tt.minute;
+       stm.tm_hour = tt.hour;
+    }
+
     stm.tm_mday = tt.day;
     stm.tm_mon = tt.month-1;
     stm.tm_year = tt.year-1900;
@@ -292,9 +299,14 @@
     /* Copy the icaltimetype to a struct tm. */
     memset (&stm, 0, sizeof (struct tm));
 
-    stm.tm_sec = tt.second;
-    stm.tm_min = tt.minute;
-    stm.tm_hour = tt.hour;
+    if (icaltime_is_date(tt)) {
+       stm.tm_sec = stm.tm_min = stm.tm_hour = 0;
+    } else {
+       stm.tm_sec = tt.second;
+       stm.tm_min = tt.minute;
+       stm.tm_hour = tt.hour;
+    }
+
     stm.tm_mday = tt.day;
     stm.tm_mon = tt.month-1;
     stm.tm_year = tt.year-1900;
@@ -454,28 +466,43 @@
        return jt.weekday + 1;
 }
 
-/** Day of the year that the first day of the week (Sunday) is on.
- * 
- *  @todo Doesn't take into account different week start days. 
+/** Day of the year that the first day of the week is on.
  */
-int icaltime_start_doy_of_week(const struct icaltimetype t){
+int icaltime_start_doy_week(const struct icaltimetype t, int fdow){
        UTinstant jt;
+    int delta;
 
-       memset(&jt,0,sizeof(UTinstant));
+    memset(&jt,0,sizeof(UTinstant));
 
-       jt.year = t.year;
+    jt.year = t.year;
     jt.month = t.month;
     jt.day = t.day;
     jt.i_hour = 0;
     jt.i_minute = 0;
     jt.i_second = 0;
 
-       juldat(&jt);
-       caldat(&jt);
+    juldat(&jt);
+    caldat(&jt);
 
-       return jt.day_of_year - jt.weekday;
+    delta = jt.weekday - (fdow - 1);
+    if (delta < 0) delta += 7;
+    return jt.day_of_year - delta;
 }
 
+/** Day of the year that the first day of the week (Sunday) is on.
+ *
+ *  @deprecated Doesn't take into account different week start days.
+ */
+int icaltime_start_doy_of_week(const struct icaltimetype t){
+
+#ifndef NO_WARN_DEPRECATED
+    icalerror_warn("icaltime_start_doy_of_week() is DEPRECATED, use\
+           icaltime_start_doy_week() instead");
+#endif
+
+    return icaltime_start_doy_week(t, 1);
+}
+
 /** 
  * @todo Doesn't take into account the start day of the
  * week. strftime assumes that weeks start on Monday. 
@@ -752,9 +779,13 @@
        const int minutes, const int seconds) {
 
     int second, minute, hour, day;
-    int minutes_overflow, hours_overflow, days_overflow, years_overflow;
+    int minutes_overflow, hours_overflow, days_overflow = 0, years_overflow;
     int days_in_month;
 
+    /* If we are passed a date make sure to ignore hour minute and second */
+    if (tt->is_date)
+       goto IS_DATE;
+
     /* Add on the seconds. */
     second = tt->second + seconds;
     tt->second = second % 60;
@@ -782,6 +813,7 @@
        days_overflow--;
     }
 
+IS_DATE:
     /* Normalize the month. We do this before handling the day since we may
        need to know what month it is to get the number of days in it.
        Note that months are 1 to 12, so we have to be a bit careful. */

Modified: xfcalendar/trunk/libical/src/libical/icaltime.h
===================================================================
--- xfcalendar/trunk/libical/src/libical/icaltime.h     2006-09-04 19:18:10 UTC 
(rev 23079)
+++ xfcalendar/trunk/libical/src/libical/icaltime.h     2006-09-04 19:19:40 UTC 
(rev 23080)
@@ -24,6 +24,8 @@
  Code is Eric Busboom
 
 
+ 2006-09-03 weekstartday fix **Juha
+    based on CVS code 
 ======================================================================*/
 
 /**    @file icaltime.h
@@ -64,7 +66,7 @@
  *     - icaltime_set_timezone(struct icaltimetype t, const icaltimezone *zone)
  *     - icaltime_day_of_year(struct icaltimetype t)
  *     - icaltime_day_of_week(struct icaltimetype t)
- *     - icaltime_start_doy_of_week(struct icaltimetype t)
+ *     - icaltime_start_doy_week(struct icaltimetype t, int fdow)
  *     - icaltime_week_number(struct icaltimetype t)
  *
  *     Query methods include:
@@ -204,6 +206,14 @@
    given time is within. */
 int icaltime_start_doy_of_week(const struct icaltimetype t);
 
+/** Return the day of the year for the first day of the week that the
+   given time is within. */
+int icaltime_start_doy_in_week(const struct icaltimetype t, int fdow);
+
+/** Return the day of the year for the first day of the week that the
+   given time is within. */
+int icaltime_start_doy_week(const struct icaltimetype t, int fdow);
+
 /** Return the week number for the week the given time is within */
 int icaltime_week_number(const struct icaltimetype t);
 

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to