How to know the last weekend of a month in LUA

4

How to get the last weekend of March to change your time for daylight saving time.

Code to identify whether it is the month of March and whether it is a Sunday.

month_now=os.date("%m")
week_day=os.date("%w")
if week_day=="7" then
  print("domingo")
end
if month_now=="03" then
  print("Março")
end
    
asked by anonymous 17.01.2015 / 12:52

1 answer

3

Without entering the merits of daylight saving time, the function below calculates the day of the last Saturday in March of a given year.

function last(y)
    local t={ day=31, month=3, year=y }
    local w=os.date("*t",os.time(t)).wday
    return 31-(w%7)
end
    
19.01.2015 / 02:00