I am developing a scheduling feature in my application where users can set specific time ranges and days for recurring tasks. For example, a user might configure a task to run every Thursday and Friday from 15:00 to 16:00.
I need to store these schedules in my database and am debating between two approaches:
- Storing start time, end time, and a list of days as separate fields.
- Using a CRON expression to represent the schedule.
Here's a simplified version of the current approach using separate fields:
start_time: "15:00"end_time: "16:00"days: ["Thursday", "Friday"]
Alternatively, I could convert these schedules to a CRON expression in UTC:
CRON: "0 15 * * 4,5"
Considerations :
Time Zones: Users configure times in their local time zone, but the application needs to store and process these times in UTC - Maybe it is better to store it as UTC, right?
If a user change it's time zone, for example he moves from time zone A to B, I will have to update all it's schedules stored in database, because the time (15h-16h) should be the same.
Users have a date picker. it's easier for them to use date picker instead define a cron.
Questions:
- Which approach is generally recommended for storing recurring schedules in a database?
- Are there best practices or common patterns for handling such scheduling requirements?
Thank you a lot!