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

View File

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

View File

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

View File

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