I would like to set up a function to automatically insert pre-defined shifts into a schedule table. I have created a table called shift_times that stores the required start/end times for each distinct shift type:
| start_time | lunch_start | lunch_end | end_time |
| 8:30am | 12:00pm | 12:45pm | 4:30pm |
Because the start and end times are not specific to any date, I am unsure of the best data type to use for this column.
One idea I have toyed with is using a Double, with the minutes stored after the decimal point. The table above would look like this:
| start_time | lunch_start | lunch_end | end_time |
| 8.5 | 12 | 12.75 | 16.5 |
The schedule works exclusively at a granularity of 15 minutes, so the decimals will always round to the nearest 0.25, and it should be quite an easy format to convert to and from (and easy to send as JSON).
However, I’m not sure if I would be better served by a more detailed number format (e.g. number of minutes since midnight) or an actual date/time field with the date portion disregarded.
Don’t try to use doubles for this kind of problem because they seem convenient.
Have a bit of a look at why you shouldn’t use doubles to store money values. Same arguments apply to times.
Your suggestion of an integer number of minutes past 0000 is probably a good starting point.