calculate date from days variable

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
}

Six lines less (not much):

:set lastday "31"
 :if ([$CurrentMonth] = "02") do={ 
        :if ($leapyear = true) do={ :set lastday "29" }
        :if ($leapyear = false) do={ :set lastday "28" }}
 :if ($CurrentMonth = "04") do={ :set lastday "30" }
 :if ($CurrentMonth = "06") do={ :set lastday "30" }
 :if ($CurrentMonth = "09") do={ :set lastday "30" }
 :if ($CurrentMonth = "11") do={ :set lastday "30" }

Italian:
30 dì conta novembre, con april, giugno e settembre, di 28 ce n’è uno, tutti gli altri ne han 31.
https://it.wikipedia.org/wiki/Trenta_giorni_ha_novembre
English:
https://en.wikipedia.org/wiki/Thirty_Days_Hath_September
Thirty days has September,
April, June, and November,
All the rest have thirty-one,
Save February at twenty-eight,
But leap year, coming once in four,
February then has one day more.

Well yes, in fact you could set 31 by default and only set the exceptions. anyway I thought something could be done by collecting data as an array in a variable

Something like (WARNING: pseudocode, needs to be checked)
:local mdays {31;28;31;30;31;30;31;31;30;31;30;31;29}
:if ([$CurrentMonth] = “02”) do={
:if ($leapyear = true) do={ :set CurrentMonth “13” }
:put [:pick $mdays :tonum:$CurrentMonth ]
?

:local daysOnMnt [:toarray “31,28,31,30,31,30,31,31,30,31,30,31”]
:if ((($yyyy - 1968) % 4) = 0) do={:set ($daysOnMnt->1) 29}