From 18c1cb04aef71920493092ccc64790d0f5aabd9b Mon Sep 17 00:00:00 2001 From: Ioan Popovici Date: Wed, 17 Jan 2024 19:11:19 +0100 Subject: [PATCH] Released v5.0.4b MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 5.0.4b - 2024–01-17 * Added `OffsetDays` #31 --- .../ufn_CM_GetNextMaintenanceWindow.sql | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/MEM.Zone-Dashboards/Extensions/ufn_CM_GetNextMaintenanceWindow.sql b/MEM.Zone-Dashboards/Extensions/ufn_CM_GetNextMaintenanceWindow.sql index 131b60b..6f702fd 100644 --- a/MEM.Zone-Dashboards/Extensions/ufn_CM_GetNextMaintenanceWindow.sql +++ b/MEM.Zone-Dashboards/Extensions/ufn_CM_GetNextMaintenanceWindow.sql @@ -58,33 +58,35 @@ RETURNS @NextServiceWindow TABLE ( AS BEGIN - --1 Occurs on 1/1/2012 12:00 AM 00011A8500080000 - --2 Occurs every 1 day(s) effective 1/1/2012 8:00 PM 01CA8C80C0100008 - --2 Occurs every 3 day(s) effective 1/1/2012 8:00 PM 02811A8040100018 - --3 Occurs every 3 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F6000 - --3 Occurs every 1 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F2000 - --5 Occurs day 2 of every 2 month(s) effective 1/1/2012 8:00 PM 02811A8040288800 - --5 Occurs day 31 of every 1 month(s) effective 1/1/2012 8:00 PM 02811A80402FC400 - --5 Occurs the last day of every 3 months effective 1/1/2012 8:00 PM 02811A8040280C00 - --5 Occurs the last day of every 1 months effective 1/1/2012 8:00 PM 02811A8040280400 - --4 Occurs the Third Monday of every 1 month(s) effective 1/1/2012 4:00 AM 00811A9E08221600 - --4 Occurs the Last Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241000 - --4 Occurs the Fourth Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241800 - --4 Occurs the Last Monday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040221000 - --3 Occurs every 1 week(s) on Monday effective 1/1/2012 4:00 AM 00811A9E081A2000 + --1 Occurs on 1/1/2012 12:00 AM 00011A8500080000 + --2 Occurs every 1 day(s) effective 1/1/2012 8:00 PM 01CA8C80C0100008 + --2 Occurs every 3 day(s) effective 1/1/2012 8:00 PM 02811A8040100018 + --3 Occurs every 3 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F6000 + --3 Occurs every 1 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F2000 + --5 Occurs day 2 of every 2 month(s) effective 1/1/2012 8:00 PM 02811A8040288800 + --5 Occurs day 31 of every 1 month(s) effective 1/1/2012 8:00 PM 02811A80402FC400 + --5 Occurs the last day of every 3 months effective 1/1/2012 8:00 PM 02811A8040280C00 + --5 Occurs the last day of every 1 months effective 1/1/2012 8:00 PM 02811A8040280400 + --4 Occurs the Third Monday of every 1 month(s) effective 1/1/2012 4:00 AM 00811A9E08221600 + --4 Occurs the Last Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241000 + --4 Occurs the Fourth Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241800 + --4 Occurs the Last Monday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040221000 + --6 Occurs 7 day(s) after the First Monday of every 1 months effective 01-Jan-2024 01:00:00 00211D80083213C0 -- http://msdn.microsoft.com/en-us/library/cc143300.aspx Jump - DECLARE @RecurrenceType_NONE INT - , @RecurrenceType_DAILY INT - , @RecurrenceType_WEEKLY INT - , @RecurrenceType_MONTHLYBYWEEKDAY INT - , @RecurrenceType_MONTHLYBYDATE INT - - SELECT @RecurrenceType_NONE = 1 - , @RecurrenceType_DAILY = 2 - , @RecurrenceType_WEEKLY = 3 - , @RecurrenceType_MONTHLYBYWEEKDAY = 4 - , @RecurrenceType_MONTHLYBYDATE = 5 + DECLARE @RecurrenceType_NONE INT + , @RecurrenceType_DAILY INT + , @RecurrenceType_WEEKLY INT + , @RecurrenceType_MONTHLYBYWEEKDAY INT + , @RecurrenceType_MONTHLYBYDATE INT + , @RecurrenceType_MONTHLYBYWEEKDAYBASE INT + + SELECT @RecurrenceType_NONE = 1 + , @RecurrenceType_DAILY = 2 + , @RecurrenceType_WEEKLY = 3 + , @RecurrenceType_MONTHLYBYWEEKDAY = 4 + , @RecurrenceType_MONTHLYBYDATE = 5 + , @RecurrenceType_MONTHLYBYWEEKDAYBASE = 6 -- http://msdn.microsoft.com/en-us/library/cc143505.aspx Jump @@ -104,9 +106,10 @@ AS SET @StartTime = DATEADD(HOUR, (@ScheduleStartTime / POWER(2,21)) % POWER(2, 5), @StartTime) SET @StartTime = DATEADD(MINUTE, (@ScheduleStartTime / POWER(2,26)) % POWER(2, 5), @StartTime) - -- Determinte UTC and Flags + -- Determinte UTC and Flags and Offset Days DECLARE @IsGMTTime BIT; SET @IsGMTTime = CAST(@ScheduleDuration % POWER(2, 1) AS BIT) DECLARE @Flags INT; SET @Flags = (@ScheduleDuration / POWER(2,19)) % POWER(2, 3) + DECLARE @OffsetDays INT; SET @OffsetDays = (@ScheduleDuration / POWER(2,6)) % POWER(2, 3) -- Calculate the total duration in minutes SET @Duration = @Duration + ((@ScheduleDuration / POWER(2,22)) % POWER(2, 5)) * 24 * 60 -- DAYS @@ -173,7 +176,7 @@ AS SET @NextMaintenanceWindow = @WeeklyNextInterval END - END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYWEEKDAY BEGIN + END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYWEEKDAY OR @RecurrenceType = RecurrenceType_MONTHLYBYWEEKDAYBASE BEGIN DECLARE @MonthlyBWWeek INT; SET @MonthlyBWWeek = (@ScheduleDuration / POWER(2,9)) % POWER(2, 3) DECLARE @MontlhyBWInterval INT; SET @MontlhyBWInterval = (@ScheduleDuration / POWER(2,12)) % POWER(2, 4) DECLARE @MonthlyBWDoW INT; SET @MonthlyBWDoW = (@ScheduleDuration / POWER(2,16)) % POWER(2, 3) @@ -202,7 +205,7 @@ AS SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, -(7 - DATEPART(WEEKDAY, @MonthlyBWLDOMNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWLDOMNextInterval) END - SET @NextMaintenanceWindow = @MonthlyBWLDOMNextInterval + SET @NextMaintenanceWindow = DATEADD(DAY, @OffsetDays, @MonthlyBWLDOMNextInterval) END ELSE BEGIN -- Calculate the next interval DECLARE @MonthlyBWNextInterval DATETIME; SET @MonthlyBWNextInterval = DATEADD(MONTH, @MonthlyBWNumberOfCompletedIntervals * @MontlhyBWInterval, @StartTime) @@ -230,7 +233,7 @@ AS SET @MonthlyBWNextInterval = DATEADD(WEEK, @MonthlyBWWeek-1, @MonthlyBWNextInterval) END - SET @NextMaintenanceWindow = @MonthlyBWNextInterval + SET @NextMaintenanceWindow = DATEADD(DAY, @OffsetDays, @MonthlyBWNextInterval) END END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYDATE BEGIN DECLARE @MontlhyBDInterval INT; SET @MontlhyBDInterval = (@ScheduleDuration / POWER(2,10)) % POWER(2, 4)