diff --git a/shifts.ps1 b/shifts.ps1 index 589a243..fea567c 100644 --- a/shifts.ps1 +++ b/shifts.ps1 @@ -335,8 +335,14 @@ try { Write-Debug("{0} {1}: yesterday was Tuesday number {3}, planning RLCZ maintenance shift" -f $dayDate.Date, $dayDate.DayOfWeek, $email, $tuesdaynumber) $rlcz_starttime = $dateEnd.AddHours(1) $rlcz_endtime = $rlcz_starttime.AddHours($rlcz_maintenance_length) - $newshift = Set-Shift -userId $userId -groupID $group.id -shiftName "RLCZ" -StartDate $rlcz_starttime -EndDate $rlcz_endtime -color "yellow" -teamID $team.id -mail $email - $allshifts += [Object[]] $newshift + $rlcz_shifts = [Object[]] $allshifts | Where-Object -Filter { $_.schedulingGroupId -eq $group.Id -and $_.SharedShift.Notes -eq "RLCZ" -and ($_.SharedShift.StartDateTime.ToString("yyyy-MM-dd HH:mm") -eq $rlcz_starttime.ToString("yyyy-MM-dd HH:mm") -and $_.SharedShift.EndDateTime.ToString("yyyy-MM-dd HH:mm") -eq $rlcz_endtime.ToString("yyyy-MM-dd HH:mm")) } + if(Invoke-HasShift -UID $userId -shifts $rlcz_shifts -mail $email) { + Write-Debug("{0} {1}: RLCZ maintenance shift is already set for {2}" -f $dayDate.Date, $dayDate.DayOfWeek, $email) + } + else { + $newshift = Set-Shift -userId $userId -groupID $group.id -shiftName "RLCZ" -StartDate $rlcz_starttime -EndDate $rlcz_endtime -color "yellow" -teamID $team.id -mail $email + $allshifts += [Object[]] $newshift + } } } }