TvPlanIt: Attempting to fix missing events in day view having exactly equal start and end times.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8176 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-12-13 23:55:46 +00:00
parent e584f4c869
commit 2be4c5efdd
2 changed files with 46 additions and 39 deletions

View File

@ -153,35 +153,44 @@ function TVpDayViewPainter.CountOverlappingEvents(Event: TVpEvent;
const EArray: TVpDvEventArray): Integer;
var
K, SelfLevel: Integer;
Tmp: TVpEvent;
tmp: TVpEvent;
Levels: array of Integer = nil;
EventStart, EventEnd: TTime;
tmpStart, tmpEnd: TTime;
begin
{ initialize the levels array }
Result := 0;
EventStart := frac(Event.StartTime);
EventEnd := frac(Event.EndTime);
{ Initialize the levels array }
SetLength(Levels, MaxEventDepth);
for K := 0 to pred(MaxEventDepth) do
Levels[K] := 0;
result := 0;
{ First, simply count the number of overlapping events. }
K := 0;
SelfLevel := -1;
Tmp := TVpEvent(EArray[K].Event);
while Tmp <> nil do begin
if Tmp = Event then begin
tmp := TVpEvent(EArray[K].Event);
while tmp <> nil do begin
if tmp = Event then begin
SelfLevel := K;
Inc(K);
Tmp := TVpEvent(EArray[K].Event);
tmp := TVpEvent(EArray[K].Event);
Continue;
end;
{ if the Tmp event's StartTime or EndTime falls within the range of }
{ Event... }
if TimeInRange(frac(Tmp.StartTime), frac(Event.StartTime), frac(Event.EndTime), false) or
TimeInRange(frac(Tmp.EndTime), frac(Event.StartTime), frac(Event.EndTime), false) or
tmpStart := frac(tmp.StartTime);
tmpEnd := frac(tmp.EndTime);
{ if the Tmp event's StartTime or EndTime falls within the range of Event... }
if TimeInRange(tmpStart, EventStart, EventEnd, false) or
TimeInRange(tmpEnd, EventStart, EventEnd, false) or
{ or the Tmp event's StartTime is before or equal to the Event's }
{ start time AND its end time is after or equal to the Event's }
{ end time, then the events overlap and we will need to increment }
{ the value of K. }
((frac(Tmp.StartTime) <= frac(Event.StartTime)) and (frac(Tmp.EndTime) >= frac(Event.EndTime)))
(
(SameTime(tmpStart, EventStart) or (tmpStart < EventStart)) and
(SameTime(tmpEnd, EventEnd) or (tmpEnd > EventEnd))
)
then begin
{ Count this event at this level }
Inc(Levels[EArray[K].Level]);
@ -189,8 +198,9 @@ begin
end;
Inc(K);
Tmp := TVpEvent(EArray[K].Event);
tmp := TVpEvent(EArray[K].Event);
end;
{ Then adjust count for overlapping events which share a level. }
for K := 0 to pred(MaxEventDepth) do begin
if K = SelfLevel then Continue;
@ -1891,7 +1901,7 @@ var
event: TVpEvent;
level: Integer;
I, J: Integer;
thisTime: TTime;
thisTime, tStart, tEnd: TTime;
begin
{ Set the event array's max size }
SetLength(EventArray, MaxVisibleEvents); // EventArray is global within painter
@ -1906,10 +1916,10 @@ begin
EventList := TList.Create;
try
{Get all of the events for this day}
// Get all of the events for this day
FDayView.DataStore.Resource.Schedule.EventsByDate(ARenderDate, EventList);
{ Discard AllDayEvents, because they are drawn separately. }
// Discard AllDayEvents, because they are drawn separately.
for I := pred(EventList.Count) downto 0 do begin
event := EventList[I];
if event.AllDayEvent then
@ -1930,8 +1940,12 @@ begin
ThisTime := 0.0;
while (J < EventList.Count) and (J < MaxVisibleEvents) do begin
event := EventList[J];
if SameTime(frac(event.StartTime), thisTime) or (frac(event.StartTime) > thisTime) then begin
thisTime := frac(event.EndTime);
tStart := frac(event.StartTime);
tEnd := frac(event.EndTime);
if SameTime(tStart, thisTime) or (tStart > thisTime) then
begin
thisTime := tEnd;
{ Handle end times of midnight }
if thisTime = 0 then
thisTime := EncodeTime(23, 59, 59, 0);

View File

@ -787,16 +787,11 @@ end;
checked with a precision of 0.1 sec (see: CompareTimeEps). }
function TimeInRange(ATime, StartTime, EndTime: TDateTime;
IncludeLimits: Boolean): Boolean;
var
equStart, equEnd: Boolean;
begin
equStart := abs(ATime - StartTime) < CompareTimeEps;
equEnd := abs(ATime - EndTime) < CompareTimeEps;
if IncludeLimits then
Result := equStart or equEnd or ((ATime > StartTime) and (ATime < EndTime))
else
Result := (not equStart) and (not equEnd) and (ATime > StartTime) and (ATime < EndTime);
Result := (ATime > StartTime) and (ATime < EndTime);
if IncludeLimits and (not Result) then
Result := SameValue(ATime, StartTime, CompareTimeEps) or
SameValue(ATime, EndTime, CompareTimeEps);
end;
{ Returns true of the two specified date/time variables have the same date part }
@ -805,12 +800,10 @@ begin
Result := trunc(dt1) = trunc(dt2);
end;
{ Checks whether the two time values equal within a tolerance of 1 ms }
{ Checks whether the two time values equal within a tolerance of 0.1 sec }
function SameTime(t1, t2: TTime): Boolean;
const
ONE_MILLISECOND = 1.0/(24*60*60*1000);
begin
Result := SameValue(t1, t2, ONE_MILLISECOND);
Result := SameValue(t1, t2, CompareTimeEps);
end;
// Calculates ISO week number (checked with Jan 1, 2016, which is in week 53).