Setting Local Notifications - Days of the week / Everyday

Hi All,

I’m implementing local notifications in my app and I can’t seem to find a way to set days (other than setting specific dates)

Like “Every Tuesday” “Everyday” etc.

I’ve used the documentation example (in this case set to 30secs for testing)

    local function setAlarm()         local futureTime = os.date( "!\*t", os.time() + (30) )         local options = {             alert = "ALERT TEXT",             custom = { msg = "Alert" }         }         local notificationID = system.scheduleNotification( futureTime, options )     end  

I understand I should replace “!*t” for something equivalent to Every Tuesday or Everyday, etc…

Any help?

Convert your current time to date table. Then check wday key. Then add to current time: differenceBetweenTodayAndSaturday*60*60*24

EDIT:

you can only pass time as number

Sorry, I’m not sure I get your answer…  Could you write a code example of what you mean? Thanks!

Ah, sorry - for UTC you must pass table, but other is as follow:

local weekDayForNotification = 2 -- Tuesday local now = os.time() print("now in seconds", now) print("now date", os.date("%d-%m-%Y %H:%M:%S", now)) local date = os.date("!\*t") print("now week day", date.wday) local daysDiff = weekDayForNotification - date.wday if daysDiff \< 0 then daysDiff = daysDiff + 7 end print("days to next week day", daysDiff) -- days to next Tuesday local nextNoticifactionDay = now + daysDiff\*3600\*24 local tableForNotification = os.date("\*t", nextNoticifactionDay) -- I do not use "!" because we added time to UTC time print("next week day in seconds", nextNoticifactionDay) print("next week day date", os.date("%d-%m-%Y %H:%M:%S", nextNoticifactionDay))

Convert your current time to date table. Then check wday key. Then add to current time: differenceBetweenTodayAndSaturday*60*60*24

EDIT:

you can only pass time as number

Sorry, I’m not sure I get your answer…  Could you write a code example of what you mean? Thanks!

Ah, sorry - for UTC you must pass table, but other is as follow:

local weekDayForNotification = 2 -- Tuesday local now = os.time() print("now in seconds", now) print("now date", os.date("%d-%m-%Y %H:%M:%S", now)) local date = os.date("!\*t") print("now week day", date.wday) local daysDiff = weekDayForNotification - date.wday if daysDiff \< 0 then daysDiff = daysDiff + 7 end print("days to next week day", daysDiff) -- days to next Tuesday local nextNoticifactionDay = now + daysDiff\*3600\*24 local tableForNotification = os.date("\*t", nextNoticifactionDay) -- I do not use "!" because we added time to UTC time print("next week day in seconds", nextNoticifactionDay) print("next week day date", os.date("%d-%m-%Y %H:%M:%S", nextNoticifactionDay))