From: Wilfried Göesgens Date: Tue, 17 Mar 2009 21:58:57 +0000 (+0000) Subject: * webcit part of michael meskes full day calendar patch; accidentely committed it... X-Git-Tag: v7.86~1341 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=ce7abae6d47bae96f8ea7ccaa1955115ad843ded * webcit part of michael meskes full day calendar patch; accidentely committed it partly in advance. --- diff --git a/webcit/availability.c b/webcit/availability.c index f8772780b..f71dd1299 100644 --- a/webcit/availability.c +++ b/webcit/availability.c @@ -54,29 +54,42 @@ int ical_ctdl_is_overlap( if (icaltime_is_null_time(t1start)) return(0); if (icaltime_is_null_time(t2start)) return(0); - /* First, check for all-day events */ - if (t1start.is_date) { - if (!icaltime_compare_date_only(t1start, t2start)) { - return(1); - } - if (!icaltime_is_null_time(t2end)) { - if (!icaltime_compare_date_only(t1start, t2end)) { - return(1); - } + /* if either event lacks end time, assume end = start */ + if (icaltime_is_null_time(t1end)) + memcpy(&t1end, &t1start, sizeof(struct icaltimetype)); + else { + if (t1end.is_date && icaltime_compare(t1start, t1end)) { + /* + * the end date is non-inclusive so adjust it by one + * day because our test is inclusive, note that a day is + * not too much because we are talking about all day + * events + * if start = end we assume that nevertheless the whole + * day is meant + */ + icaltime_adjust(&t1end, -1, 0, 0, 0); } } - if (t2start.is_date) { - if (!icaltime_compare_date_only(t2start, t1start)) { - return(1); - } - if (!icaltime_is_null_time(t1end)) { - if (!icaltime_compare_date_only(t2start, t1end)) { - return(1); - } + if (icaltime_is_null_time(t2end)) + memcpy(&t2end, &t2start, sizeof(struct icaltimetype)); + else { + if (t2end.is_date && icaltime_compare(t2start, t2end)) { + icaltime_adjust(&t2end, -1, 0, 0, 0); } } + /* First, check for all-day events */ + if (t1start.is_date || t2start.is_date) { + /* If event 1 ends before event 2 starts, we're in the clear. */ + if (icaltime_compare_date_only(t1end, t2start) < 0) return(0); + + /* If event 2 ends before event 1 starts, we're also ok. */ + if (icaltime_compare_date_only(t2end, t1start) < 0) return(0); + + return(1); + } + /* lprintf (9, "Comparing t1start %d:%d t1end %d:%d t2start %d:%d t2end %d:%d \n", t1start.hour, t1start.minute, t1end.hour, t1end.minute, t2start.hour, t2start.minute, t2end.hour, t2end.minute); @@ -84,10 +97,6 @@ int ical_ctdl_is_overlap( /* Now check for overlaps using date *and* time. */ - /* First, bail out if either event 1 or event 2 is missing end time. */ - if (icaltime_is_null_time(t1end)) return(0); - if (icaltime_is_null_time(t2end)) return(0); - /* If event 1 ends before event 2 starts, we're in the clear. */ if (icaltime_compare(t1end, t2start) <= 0) return(0); /* lprintf(9, "first passed\n"); */ diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 8ff0a4dbc..635e96a00 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -163,6 +163,7 @@ void calendar_month_view_display_events(int year, int month, int day) struct icaltimetype end_t; struct icaltimetype today_start_t; struct icaltimetype today_end_t; + struct icaltimetype today_t; struct tm starting_tm; struct tm ending_tm; int all_day_event = 0; @@ -199,6 +200,14 @@ void calendar_month_view_display_events(int year, int month, int day) today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone()); today_end_t.is_utc = 1; + /* + * Create another one without caring about the timezone for all day events. + */ + today_t = icaltime_null_date(); + today_t.year = year; + today_t.month = month; + today_t.day = day; + /* * Now loop through our list of events to see which ones occur today. */ @@ -224,7 +233,7 @@ void calendar_month_view_display_events(int year, int month, int day) if (all_day_event) { - show_event = ((t.year == year) && (t.month == month) && (t.day == day)); + show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time()); } else { @@ -275,33 +284,62 @@ void calendar_month_view_display_events(int year, int month, int day) q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY); if (q != NULL) { + int no_end = 0; + t = icalproperty_get_dtstart(q); - + q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY); + if (q != NULL) { + end_t = icalproperty_get_dtend(q); + } + else { + /* + * events with starting date/time equal + * ending date/time might get only + * DTSTART but no DTEND + */ + no_end = 1; + } + if (t.is_date) { + /* all day event */ struct tm d_tm; - char d_str[32]; + + if (!no_end) { + /* end given, have to adjust it */ + icaltime_adjust(&end_t, -1, 0, 0, 0); + } memset(&d_tm, 0, sizeof d_tm); d_tm.tm_year = t.year - 1900; d_tm.tm_mon = t.month - 1; d_tm.tm_mday = t.day; - wc_strftime(d_str, sizeof d_str, "%x", &d_tm); - wprintf("%s %s
", - _("Date:"), d_str); + wc_strftime(buf, sizeof buf, "%x", &d_tm); + + if (no_end || !icaltime_compare(t, end_t)) { + wprintf("%s %s
", + _("Date:"), buf); + } + else { + wprintf("%s %s
", + _("Starting date:"), buf); + d_tm.tm_year = end_t.year - 1900; + d_tm.tm_mon = end_t.month - 1; + d_tm.tm_mday = end_t.day; + wc_strftime(buf, sizeof buf, "%x", &d_tm); + wprintf("%s %s
", + _("Ending date:"), buf); + } } else { tt = icaltime_as_timet(t); webcit_fmt_date(buf, tt, DATEFMT_BRIEF); - wprintf("%s %s
", - _("Starting date/time:"), buf); - - /* - * Embed the 'show end date/time' loop inside here so it - * only executes if this is NOT an all day event. - */ - q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY); - if (q != NULL) { - t = icalproperty_get_dtend(q); - tt = icaltime_as_timet(t); + if (no_end || !icaltime_compare(t, end_t)) { + wprintf("%s %s
", + _("Date/time:"), buf); + } + else { + wprintf("%s %s
", + _("Starting date/time:"), buf); + tt = icaltime_as_timet(end_t); webcit_fmt_date(buf, tt, DATEFMT_BRIEF); wprintf("%s %s
", _("Ending date/time:"), buf); } @@ -770,6 +808,7 @@ void calendar_day_view_display_events(time_t thetime, struct icaltimetype end_t; struct icaltimetype today_start_t; struct icaltimetype today_end_t; + struct icaltimetype today_t; struct tm starting_tm; struct tm ending_tm; int top = 0; @@ -780,8 +819,6 @@ void calendar_day_view_display_events(time_t thetime, int endmin = 0; char buf[256]; - struct tm d_tm; - char d_str[32]; if (GetCount(WCC->disp_cal_items) == 0) { /* nothing to display */ @@ -809,6 +846,14 @@ void calendar_day_view_display_events(time_t thetime, today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone()); today_end_t.is_utc = 1; + /* + * Create another one without caring about the timezone for all day events. + */ + today_t = icaltime_null_date(); + today_t.year = year; + today_t.month = month; + today_t.day = day; + /* Now loop through our list of events to see which ones occur today. */ Pos = GetNewHashPos(WCC->disp_cal_items, 0); @@ -827,26 +872,39 @@ void calendar_day_view_display_events(time_t thetime, else { memset(&t, 0, sizeof t); } + + if (t.is_date) all_day_event = 1; + q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY); if (q != NULL) { end_t = icalproperty_get_dtend(q); - event_tte = icaltime_as_timet(end_t); - localtime_r(&event_tte, &event_tm); } else { - memset(&end_t, 0, sizeof end_t); + /* no end given means end = start */ + memcpy(&end_t, &t, sizeof(struct icaltimetype)); } - if (t.is_date) all_day_event = 1; if (all_day_event) { - show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events)); + show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time()); + if (icaltime_compare(t, end_t)) { + /* + * the end date is non-inclusive so adjust it by one + * day because our test is inclusive, note that a day is + * not to much because we are talking about all day + * events + */ + icaltime_adjust(&end_t, -1, 0, 0, 0); + } } else { show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t); } + event_tte = icaltime_as_timet(end_t); + localtime_r(&event_tte, &event_tm); + /* If we determined that this event occurs today, then display it. */ p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY); @@ -874,13 +932,17 @@ void calendar_day_view_display_events(time_t thetime, wprintf("%s ", _("Location:")); escputs((char *)icalproperty_get_comment(q)); wprintf("
"); - } - memset(&d_tm, 0, sizeof d_tm); - d_tm.tm_year = t.year - 1900; - d_tm.tm_mon = t.month - 1; - d_tm.tm_mday = t.day; - wc_strftime(d_str, sizeof d_str, "%x", &d_tm); - wprintf("%s %s
",_("Date:"), d_str); + } + if (!icaltime_compare(t, end_t)) { /* one day only */ + webcit_fmt_date(buf, event_tt, DATEFMT_LOCALEDATE); + wprintf("%s %s
", _("Date:"), buf); + } + else { + webcit_fmt_date(buf, event_tt, DATEFMT_LOCALEDATE); + wprintf("%s %s
", _("Starting date:"), buf); + webcit_fmt_date(buf, event_tte, DATEFMT_LOCALEDATE); + wprintf("%s %s
", _("Ending date:"), buf); + } q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY); if (q) { wprintf("%s ", _("Notes:")); @@ -992,10 +1054,16 @@ void calendar_day_view_display_events(time_t thetime, escputs((char *)icalproperty_get_comment(q)); wprintf("
"); } - webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF); - wprintf("%s %s
", _("Starting date/time:"), buf); - webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF); - wprintf("%s %s
", _("Ending date/time:"), buf); + if (!icaltime_compare(t, end_t)) { /* one day only */ + webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF); + wprintf("%s %s
", _("Date/time:"), buf); + } + else { + webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF); + wprintf("%s %s
", _("Starting date/time:"), buf); + webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF); + wprintf("%s %s
", _("Ending date/time:"), buf); + } q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY); if (q) { wprintf("%s ", _("Notes:")); diff --git a/webcit/event.c b/webcit/event.c index 9f7bdfc2b..468422a9a 100644 --- a/webcit/event.c +++ b/webcit/event.c @@ -242,25 +242,34 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, } } else { - /* - * If this is an all-day-event, set the end time to be identical to - * the start time (the hour/minute/second will be set to midnight). - * Otherwise extract or create it. - */ - if (t_start.is_date) { - t_end = t_start; + if (created_new_vevent == 1) { + /* set default duration */ + if (t_start.is_date) { + /* + * If this is an all-day-event, set the end time to be identical to + * the start time (the hour/minute/second will be set to midnight). + */ + t_end = t_start; + } + else { + /* + * If this is not an all-day event and there is no + * end time specified, make the default one hour + * from the start time. + */ + t_end = t_start; + t_end.hour += 1; + t_end.second = 0; + t_end = icaltime_normalize(t_end); + /* t_end = icaltime_from_timet(now, 0); */ + } } else { /* - * If this is not an all-day event and there is no - * end time specified, make the default one hour - * from the start time. + * If an existing event has no end date/time this is + * supposed to mean end = start. */ t_end = t_start; - t_end.hour += 1; - t_end.second = 0; - t_end = icaltime_normalize(t_end); - /* t_end = icaltime_from_timet(now, 0); */ } } display_icaltimetype_as_webform(&t_end, "dtend", 0); diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c index 04cb391f5..ecc7b78bb 100644 --- a/webcit/fmt_date.c +++ b/webcit/fmt_date.c @@ -67,6 +67,7 @@ void webcit_fmt_date(char *buf, time_t thetime, int Format) * show the month and day, and the time * older than 6 months, show only the date * DATEFMT_RAWDATE: show full date, regardless of age + * DATEFMT_LOCALEDATE: show full date as prefered for the locale */ switch (Format) { @@ -98,6 +99,9 @@ void webcit_fmt_date(char *buf, time_t thetime, int Format) case DATEFMT_RAWDATE: wc_strftime(buf, 32, "%a %b %d %Y", &tm); break; + case DATEFMT_LOCALEDATE: + wc_strftime(buf, 32, "%x", &tm); + break; } } diff --git a/webcit/webcit.h b/webcit/webcit.h index 202bcabb5..381204299 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -725,6 +725,7 @@ const char *get_selected_language(void); #define DATEFMT_FULL 0 #define DATEFMT_BRIEF 1 #define DATEFMT_RAWDATE 2 +#define DATEFMT_LOCALEDATE 3 void webcit_fmt_date(char *buf, time_t thetime, int Format); int fetch_http(char *url, char *target_buf, int maxbytes); void free_attachments(wcsession *sess);