tvplanit: Some refactoring (checking if a date is in date range), some cosmetic changes

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4907 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-04 09:55:08 +00:00
parent 698d597333
commit 1b42108c15
4 changed files with 32 additions and 66 deletions

View File

@ -193,8 +193,6 @@ begin
end;
procedure TVpBufDSDatastore.SetConnected(const Value: boolean);
var
dir: String;
begin
{ Don't do anything with live data until run time. }
if (csDesigning in ComponentState) or (csLoading in ComponentState) then
@ -211,8 +209,6 @@ begin
end;
procedure TVpBufDSDatastore.SetDirectory(AValue: String);
var
wasConn: Boolean;
begin
if AValue = FDirectory then
exit;

View File

@ -1197,25 +1197,20 @@ var
begin
result := false;
if (Event.RepeatCode <> rtNone)
and (trunc(Event.RepeatRangeEnd + 1) > now)
then begin
if (Event.RepeatCode <> rtNone) and (trunc(Event.RepeatRangeEnd + 1) > now) then
begin
case Event.RepeatCode of
rtDaily:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
result := true;
end;
rtWeekly:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
result := (Trunc(Day) - Trunc(Event.StartTime)) mod 7 = 0;
end;
rtMonthlyByDay:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
begin
{ get the year, month and day of the first event in the series }
DecodeDate(Event.StartTime, EY, EM, ED);
{ get the weekday of the first event in the series }
@ -1237,8 +1232,8 @@ begin
end;
rtMonthlyByDate:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
begin
{ get the year, month and day of the first event in the series }
DecodeDate(Event.StartTime, EY, EM, ED);
{ get the year, month and day of the "Day" parameter }
@ -1249,8 +1244,8 @@ begin
end;
rtYearlyByDay:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
begin
{ get the julian date of the first event in the series }
EventJulian := GetJulianDate(Event.StartTime);
{ get the julian date of the "Day" parameter }
@ -1261,8 +1256,8 @@ begin
end;
rtYearlyByDate:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
begin
{ get the year, month and day of the first event in the series }
DecodeDate(Event.StartTime, EY, EM, ED);
{ get the year, month and day of the "Day" parameter }
@ -1273,13 +1268,12 @@ begin
end;
rtCustom:
if (Day < trunc(Event.RepeatRangeEnd) + 1)
and (Day > trunc(Event.StartTime)) then begin
if (Day < trunc(Event.RepeatRangeEnd) + 1) and (Day > trunc(Event.StartTime)) then
begin
{ if the number of elapsed days between the "Day" parameter and }
{ the event start time is evenly divisible by the event's custom }
{ interval, then we have a recurrence on this day }
result := (Trunc(Day) - Trunc(Event.StartTime))
mod Event.CustomInterval = 0;
result := (Trunc(Day) - Trunc(Event.StartTime)) mod Event.CustomInterval = 0;
end;
end;
end;
@ -1294,16 +1288,14 @@ begin
result := 0;
for I := 0 to pred(EventCount) do begin
Event := GetEvent(I);
{ if this is a repeating event and it falls on today then inc }
{ result }
if (Event.RepeatCode > rtNone)
and (RepeatsOn(Event, Value))
then
{ if this is a repeating event and it falls on today then inc result }
if (Event.RepeatCode > rtNone) and RepeatsOn(Event, Value) then
Inc(Result)
{ otherwise if it is an event that naturally falls on today, then }
{ inc result }
else if ((trunc(Value) >= trunc(Event.StartTime))
and (trunc(Value) <= trunc(Event.EndTime))) then
{ Otherwise if it is an event that naturally falls on today, then inc result }
// else if ((trunc(Value) >= trunc(Event.StartTime))
// and (trunc(Value) <= trunc(Event.EndTime))) then
else
if DateInRange(Value, Event.StartTime, Event.EndTime, true) then
Inc(Result);
end;
end;
@ -1348,8 +1340,11 @@ begin
{ Add this days events to the Event List. }
for I := 0 to pred(EventCount) do begin
Event := GetEvent(I);
if (((trunc(Date) >= trunc(Event.StartTime)) and (trunc(Date) <= trunc(Event.EndTime))) or (RepeatsOn(Event,Date)))
and (Event.AllDayEvent) then
if Event.AllDayEvent and
(DateInRange(Date, Event.StartTime, Event.EndTime, true) or RepeatsOn(Event, Date))
then
// if (((trunc(Date) >= trunc(Event.StartTime)) and (trunc(Date) <= trunc(Event.EndTime))) or (RepeatsOn(Event,Date)))
// and (Event.AllDayEvent) then
EventList.Add(Event);
end;
end;

View File

@ -1559,6 +1559,9 @@ var
begin
inherited;
// Make sure to use only the date part
ARenderDate := trunc(ARenderDate);
// Here begins the original routine...
InitColors;
SavePenBrush;

View File

@ -1268,34 +1268,6 @@ procedure TVpPrinter.AddDefaultVariables(Date: TDateTime);
Result := '12'
else
Result := IntToStr(ord(Hour) mod 12);
{
case Hour of
h_00 : Result := '12';
h_01 : Result := '1';
h_02 : Result := '2';
h_03 : Result := '3';
h_04 : Result := '4';
h_05 : Result := '5';
h_06 : Result := '6';
h_07 : Result := '7';
h_08 : Result := '8';
h_09 : Result := '9';
h_10 : Result := '10';
h_11 : Result := '11';
h_12 : Result := '12';
h_13 : Result := '1';
h_14 : Result := '2';
h_15 : Result := '3';
h_16 : Result := '4';
h_17 : Result := '5';
h_18 : Result := '6';
h_19 : Result := '7';
h_20 : Result := '8';
h_21 : Result := '9';
h_22 : Result := '10';
h_23 : Result := '11';
end;
}
end;
function GranularityToStr(Gran: TVpGranularity): string;
@ -1574,8 +1546,8 @@ var
Scale := PixelsPerInchY / Screen.PixelsPerInch;
StartLine := HourToLine (DayStart, Granularity);
EndLine := HourToLine (DayEnd, Granularity);
StartLine := HourToLine(DayStart, Granularity);
EndLine := HourToLine(DayEnd, Granularity);
end;
procedure GetPrintRectangle(Element: TVpPrintFormatElementItem);