tvplanit: Improved handling of all-day events in ical files.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9088 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-12-16 23:10:30 +00:00
parent e10ac1b73e
commit 4e6e861a43
4 changed files with 40 additions and 13 deletions

View File

@ -65,6 +65,7 @@ type
FEndTime: TDateTime;
FEndTimeTZ: String;
FDuration: double;
FAllDayEvent: Boolean;
FRecurrenceFreq: String;
FRecurrenceInterval: Integer;
FRecurrenceEndDate: TDateTime;
@ -192,6 +193,7 @@ uses
VpConst, VpBase;
const
DATE_FORMAT = 'yyyymmdd';
TIME_FORMAT = 'yyyymmdd"T"hhnnss';
TIME_FORMAT_UTC = TIME_FORMAT + '"Z"';
@ -440,9 +442,11 @@ begin
FSummary := item.Value;
'DTSTART':
begin
s := item.GetAttribute('VALUE');
FAllDayEvent := (s = 'DATE');
FStartTimeTZ := item.GetAttribute('TZID');
FStartTime := iCalDateTime(item.Value, isUTC);
if not isUTC then
if (not isUTC) and (not FAllDayEvent) then
FStartTime := FCalendar.LocalTimeToUTC(FStartTime, FStartTimeTZ);
end;
'DTEND':
@ -486,6 +490,15 @@ begin
end;
end;
end;
{
if (FEndTime = NO_DATE) and (FStartTime <> NO_DATE) then
begin
if FDuration = 0 then
FEndTime := FStartTime + 1.0/24 // 1 hour default
else
FEndTime := FStartTime + FDuration;
end;
}
end;
function TVpICalEvent.Categories: TStrings;
@ -544,6 +557,10 @@ function TVpICalEvent.IsAllDayEvent: Boolean;
var
tstart, tend: TDateTime;
begin
Result := true;
if FAllDayEvent then
exit;
tstart := GetStartTime(false);
tend := GetEndTime(false);
if ((FEndTime = NO_DATE) or (frac(tend) = 0.0)) and (frac(tstart) = 0.0) then
@ -571,16 +588,21 @@ begin
AList.Add('CATEGORIES:' + FCategories.CommaText);
// todo: check time zones!
if FStartTimeTZ <> '' then
lKey := 'DTSTART;TZID=' + FStartTimeTZ + ':'
if IsAllDayEvent then
lKey := 'DTSTART;VALUE=DATE:'+ FormatDateTime(DATE_FORMAT, StartTime[true])
else
lKey := 'DTSTART:';
AList.Add(lKey + FormatDateTime(TIME_FORMAT_UTC, StartTime[true]));
if FEndTimeTZ <> '' then
lKey := 'DTEND;TZID=' + FEndTimeTZ + ':'
else
lKey := 'DTEND:';
AList.Add(lKey + FormatDateTime(TIME_FORMAT_UTC, EndTime[true]));
begin
if FStartTimeTZ <> '' then
lKey := 'DTSTART;TZID=' + FStartTimeTZ + ':'
else
lKey := 'DTSTART:';
AList.Add(lKey + FormatDateTime(TIME_FORMAT_UTC, StartTime[true]));
if FEndTimeTZ <> '' then
lKey := 'DTEND;TZID=' + FEndTimeTZ + ':'
else
lKey := 'DTEND:';
AList.Add(lKey + FormatDateTime(TIME_FORMAT_UTC, EndTime[true]));
end;
if RecurrenceFrequency <> '' then
begin

View File

@ -6,8 +6,8 @@ object VpImportPreviewForm: TVpImportPreviewForm
Caption = 'VpImportPreviewForm'
ClientHeight = 295
ClientWidth = 634
LCLVersion = '3.99.0.0'
OnShow = FormShow
LCLVersion = '2.3.0.0'
object ButtonPanel: TPanel
Left = 6
Height = 25

View File

@ -164,7 +164,7 @@ begin
FixedCols := 0;
Options := [goEditing, goRowSelect, goThumbTracking,
goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goRangeSelect, goSmoothScroll];
goRangeSelect]; // Strange scroll effect when using goSmoothScroll...
OnDrawCell := @GridDrawCell;
OnGetCheckboxState := @GridGetCheckboxState;
OnPrepareCanvas := @GridPrepareCanvas;

View File

@ -100,8 +100,12 @@ var
begin
startTime := AEvent.StartTime[false];
endTime := AEvent.EndTime[false];
sStartTime := FormatDateTime(FTimeFormat, startTime);
sEndTime := FormatDateTime(FTimeFormat, endTime - OneSecond);
if endTime = NO_DATE then
sEndTime := ''
else
sEndTime := FormatDateTime(FTimeFormat, endTime - OneSecond);
if AEvent.IsAllDayEvent then
begin
if endTime = NO_DATE then nDays := 1 else nDays := round(endTime - startTime);
@ -109,6 +113,7 @@ begin
Result := Format('%s (%s)', [sStartTime, RSAllDay])
else
Result := Format('%s - %s (%s)', [sStartTime, sEndTime, RSAllDay]);
Result := Result + ' (all day)';
end else
Result :=
RSStartTimeLbl + ' ' + sStartTime + LineEnding +