tvplanit: Refactor of dayview painting (preps)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4910 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-04 19:00:42 +00:00
parent 8cebf7fdb9
commit 9438c5f7a0
3 changed files with 43 additions and 24 deletions

View File

@ -62,6 +62,9 @@ const
HoursInDay = 24; { Number of hours in a day }
MinutesInHour = 60; { Number of minutes in an hour }
MinutesInDay = 1440; { Number of minutes in a day }
OneSecond = 1.0 / SecondsInDay;
OneMinute = 1.0 / MinutesInDay;
OneHour = 1.0 / HoursInDay;
MaxDateLen = 40; { maximum length of date picture strings }
MaxMonthName = 15; { maximum length for month names }
MaxDayName = 15; { maximum length for day names }

View File

@ -103,6 +103,8 @@ function MonthOfTheYear(TheDate: TDateTime): Word;
procedure IncAMonth(var Year, Month, Day: Word; NumMonths: Integer);
function IncMonth(const TheDate: TDateTime; NumberOfMonths: Integer): TDateTime;
function IncYear(TheDate: TDateTime; NumYears: Integer): TDateTime;
function TimeOf(ADateTime: TDateTime): TDateTime;
function DateOf(ADateTime: TDateTime): TDateTime;
{$ENDIF}{$ENDIF}
function GetJulianDate(Date: TDateTime): Word;
@ -127,6 +129,9 @@ function EncodeLineEndings(const AText: String): String;
implementation
uses
{$IFDEF LCL}
DateUtils,
{$ENDIF}
VpException, VpSR;
procedure StripString(var Str: string);
@ -392,7 +397,7 @@ begin
Sign := 1
else
Sign := -1;
Year := Year + (NumMonths div 12);
Year := Year + NumMonths div 12;
NumMonths := NumMonths mod 12;
Inc (Month, NumMonths);
if Word(Month-1) > 11 then
@ -416,10 +421,21 @@ begin
end;
{=====}
function IncYear (TheDate : TDateTime; NumYears : Integer) : TDateTime;
function IncYea (TheDate: TDateTime; NumYear : Integer) : TDateTime;
begin
Result := IncMonth (TheDate, NumYears * 12);
Result := IncMont (TheDate, NumYears * 12);
end;
function DateOf(ADateTime: TDateTime): TDateTime;
begin
Result := trunc(ADateTime);
end;
function TimeOf(ADateTime: TDateTime): TDateTime;
begin
Result := frac(ADateTime);
end;
{=====}
{$ENDIF}{$ENDIF}
@ -455,7 +471,7 @@ var
Time: Double;
begin
{ remove the date part, and add one minute to the time }
Time := frac(StartTime) + 1 / MinutesInDay;
Time := TimeOf(StartTime) + OneMinute;
LineDuration := GranularityMinutes[Granularity] / MinutesInDay;
result := trunc(Time / LineDuration);
end;
@ -467,7 +483,7 @@ var
Time: Double;
begin
{ remove the date part, and subtract one minute from the time }
Time := frac(EndTime) - 1 / MinutesInDay;
Time := TimeOf(EndTime) - OneMinute;
LineDuration := GranularityMinutes[Granularity] / MinutesInDay;
result := trunc(Time / LineDuration);
end;
@ -478,8 +494,8 @@ function GetAlarmAdvanceTime(Advance: Integer;
begin
result := 0.0;
case AdvanceType of
atMinutes : result := Advance / MinutesInDay;
atHours : result := Advance * 60 / MinutesInDay;
atMinutes : result := Advance * OneMinute;
atHours : result := Advance * OneHour;
atDays : result := Advance;
end;
end;