From e395c07fd398820e774bf5f2cb3de86f41e71b7c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 14 Jul 2005 04:02:19 +0000 Subject: [PATCH] * Fix bug #147 (date sometimes saved incorrectly for all day events due to timezone differences) --- webcit/ChangeLog | 5 +++++ webcit/calendar.c | 11 +++++------ webcit/calendar_tools.c | 44 ++++++++++++++++++++++++++--------------- webcit/event.c | 16 +++++++-------- webcit/webcit.h | 3 ++- 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 01ffb0638..4eed4c6e1 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -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 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/calendar.c b/webcit/calendar.c index a697ecc26..0864c5875 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -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. */ diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index d67ffd1d4..8113a9474 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -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; } diff --git a/webcit/event.c b/webcit/event.c index e3185e515..67338c9d9 100644 --- a/webcit/event.c +++ b/webcit/event.c @@ -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) ) ); } diff --git a/webcit/webcit.h b/webcit/webcit.h index e9ba29537..19d62976a 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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); -- 2.30.2