Hi, I am trying to convert the number of the day of the week to the name of the day of the week.
This is what I did so far, but the problem is that it doesn’t work if you put a number higher than 7.
local function formatDay(day: number)
local days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
return days[day]
end
print(formatDay(2)) --> Tuesday
This won’t work either because lua tables start at 1 and not 0 (any multiple of 7 would give 0). They’d have to change the function as well to have the first index be 0 and treat it as such everywhere else.
local function formatDay(day: number)
local days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
return days[day % 7 ~= 0 and day % 7 or 7]
end
print(formatDay(14)) --> Sunday