A user can set a day alert for a birthday. (We do not care about the year of birth)
He also picks if he wants to be alerted 0, 1, 2, ou 7 days (Delta) before the D day.
Users have a timezone setting.
I want the server to send the alerts at 8 am on the the D day – deleta +- user timezone
Example:
12 jun, with “alert me 3 days before” will give 9 of Jun.
My idea was to have a trigger_datetime extra field saved on the ‘recurrent event’ object.
Like this a cron Job running every hour on my server will just check for all events matching irs current time hour, day and month and send to the alert.
The problem from a year to the next the trigger_date could change !
If the alert is set on 1st of March, with a one day delay that could be either 28 or 29 of February ..
Maybe i should not use the trigger date trick and use some other kind of scheme.
All plans are welcome.
Although using plain
datetimepython module you will be able to implement all you need, a much more powerful python-dateutil extension is available, especially if you need to work with recurring events. The code below should give you an indication of how to achieve your goal:And I suggest that you do not store the next year reminder date, because the
deltamay change, ortimezonemay change, and evenbirthdayitself, so you would need to recompute it. The method above basically computes the reminder date (and time) on the fly.One more thing I can suggest is to store for which date (birthday including the year) the last reminder has been sent. So if there is a system downtime you would not miss the reminders but send all that have not been sent. You will need to adapt the code to have this additional check and update.