Good morning everyone, I created this script to allow the user via the LifeDay variable to decide after how many days to schedule the deletion of a hotspot user. the script works perfectly. writes the date in YYYY-MM-DD format in the user’s comment. another script reads how long the user has been active and if he has exceeded the days set in LifeDay it has been shown to delete him. In your opinion, is the part of the screenplay that I post below well done? From the tests I’ve done it seems reliable, but maybe it can be simplified with fewer lines
{
:local CurrentDate [/system clock get date]
:local CurrentDay "10"
#[:pick $CurrentDate 8 10]
:local CurrentMonth "12"
#[:pick $CurrentDate 5 7]
:local CurrentYear "2027"
#[:pick $CurrentDate 0 4]
:local LastYear ($CurrentYear-1)
:local dayX
:local monthX
:local yearX
:local dateX
:local lastday
:global LifeDay
:local leapyear
:local yeardiv
:local yearmult
:set yeardiv ($CurrentYear / 4)
:set yearmult ($yeardiv * 4)
:if ([$yearmult] = $CurrentYear) do={ :set leapyear true } else={ :set leapyear false }
:if ([$CurrentMonth] = "01") do={ :set lastday "31" }
:if ([$CurrentMonth] = "02") do={
:if ($leapyear = true) do={ :set lastday "29" }
:if ($leapyear = false) do={ :set lastday "28" }}
:if ($CurrentMonth = "03") do={ :set lastday "31" }
:if ($CurrentMonth = "04") do={ :set lastday "30" }
:if ($CurrentMonth = "05") do={ :set lastday "31" }
:if ($CurrentMonth = "06") do={ :set lastday "30" }
:if ($CurrentMonth = "07") do={ :set lastday "31" }
:if ($CurrentMonth = "08") do={ :set lastday "31" }
:if ($CurrentMonth = "09") do={ :set lastday "30" }
:if ($CurrentMonth = "10") do={ :set lastday "31" }
:if ($CurrentMonth = "11") do={ :set lastday "30" }
:if ($CurrentMonth = "12") do={ :set lastday "31" }
:put $CurrentMonth
:put $lastday
:local dayX ($CurrentDay + $LifeDay);
:if ($dayX <= $lastday) do={
:set monthX ($CurrentMonth)
:set yearX ($CurrentYear)
}
:if ($dayX > $lastday) do={
:if ($CurrentMonth ="12") do={
:set dayX ($dayX-$lastday)
:set monthX ($CurrentMonth-"11")
:set yearX ($CurrentYear+"1")
}
:if ($CurrentMonth < "12") do={
:set dayX ($dayX-$lastday)
:set monthX ($CurrentMonth+"1")
:set yearX ($CurrentYear)
}
}
:local monthY [:len $monthX]
:local dayY [:len $dayX]
:if ($monthY = 1) do={
:set $monthX ("0".$monthX)
}
:if ($dayY = 1) do={
:set $dayX ("0".$dayX)
}
:local dateX ($yearX."-".$monthX."-".$dayX)
:put $dateX
}