Skip to content

Commit

Permalink
Released v5.0.4b
Browse files Browse the repository at this point in the history
## 5.0.4b - 2024–01-17

* Added `OffsetDays` #31
  • Loading branch information
Ioan-Popovici committed Jan 17, 2024
1 parent 2dfa0a2 commit 18c1cb0
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions MEM.Zone-Dashboards/Extensions/ufn_CM_GetNextMaintenanceWindow.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 18c1cb0

Please sign in to comment.