diff --git a/components/tvplanit/source/vpdata.pas b/components/tvplanit/source/vpdata.pas index 17e0e7975..4ef2780fb 100644 --- a/components/tvplanit/source/vpdata.pas +++ b/components/tvplanit/source/vpdata.pas @@ -1318,20 +1318,16 @@ begin EventList.Clear else begin - { Add this days events to the Event List. } + { Add this day's events to the Event List. } for I := 0 to pred(EventCount) do begin Event := GetEvent(I); - { if this is a repeating event and it falls on "Date" then add it to } - { the list. } - if (Event.RepeatCode > rtNone) - and (RepeatsOn(Event, Date)) - then + { if this is a repeating event and it falls on "Date" then add it to the list. } + if (Event.RepeatCode > rtNone) and RepeatsOn(Event, Date) then EventList.Add(Event) - { otherwise if this event naturally falls on "Date" then add it to } - { the list. } - else if ((trunc(Date) >= trunc(Event.StartTime)) - and (trunc(Date) <= trunc(Event.EndTime))) then + else + { otherwise if this event naturally falls on "Date" then add it to the list. } + if DateInRange(Date, Event.StartTime, Event.EndTime, true) then EventList.Add(Event); end; end; @@ -2323,7 +2319,9 @@ var begin event1 := TVpEvent(P1); event2 := TVpEvent(P2); - Result := CompareValue(frac(event1.StartTime), frac(event2.EndTime)); + Result := CompareValue(frac(event1.StartTime), frac(event2.StartTime)); + if Result = 0 then + Result := CompareValue(frac(event1.EndTime), frac(event2.EndTime)); end; end. diff --git a/components/tvplanit/source/vpdayviewpainter.pas b/components/tvplanit/source/vpdayviewpainter.pas index ba91648be..d89f368eb 100644 --- a/components/tvplanit/source/vpdayviewpainter.pas +++ b/components/tvplanit/source/vpdayviewpainter.pas @@ -1630,7 +1630,7 @@ begin { Now sort times in ascending order. This must be done because the event list can contain recurring events which have the wrong date part } - // EventList.Sort(CompareEventsByTimeOnly); + EventList.Sort(@CompareEventsByTimeOnly); { Arrange this day's events in the event matrix } level := 0; diff --git a/components/tvplanit/source/vpmisc.pas b/components/tvplanit/source/vpmisc.pas index afd0ccea4..6f18063da 100644 --- a/components/tvplanit/source/vpmisc.pas +++ b/components/tvplanit/source/vpmisc.pas @@ -108,7 +108,8 @@ function IncYear(TheDate: TDateTime; NumYears: Integer): TDateTime; function GetJulianDate(Date: TDateTime): Word; function GetWeekOfYear(ADate: TDateTime): byte; function SameDate(dt1, dt2: TDateTime): Boolean; -function TimeInRange(Time, StartTime, EndTime: TDateTime; Inclusive: Boolean): Boolean; +function DateInRange(ADate, StartDate, EndDate: TDateTime; Inclusive: Boolean): Boolean; +function TimeInRange(ATime, StartTime, EndTime: TDateTime; Inclusive: Boolean): Boolean; function HourToLine(const Value: TVpHours; const Granularity: TVpGranularity): Integer; function GetStartLine(StartTime: TDateTime; Granularity: TVpGranularity): Integer; @@ -526,20 +527,29 @@ begin end; {=====} -function TimeInRange(Time, StartTime, EndTime: TDateTime; +function DateInRange(ADate, StartDate, EndDate: TDateTime; + Inclusive: Boolean): Boolean; +begin + ADate := trunc(ADate); + StartDate := trunc(StartDate); + EndDate := trunc(EndDate); + Result := (StartDate < ADate) and (ADate < EndDate); + if Inclusive and (not Result) then + Result := (StartDate = ADate) or (EndDate = ADate); +end; + +function TimeInRange(ATime, StartTime, EndTime: TDateTime; Inclusive: Boolean): Boolean; var equStart, equEnd: Boolean; begin - equStart := abs(Time - StartTime) < CompareTimeEps; - equEnd := abs(Time - EndTime) < CompareTimeEps; + equStart := abs(ATime - StartTime) < CompareTimeEps; + equEnd := abs(ATime - EndTime) < CompareTimeEps; if Inclusive then - Result := equStart or equEnd or ((Time > StartTime) and (Time < EndTime)) -// result := (Time >= StartTime) and (Time <= EndTime) + Result := equStart or equEnd or ((ATime > StartTime) and (ATime < EndTime)) else - Result := (not equStart) and (not equEnd) and (Time > StartTime) and (Time < EndTime); -// result := (Time > StartTime) and (Time < EndTime); + Result := (not equStart) and (not equEnd) and (ATime > StartTime) and (ATime < EndTime); end; {=====} diff --git a/components/tvplanit/source/vpweekviewpainter.pas b/components/tvplanit/source/vpweekviewpainter.pas index bbf362177..c874bbbf4 100644 --- a/components/tvplanit/source/vpweekviewpainter.pas +++ b/components/tvplanit/source/vpweekviewpainter.pas @@ -300,7 +300,7 @@ begin { Now sort times in ascending order. This must be done because the event list can contain recurring events which have the wrong date part } -// EventList.Sort(CompareEventsByTimeOnly); + EventList.Sort(CompareEventsByTimeOnly); { initialize TextRect for this day } TextRect := DayRect;