You are reaching what are called edge cases. You need a function to actually do the math for you.
Something like this might work.I hhaven't tested it but the logic is there. I also apologize for the formating. I'm on my phone.
-- Function to get tomorrow's date function getTomorrow()
local currentDay = tonumber(os.date("%d"))
-- Get today's date as a number
local daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
local currentMonth = tonumber(os.date("%m"))
local currentYear = tonumber(os.date("%Y"))
-- Adjust for leap year
if (currentYear % 4 == 0 and (currentYear % 100 ~= 0 or currentYear % 400 == 0)) then
daysInMonth[2] = 29
end
-- Increment the day, adjust month and year if needed currentDay = currentDay + 1
if currentDay > daysInMonth[currentMonth] then
currentDay = 1
currentMonth = currentMonth + 1
if currentMonth > 12 then
currentMonth = 1
currentYear = currentYear + 1
end
end
return string.format("%02d/%02d/%04d", currentMonth, currentDay, currentYear)
end
-- Function to get yesterday's date function getYesterday()
local currentDay = tonumber(os.date("%d"))
local daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
local currentMonth = tonumber(os.date("%m"))
local currentYear = tonumber(os.date("%Y"))
-- Adjust for leap year
if (currentYear % 4 == 0 and (currentYear % 100 ~= 0 or currentYear % 400 == 0)) then daysInMonth[2] = 29 end
-- Decrement the day, adjust month and year if needed currentDay = currentDay - 1
if currentDay < 1 then
currentMonth = currentMonth - 1
if currentMonth < 1 then
currentMonth = 12
currentYear = currentYear - 1
end
currentDay = daysInMonth[currentMonth]
end
return string.format("%02d/%02d/%04d", currentMonth, currentDay, currentYear)
end
-- Display the dates text_layer_tomorrow = wm_tag("{dh23z}:{dmz}") .. " Tomorrow: " .. getTomorrow() text_layer_yesterday = wm_tag("{dh23z}:{dmz}") .. " Yesterday: " .. getYesterday()