Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sector Nord AG: Bugfix - CalendarAppointment Daylight Saving Time _AppointmentRecurringCreate() #517

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Kernel/System/Calendar/Appointment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,9 @@ sub AppointmentNotification {

sub _AppointmentRecurringCreate {
my ( $Self, %Param ) = @_;
my %User = $Kernel::OM->Get('Kernel::System::User')->GetUserData(
UserID => $Param{Appointment}->{UserID}
);

# check needed stuff
for my $Needed (qw(ParentID Appointment)) {
Expand All @@ -2302,12 +2305,14 @@ sub _AppointmentRecurringCreate {
'Kernel::System::DateTime',
ObjectParams => {
String => $Param{Appointment}->{StartTime},
TimeZone => $User{UserTimeZone} || '',
},
);
my $EndTimeObject = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
String => $Param{Appointment}->{EndTime},
TimeZone => $User{UserTimeZone} || '',
},
);

Expand Down Expand Up @@ -2366,6 +2371,30 @@ sub _AppointmentRecurringCreate {
Time => $EndTime,
);

# Account for Dates in different timezones
my $StartDSTDiff = $StartTimeObject->CompareDST($OriginalStartTimeObject);
my $EndDSTDiff = $EndTimeObject->CompareDST($OriginalEndTimeObject);
my $CurrentStartTimeObject = $StartTimeObject->Clone();
my $CurrentEndTimeObject = $EndTimeObject->Clone();
if ( IsInteger( $StartDSTDiff ) ) {
if ( $StartDSTDiff > 0 ) {
$CurrentStartTimeObject->Subtract( Seconds => $StartDSTDiff );
}
elsif ( $StartDSTDiff < 0 ) {
$CurrentStartTimeObject->Add( Seconds => ($StartDSTDiff * -1));
}
$StartTime = $CurrentStartTimeObject->ToString();
}
if ( IsInteger( $EndDSTDiff ) ) {
if ( $EndDSTDiff > 0 ) {
$CurrentEndTimeObject->Subtract( Seconds => $EndDSTDiff );
}
elsif ( $EndDSTDiff < 0 ) {
$CurrentEndTimeObject->Add( Seconds => ($EndDSTDiff * -1));
}
$EndTime = $CurrentEndTimeObject->ToString();
}

# skip excluded appointments
next UNTIL_TIME if grep { $StartTime eq $_ } @RecurrenceExclude;

Expand Down
14 changes: 14 additions & 0 deletions Kernel/System/DateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,20 @@ sub _OpNotEquals {
return $Result;
}

=head2 CompareDST()

this function checks compares two DateTime objects and returns the TimeDifference in seconds
my $DSTDiff = $DateTimeObject->CompareDST( $OtherDateTimeObject );
return: '3600'

=cut

sub CompareDST {
my ($Self, $OtherDateTimeObject) = @_;

return $Self->{CPANDateTimeObject}->offset - $OtherDateTimeObject->{CPANDateTimeObject}->offset;
}

1;

=end Internal:
Expand Down
Loading