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