Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
[kcalcore] Properly handle exception datetimes for ClockTime events. …
Browse files Browse the repository at this point in the history
…Contributes to JB#43708

If a recurring event is specified as a ClockTime event, or if an
exception to the event is specified in ClockTime specification,
we need to apply the exception semantics specially.

That is: we should not perform a toLocalZone() conversion before
checking if the exception datetime matches, but just directly
compare the dates and times as-is.
  • Loading branch information
dcaliste authored and Chris Adams committed Nov 26, 2019
1 parent f8153fe commit 691bda3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions kcalcore/recurrence.cpp
Expand Up @@ -30,6 +30,51 @@

using namespace KCalCore;

namespace KCalCore {
template <>
int SortableList<KDateTime>::findSorted( const KDateTime &value, int start ) const
{
// Do a binary search to find the item == value
const KDateTime lzValue = value.isDateOnly()
? KDateTime(value.date(), QTime(0, 0), value.timeSpec()).toLocalZone()
: value.toLocalZone();
int st = start - 1;
int end = count();
while ( end - st > 1 ) {
int i = ( st + end ) / 2;
const KDateTime dt(at(i));
if (value.isClockTime()) {
if (value.date() < dt.date() || (value.date() == dt.date() && value.time() < dt.time())) {
end = i;
} else {
st = i;
}
} else if (dt.isClockTime()) {
if (lzValue.date() < dt.date() || (lzValue.date() == dt.date() && lzValue.time() < dt.time())) {
end = i;
} else {
st = i;
}
} else if ( value < at( i ) ) {
end = i;
} else {
st = i;
}
}
if (start >= end) {
return -1;
}
const KDateTime dt(at(st));
if (value.isClockTime()) {
return (value.date() == dt.date() && value.time() == dt.time()) ? st : -1;
} else if (dt.isClockTime()) {
return (lzValue.date() == dt.date() && lzValue.time() == dt.time()) ? st : -1;
} else {
return (value == dt) ? st : -1;
}
}
}

//@cond PRIVATE
class KCalCore::Recurrence::Private
{
Expand Down

0 comments on commit 691bda3

Please sign in to comment.