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);
/* 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"); */
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;
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.
*/
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
{
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("<i>%s</i> %s<br>",
- _("Date:"), d_str);
+ wc_strftime(buf, sizeof buf, "%x", &d_tm);
+
+ if (no_end || !icaltime_compare(t, end_t)) {
+ wprintf("<i>%s</i> %s<br>",
+ _("Date:"), buf);
+ }
+ else {
+ wprintf("<i>%s</i> %s<br>",
+ _("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("<i>%s</i> %s<br>",
+ _("Ending date:"), buf);
+ }
}
else {
tt = icaltime_as_timet(t);
webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
- wprintf("<i>%s</i> %s<br>",
- _("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("<i>%s</i> %s<br>",
+ _("Date/time:"), buf);
+ }
+ else {
+ wprintf("<i>%s</i> %s<br>",
+ _("Starting date/time:"), buf);
+ tt = icaltime_as_timet(end_t);
webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
}
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;
int endmin = 0;
char buf[256];
- struct tm d_tm;
- char d_str[32];
if (GetCount(WCC->disp_cal_items) == 0) {
/* nothing to display */
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);
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);
wprintf("<i>%s</i> ", _("Location:"));
escputs((char *)icalproperty_get_comment(q));
wprintf("<br />");
- }
- 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("<i>%s</i> %s<br>",_("Date:"), d_str);
+ }
+ if (!icaltime_compare(t, end_t)) { /* one day only */
+ webcit_fmt_date(buf, event_tt, DATEFMT_LOCALEDATE);
+ wprintf("<i>%s</i> %s<br>", _("Date:"), buf);
+ }
+ else {
+ webcit_fmt_date(buf, event_tt, DATEFMT_LOCALEDATE);
+ wprintf("<i>%s</i> %s<br>", _("Starting date:"), buf);
+ webcit_fmt_date(buf, event_tte, DATEFMT_LOCALEDATE);
+ wprintf("<i>%s</i> %s<br>", _("Ending date:"), buf);
+ }
q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
if (q) {
wprintf("<i>%s</i> ", _("Notes:"));
escputs((char *)icalproperty_get_comment(q));
wprintf("<br />");
}
- webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
- wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
- webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
- wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
+ if (!icaltime_compare(t, end_t)) { /* one day only */
+ webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
+ wprintf("<i>%s</i> %s<br>", _("Date/time:"), buf);
+ }
+ else {
+ webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
+ wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
+ webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
+ wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
+ }
q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
if (q) {
wprintf("<i>%s</i> ", _("Notes:"));