if now >
(
value of setting "MaintenanceWindow_StartTime" of client & " " & local time zone as string
)
as time then
(
(
if
(
item 0 of it = "once"
)
then
(
(
item 1 of it & item 2 of it
)
)
else if
(
item 0 of it = "daily"
)
then
(
(
item 1 of it +
(
(
now - item 1 of it
)
/ day / item 3 of it *
(
day * item 3 of it
)
)
)
& item 2 of it
)
else if
(
item 0 of it = "weekly"
)
then
(
it &
(
(
value of setting "MaintenanceWindow_WindowSizeMinutes" of client as integer
)
* minute
)
)
of
(
maximum of
(
it - 1*day; it - 2*day; it - 3*day; it - 4*day; it - 5*day; it -6 * day;it; it + 1*day; it + 2*day;it + 3*day;it + 4*day;it + 5*day;it + 6*day
)
whose
(
it < now AND
(
(
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as string as lowercase
)
)
contains
(
first 3 of
(
it as string
)
as day_of_week as string as lowercase
)
)
)
of
(
(
(
current date - item 0 of it
)
/
(
item 3 of it * week
)
*
(
item 3 of it * week
)
)
+ item 0 of it & item 1 of it
)
of
(
(
(
(
date
(
local time zone
)
of item 1 of it -
(
(
first 3 of
(
item 1 of it as string
)
as day_of_week
)
- sunday
)
)
)
, time
(
local time zone
)
of item 1 of it, item 2 of it, item 3 of it
)
)
)
else if
(
item 0 of it = "monthly"
)
then
(
it &
(
value of setting "MaintenanceWindow_WindowSizeMinutes" of client as integer * minute
)
)
of
(
(
if
(
item 3 of it = 0
)
then
(
maximum of
(
(
if exists
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
current month & current year
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
then
(
(
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
current month & current year
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
)
& time
(
local time zone
)
of item 1 of it
)
else nothing
)
;
(
if exists
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
(
current month - month
)
& current year
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
then
(
if
(
current month as integer = 1
)
then
(
(
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
(
current month - month
)
&
(
(
current year
)
- 1* year
)
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
)
& time
(
local time zone
)
of item 1 of it
)
else
(
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
(
current month - month
)
& current year
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
)
& time
(
local time zone
)
of item 1 of it
)
else nothing
)
;
(
if exists
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
(
current month -
(
2*month
)
)
& current year
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
then
(
if
(
current month as integer = 1
)
then
(
(
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
(
current month -
(
2*month
)
)
&
(
(
current year
)
- 1* year
)
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
)
& time
(
local time zone
)
of item 1 of it
)
else
(
(
first
(
value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week
)
of
(
(
current month -
(
2*month
)
)
& current year
)
+
(
(
value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1
)
* week
)
)
)
& time
(
local time zone
)
of item 1 of it
)
else nothing
)
)
whose
(
it < now
)
)
else
(
maximum of
(
(
if exists
(
(
current month &
(
day_of_month
(
item 3 of it
)
)
)
)
then
(
(
(
current month &
(
day_of_month
(
item 3 of it
)
)
)
& current year
)
& time
(
local time zone
)
of item 1 of it
)
else nothing
)
;
(
if exists
(
(
(
current month - 1* month
)
&
(
day_of_month
(
item 3 of it
)
)
)
)
then
(
if
(
current month as integer = 1
)
then
(
(
(
(
current month - 1*month
)
&
(
day_of_month
(
item 3 of it
)
)
)
&
(
current year - 1*year
)
)
& time
(
local time zone
)
of item 1 of it
)
else
(
(
(
current month - 1*month
)
&
(
day_of_month
(
item 3 of it
)
)
)
& current year
)
& time
(
local time zone
)
of item 1 of it
)
else nothing
)
;
(
if exists
(
(
(
current month - 2*month
)
&
(
day_of_month
(
item 3 of it
)
)
)
)
then
(
if
(
current month as integer = 1
)
then
(
(
(
(
current month - 2*month
)
&
(
day_of_month
(
item 3 of it
)
)
)
&
(
current year - 1*year
)
)
& time
(
local time zone
)
of item 1 of it
)
else
(
(
(
current month - 2*month
)
&
(
day_of_month
(
item 3 of it
)
)
)
& current year
)
& time
(
local time zone
)
of item 1 of it
)
else nothing
)
)
whose
(
it < now
)
)
)
)
else error "invalid maintenance type"
)
)
of
(
value of setting "MaintenanceWindow_RepeatType" of client,
(
value of setting "MaintenanceWindow_StartTime" of client & " " & local time zone as string
)
as time,
(
value of setting "MaintenanceWindow_WindowSizeMinutes" of client as integer
)
* minute, value of setting "MaintenanceWindow_RepeatInterval" of client as integer
)
else nothing
if now > (value of setting "MaintenanceWindow_StartTime" of client & " " & local time zone as string) as time then ((if (item 0 of it = "once") then ((item 1 of it & item 2 of it)) else if (item 0 of it = "daily") then ((item 1 of it + ((now - item 1 of it) / day / item 3 of it * (day * item 3 of it))) & item 2 of it) else if (item 0 of it = "weekly") then (it & ((value of setting "MaintenanceWindow_WindowSizeMinutes" of client as integer) * minute)) of (maximum of (it - 1*day; it - 2*day; it - 3*day; it - 4*day; it - 5*day; it -6 * day;it; it + 1*day; it + 2*day;it + 3*day;it + 4*day;it + 5*day;it + 6*day) whose (it < now AND (((value of setting "MaintenanceWindow_DaysOfWeek" of client as string as lowercase)) contains (first 3 of (it as string) as day_of_week as string as lowercase))) of (((current date - item 0 of it) / (item 3 of it * week) * (item 3 of it * week)) + item 0 of it & item 1 of it) of ((((date (local time zone) of item 1 of it - ((first 3 of (item 1 of it as string) as day_of_week) - sunday))) , time (local time zone) of item 1 of it, item 2 of it, item 3 of it))) else if (item 0 of it = "monthly") then (it & (value of setting "MaintenanceWindow_WindowSizeMinutes" of client as integer * minute)) of ((if (item 3 of it = 0) then (maximum of ((if exists (first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of (current month & current year) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week)) then (((first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of (current month & current year) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week))) & time (local time zone) of item 1 of it) else nothing) ; (if exists (first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of ((current month - month) & current year) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week)) then (if (current month as integer = 1) then (((first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of ((current month - month) & ((current year) - 1* year)) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week))) & time (local time zone) of item 1 of it) else ((first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of ((current month - month) & current year) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week))) & time (local time zone) of item 1 of it) else nothing) ; (if exists (first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of ((current month - (2*month)) & current year) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week)) then (if (current month as integer = 1) then (((first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of ((current month - (2*month)) & ((current year) - 1* year)) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week))) & time (local time zone) of item 1 of it) else ((first (value of setting "MaintenanceWindow_DaysOfWeek" of client as day_of_week) of ((current month - (2*month)) & current year) + ((value of setting "MaintenanceWindow_DayOrdinal" of client as integer - 1) * week))) & time (local time zone) of item 1 of it) else nothing)) whose (it < now)) else (maximum of ((if exists ((current month & (day_of_month (item 3 of it)))) then (((current month & (day_of_month (item 3 of it))) & current year) & time (local time zone) of item 1 of it) else nothing) ; (if exists (((current month - 1* month) & (day_of_month (item 3 of it)))) then (if (current month as integer = 1) then ((((current month - 1*month) & (day_of_month (item 3 of it))) & (current year - 1*year)) & time (local time zone) of item 1 of it) else (((current month - 1*month) & (day_of_month (item 3 of it))) & current year) & time (local time zone) of item 1 of it) else nothing) ; (if exists (((current month - 2*month) & (day_of_month (item 3 of it)))) then (if (current month as integer = 1) then ((((current month - 2*month) & (day_of_month (item 3 of it))) & (current year - 1*year)) & time (local time zone) of item 1 of it) else (((current month - 2*month) & (day_of_month (item 3 of it))) & current year) & time (local time zone) of item 1 of it) else nothing)) whose (it < now)))) else error "invalid maintenance type")) of (value of setting "MaintenanceWindow_RepeatType" of client, (value of setting "MaintenanceWindow_StartTime" of client & " " & local time zone as string) as time, (value of setting "MaintenanceWindow_WindowSizeMinutes" of client as integer) * minute, value of setting "MaintenanceWindow_RepeatInterval" of client as integer) else nothing