Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Should I store start time, end time, and days as separate fields or use a CRON expression in my database?

$
0
0

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:

  1. Storing start time, end time, and a list of days as separate fields.
  2. 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!


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>