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

View File

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