You've already forked lazarus-ccr
tvplanit: Fix end date of ical event import.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8384 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -57,6 +57,7 @@ const
|
|||||||
0, WS_HSCROLL, WS_VSCROLL, WS_HSCROLL or WS_VSCROLL{$IFDEF LCL},0,0,0{$ENDIF}
|
0, WS_HSCROLL, WS_VSCROLL, WS_HSCROLL or WS_VSCROLL{$IFDEF LCL},0,0,0{$ENDIF}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
NO_DATE = 9999999;
|
||||||
SecondsInDay = 86400; { Number of seconds in a day }
|
SecondsInDay = 86400; { Number of seconds in a day }
|
||||||
SecondsInHour = 3600; { Number of seconds in an hour }
|
SecondsInHour = 3600; { Number of seconds in an hour }
|
||||||
SecondsInMinute = 60; { Number of seconds in a minute }
|
SecondsInMinute = 60; { Number of seconds in a minute }
|
||||||
|
@ -313,7 +313,6 @@ type
|
|||||||
function CanEdit: Boolean;
|
function CanEdit: Boolean;
|
||||||
function CopyToSchedule(ASchedule: TVpSchedule): TVpEvent;
|
function CopyToSchedule(ASchedule: TVpSchedule): TVpEvent;
|
||||||
function GetResource: TVpResource;
|
function GetResource: TVpResource;
|
||||||
class function IsAllDayEvent(AStartTime, AEndTime: TDateTime): Boolean;
|
|
||||||
function IsOverlayed: Boolean;
|
function IsOverlayed: Boolean;
|
||||||
procedure LoadFromICalendar(AEntry: TVpICalEvent);
|
procedure LoadFromICalendar(AEntry: TVpICalEvent);
|
||||||
class procedure GetAlarmParams(ATrigger: TDateTime; out AdvTime: Integer;
|
class procedure GetAlarmParams(ATrigger: TDateTime; out AdvTime: Integer;
|
||||||
@ -1343,13 +1342,6 @@ begin
|
|||||||
Result := FOwner.Owner;
|
Result := FOwner.Owner;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Returns whether the event specified by its start and end time is an all-day
|
|
||||||
event. This is true when the time-part is zero in each case. }
|
|
||||||
class function TVpEvent.IsAllDayEvent(AStartTime, AEndTime: TDateTime): Boolean;
|
|
||||||
begin
|
|
||||||
Result := (frac(AStartTime) = 0) and (frac(AEndTime) = 0);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ The event is overlayed if its ResourceID is different from that of the
|
{ The event is overlayed if its ResourceID is different from that of the
|
||||||
resource to which it belongs. }
|
resource to which it belongs. }
|
||||||
function TVpEvent.IsOverlayed: Boolean;
|
function TVpEvent.IsOverlayed: Boolean;
|
||||||
@ -1430,7 +1422,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{ All-day event }
|
{ All-day event }
|
||||||
FAllDayEvent := TVpEvent.IsAllDayEvent(FStartTime, FEndTime);
|
FAllDayEvent := AEntry.IsAllDayEvent;
|
||||||
|
|
||||||
{ Alarm properties }
|
{ Alarm properties }
|
||||||
if AEntry.Alarm <> nil then begin
|
if AEntry.Alarm <> nil then begin
|
||||||
@ -1796,10 +1788,10 @@ begin
|
|||||||
Continue;
|
Continue;
|
||||||
startTime := TVpICalEvent(ical[i]).StartTime[false]; // use local times
|
startTime := TVpICalEvent(ical[i]).StartTime[false]; // use local times
|
||||||
endTime := TVpICalEvent(ical[i]).EndTime[false];
|
endTime := TVpICalEvent(ical[i]).EndTime[false];
|
||||||
if (startTime = 0) and (endTime = 0) then
|
if startTime = NO_DATE then
|
||||||
continue;
|
continue;
|
||||||
id := dataStore.GetNextID(EventsTableName);
|
id := dataStore.GetNextID(EventsTableName);
|
||||||
event := AddEvent(id, starttime, endtime);
|
event := AddEvent(id, starttime, endtime - OneSecond);
|
||||||
event.Changed := true;
|
event.Changed := true;
|
||||||
event.LoadFromICalendar(TVpICalEvent(ical[i]));
|
event.LoadFromICalendar(TVpICalEvent(ical[i]));
|
||||||
if (event.Category = 0) and (ADefaultCategory <> -1) then
|
if (event.Category = 0) and (ADefaultCategory <> -1) then
|
||||||
|
@ -77,6 +77,7 @@ type
|
|||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Analyze; override;
|
procedure Analyze; override;
|
||||||
function Categories: TStrings;
|
function Categories: TStrings;
|
||||||
|
function IsAllDayEvent: Boolean;
|
||||||
procedure UseAlarm;
|
procedure UseAlarm;
|
||||||
property Summary: String read FSummary; // is "Description" of tvp
|
property Summary: String read FSummary; // is "Description" of tvp
|
||||||
property Description: String read FDescription; // is "Notes" of tvp
|
property Description: String read FDescription; // is "Notes" of tvp
|
||||||
@ -328,6 +329,9 @@ begin
|
|||||||
FCategories.Delimiter := VALUE_DELIMITER;
|
FCategories.Delimiter := VALUE_DELIMITER;
|
||||||
FCategories.StrictDelimiter := True;
|
FCategories.StrictDelimiter := True;
|
||||||
FCategories.SkipLastLineBreak := True;
|
FCategories.SkipLastLineBreak := True;
|
||||||
|
FStartTime := NO_DATE;
|
||||||
|
FEndTime := NO_DATE;
|
||||||
|
FDuration := NO_DATE;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TVpICalEvent.Destroy;
|
destructor TVpICalEvent.Destroy;
|
||||||
@ -420,6 +424,9 @@ end;
|
|||||||
|
|
||||||
function TVpICalEvent.GetEndTime(UTC: Boolean): TDateTime;
|
function TVpICalEvent.GetEndTime(UTC: Boolean): TDateTime;
|
||||||
begin
|
begin
|
||||||
|
if (FEndTime = NO_DATE) and (FDuration = NO_DATE) then
|
||||||
|
Result := NO_DATE
|
||||||
|
else
|
||||||
if FEndTime <> 0 then
|
if FEndTime <> 0 then
|
||||||
Result := FEndTime
|
Result := FEndTime
|
||||||
else
|
else
|
||||||
@ -430,12 +437,37 @@ end;
|
|||||||
|
|
||||||
function TVpICalEvent.GetStartTime(UTC: Boolean): TDateTime;
|
function TVpICalEvent.GetStartTime(UTC: Boolean): TDateTime;
|
||||||
begin
|
begin
|
||||||
|
if FStartTime = NO_DATE then
|
||||||
|
Result := NO_DATE
|
||||||
|
else
|
||||||
if UTC then
|
if UTC then
|
||||||
Result := FStartTime
|
Result := FStartTime
|
||||||
else
|
else
|
||||||
Result := FCalendar.LocalTimeToUTC(FStartTime, FStartTimeTZ);
|
Result := FCalendar.LocalTimeToUTC(FStartTime, FStartTimeTZ);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ Determines whether the event is an all-day event.
|
||||||
|
See specs (https://www.rfc-editor.org/rfc/rfc5545#page-54):
|
||||||
|
The "DTEND" property for a "VEVENT" calendar component specifies the
|
||||||
|
non-inclusive end of the event. For cases where a "VEVENT" calendar
|
||||||
|
component specifies a "DTSTART" property with a DATE value type but no
|
||||||
|
"DTEND" nor "DURATION" property, the event's duration is taken to
|
||||||
|
be one day. For cases where a "VEVENT" calendar component
|
||||||
|
specifies a "DTSTART" property with a DATE-TIME value type but no
|
||||||
|
"DTEND" property, the event ends on the same calendar date and
|
||||||
|
time of day specified by the "DTSTART" property. }
|
||||||
|
function TVpICalEvent.IsAllDayEvent: Boolean;
|
||||||
|
var
|
||||||
|
tstart, tend: TDateTime;
|
||||||
|
begin
|
||||||
|
tstart := GetStartTime(false);
|
||||||
|
tend := GetEndTime(false);
|
||||||
|
if ((FEndTime = NO_DATE) or (frac(tend) = 0.0)) and (frac(tstart) = 0.0) then
|
||||||
|
Result := true
|
||||||
|
else
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TVpICalEvent.UseAlarm;
|
procedure TVpICalEvent.UseAlarm;
|
||||||
begin
|
begin
|
||||||
FAlarm.Free;
|
FAlarm.Free;
|
||||||
|
@ -24,6 +24,7 @@ type
|
|||||||
FDefaultCategory: String;
|
FDefaultCategory: String;
|
||||||
FTimeFormat: String;
|
FTimeFormat: String;
|
||||||
function GetEventText(AEvent: TVpICalEvent): String;
|
function GetEventText(AEvent: TVpICalEvent): String;
|
||||||
|
|
||||||
procedure SetCalendar(const AValue: TVpICalendar);
|
procedure SetCalendar(const AValue: TVpICalendar);
|
||||||
|
|
||||||
protected
|
protected
|
||||||
@ -47,7 +48,7 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
VpSR;
|
VpSR, VpConst;
|
||||||
|
|
||||||
constructor TVPImportPreviewICalEventForm.Create(AOwner: TComponent);
|
constructor TVPImportPreviewICalEventForm.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
@ -89,6 +90,7 @@ function TVpImportPreviewICalEventForm.GetEventText(AEvent: TVpICalEvent): Strin
|
|||||||
var
|
var
|
||||||
startTime, endTime: TDateTime;
|
startTime, endTime: TDateTime;
|
||||||
sStartTime, sEndTime: String;
|
sStartTime, sEndTime: String;
|
||||||
|
nDays: Integer;
|
||||||
advTime: Integer;
|
advTime: Integer;
|
||||||
advTimeUnits: TVpAlarmAdvType;
|
advTimeUnits: TVpAlarmAdvType;
|
||||||
dingPath: String;
|
dingPath: String;
|
||||||
@ -98,10 +100,11 @@ 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);
|
sEndTime := FormatDateTime(FTimeFormat, endTime - OneSecond);
|
||||||
if TVpEvent.IsAllDayEvent(startTime, endTime) then
|
if AEvent.IsAllDayEvent then
|
||||||
begin
|
begin
|
||||||
if trunc(startTime) = trunc(endTime) then
|
if endTime = NO_DATE then nDays := 1 else nDays := round(endTime - startTime);
|
||||||
|
if nDays in [0, 1] then
|
||||||
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]);
|
||||||
@ -119,8 +122,6 @@ begin
|
|||||||
begin
|
begin
|
||||||
cat := AEvent.Categories.Text;
|
cat := AEvent.Categories.Text;
|
||||||
if cat = '' then cat := '(none)';
|
if cat = '' then cat := '(none)';
|
||||||
// cat := FDatastore.FindBestEventCategory(AEvent.Categories);
|
|
||||||
// if cat = '' then cat := FDefaultCategory;
|
|
||||||
Result := Result + cat;
|
Result := Result + cat;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -242,6 +243,7 @@ begin
|
|||||||
for i := 0 to FCalendar.Count-1 do
|
for i := 0 to FCalendar.Count-1 do
|
||||||
if (FCalendar.Entry[i] is TVpICalEvent) then
|
if (FCalendar.Entry[i] is TVpICalEvent) then
|
||||||
FItems.Add(FCalendar.Entry[i]);
|
FItems.Add(FCalendar.Entry[i]);
|
||||||
|
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
if (FCalendar <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
|
if (FCalendar <> nil) and (FDataStore <> nil) and (Grid.Columns.Count = 2) then
|
||||||
|
Reference in New Issue
Block a user