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

View File

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

View File

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

View File

@@ -1268,34 +1268,6 @@ procedure TVpPrinter.AddDefaultVariables(Date: TDateTime);
Result := '12' Result := '12'
else else
Result := IntToStr(ord(Hour) mod 12); 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; end;
function GranularityToStr(Gran: TVpGranularity): string; function GranularityToStr(Gran: TVpGranularity): string;