* Fix bug #147 (date sometimes saved incorrectly for all day events due
authorArt Cancro <ajc@citadel.org>
Thu, 14 Jul 2005 04:02:19 +0000 (04:02 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 14 Jul 2005 04:02:19 +0000 (04:02 +0000)
  to timezone differences)

webcit/ChangeLog
webcit/calendar.c
webcit/calendar_tools.c
webcit/event.c
webcit/webcit.h

index 01ffb06380fb41824b6ed5a29f725e1157ec9103..4eed4c6e10a34a8b9254a1703871cd03d805e029 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 619.23  2005/07/14 04:02:18  ajc
+* Fix bug #147 (date sometimes saved incorrectly for all day events due
+  to timezone differences)
+
 Revision 619.22  2005/07/13 16:55:59  ajc
 * Use the new icons in more places.
 
@@ -2695,3 +2699,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index a697ecc26302dd84a2274338188686e619c81c5c..0864c5875421e14a62e6aa267bb0b41cac43cb04 100644 (file)
@@ -597,6 +597,7 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
        int created_new_vtodo = 0;
        int i;
        int sequence = 0;
+       struct icaltimetype t;
 
        if (supplied_vtodo != NULL) {
                vtodo = supplied_vtodo;
@@ -646,10 +647,9 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
                        icalcomponent_remove_property(vtodo, prop);
                        icalproperty_free(prop);
                }
+               icaltime_from_webform(&t, "dtstart");
                icalcomponent_add_property(vtodo,
-                       icalproperty_new_dtstart(
-                               icaltime_from_webform("dtstart")
-                       )
+                       icalproperty_new_dtstart(t)
                );
        
                while (prop = icalcomponent_get_first_property(vtodo,
@@ -657,10 +657,9 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
                        icalcomponent_remove_property(vtodo, prop);
                        icalproperty_free(prop);
                }
+               icaltime_from_webform(&t, "due");
                icalcomponent_add_property(vtodo,
-                       icalproperty_new_due(
-                               icaltime_from_webform("due")
-                       )
+                       icalproperty_new_due(t)
                );
 
                /* Give this task a UID if it doesn't have one. */
index d67ffd1d41017e840d212734043c268fae7fe05e..8113a9474aece591a4b30964b53347fe82036d42 100644 (file)
@@ -163,25 +163,37 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
 }
 
 
-struct icaltimetype icaltime_from_webform(char *prefix) {
-       struct icaltimetype t;
-       time_t tt;
-       struct tm tm;
-       char vname[SIZ];
+void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
+       char vname[32];
+        time_t tt;
+        struct tm tm;
+       struct icaltimetype t2;
+
+        tt = time(NULL);
+        localtime_r(&tt, &tm);
+
+        sprintf(vname, "%s_month", prefix);     tm.tm_mon = atoi(bstr(vname)) - 1;
+        sprintf(vname, "%s_day", prefix);       tm.tm_mday = atoi(bstr(vname));
+        sprintf(vname, "%s_year", prefix);      tm.tm_year = atoi(bstr(vname)) - 1900;
+        sprintf(vname, "%s_hour", prefix);      tm.tm_hour = atoi(bstr(vname));
+        sprintf(vname, "%s_minute", prefix);    tm.tm_min = atoi(bstr(vname));
+
+        tt = mktime(&tm);
+        t2 = icaltime_from_timet(tt, 0);
+       memcpy(t, &t2, sizeof(struct icaltimetype));
+}
+
 
-       tt = time(NULL);
-       localtime_r(&tt, &tm);
+void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
+       char vname[32];
 
-       sprintf(vname, "%s_month", prefix);     tm.tm_mon = atoi(bstr(vname)) - 1;
-       sprintf(vname, "%s_day", prefix);       tm.tm_mday = atoi(bstr(vname));
-       sprintf(vname, "%s_year", prefix);      tm.tm_year = atoi(bstr(vname)) - 1900;
-       sprintf(vname, "%s_hour", prefix);      tm.tm_hour = atoi(bstr(vname));
-       sprintf(vname, "%s_minute", prefix);    tm.tm_min = atoi(bstr(vname));
+       memset(t, 0, sizeof(struct icaltimetype));
 
-       tt = mktime(&tm);
-       t = icaltime_from_timet(tt, 0);
-       t = icaltime_normalize(t);
-       return(t);
+        sprintf(vname, "%s_month", prefix);     t->month = atoi(bstr(vname));
+        sprintf(vname, "%s_day", prefix);       t->day = atoi(bstr(vname));
+        sprintf(vname, "%s_year", prefix);      t->year = atoi(bstr(vname));
+       t->is_utc = 1;
+       t->is_date = 1;
 }
 
 
index e3185e515c959d24409bb428d9ed2be9e370d213..67338c9d989d41daf55aae3df69e0381eceb501d 100644 (file)
@@ -420,7 +420,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
        icalcomponent *vevent, *encaps;
        int created_new_vevent = 0;
        int all_day_event = 0;
-       struct icaltimetype event_start;
+       struct icaltimetype event_start, t;
        icalproperty *attendee = NULL;
        char attendee_string[SIZ];
        int i;
@@ -495,14 +495,12 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        all_day_event = 0;
                }
 
-               event_start = icaltime_from_webform("dtstart");
                if (all_day_event) {
-                       event_start.is_date = 1;
-                       event_start.hour = 0;
-                       event_start.minute = 0;
-                       event_start.second = 0;
+                       icaltime_from_webform_dateonly(&event_start, "dtstart");
+               }
+               else {
+                       icaltime_from_webform(&event_start, "dtstart");
                }
-
 
                /* The following odd-looking snippet of code looks like it
                 * takes some unnecessary steps.  It is done this way because
@@ -533,9 +531,9 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                }
 
                if (all_day_event == 0) {
+                       icaltime_from_webform(&t, "dtend");     
                        icalcomponent_add_property(vevent,
-                               icalproperty_new_dtend(icaltime_normalize(
-                                       icaltime_from_webform("dtend"))
+                               icalproperty_new_dtend(icaltime_normalize(t)
                                )
                        );
                }
index e9ba2953730bb059b1803d4cd534e80bd16cb52b..19d62976a9c6cadf4b63bd1c563f3f8ccf9d89b5 100644 (file)
@@ -461,7 +461,8 @@ void save_task(void);
 void display_edit_event(void);
 void save_event(void);
 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
-struct icaltimetype icaltime_from_webform(char *prefix);
+void icaltime_from_webform(struct icaltimetype *result, char *prefix);
+void icaltime_from_webform_dateonly(struct icaltimetype *result, char *prefix);
 void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
 void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
 void respond_to_request(void);