I have users from multiple timezone and storing time in Database in UTC format. Running into issue with time part alone.
Storing user working hours for the Week as follows.
Id | UserId | Day | StTime | EndTime |
---|---|---|---|---|
1 | 1 | 0 | 10:00 | 18:00 |
2 | 1 | 1 | 10:00 | 18:00 |
3 | 1 | 2 | 10:00 | 18:00 |
4 | 1 | 3 | 10:00 | 18:00 |
5 | 1 | 4 | 10:00 | 18:00 |
Day, 0 for Sunday,1 for Monday, ...
Here, the time is being stored in UTC. The time is being converted in the UI based on the browser timezone. Since, there is no date part needed here, it is causing issues here.
For ex, Let's say user is selecting 7AM to 7PM in UI and the time gets converted to UTC which is 15:00 today to 02:00 tomorrow. So, in DB the time is being stored as
Id | UserId | Day | StTime | EndTime |
---|---|---|---|---|
1 | 1 | 0 | 15:00 | 02:00 |
2 | 1 | 1 | 15:00 | 02:00 |
3 | 1 | 2 | 15:00 | 02:00 |
4 | 1 | 3 | 15:00 | 02:00 |
5 | 1 | 4 | 15:00 | 02:00 |
Here, start time is bigger than the end time, which is not correct.
How do we need to handle timezone when storing just the time part of it?
My requirement is to get open slots for a user based on the following info.
- Booked slots
- Blocked Slots
- Working hours
BookedSlots,
Id | userId | St_time(datetime) | duration(mins) |
---|---|---|---|
1 | 1 | 2021-11-27 16:00:00 | 30 |
1 | 1 | 2021-11-27 18:00:00 | 45 |
Here, the time is in UTC.
- BlockedSlots
Id | userId | St_time | end_date | st_time | end_time |
---|---|---|---|---|---|
1 | 1 | 2021-11-22 | 2021-11-25 | 09:00 | 18:00 |
1 | 1 | 2021-12-17 | 2021-12-20 | 09:00 | 18:00 |
Here also, time needs to be stored in UTC
- WorkingHours
Id | UserId | Day | StTime | EndTime |
---|---|---|---|---|
1 | 1 | 0 | 15:00 | 02:00 |
2 | 1 | 1 | 15:00 | 02:00 |
3 | 1 | 2 | 15:00 | 02:00 |
4 | 1 | 3 | 15:00 | 02:00 |
5 | 1 | 4 | 15:00 | 02:00 |
I need to calculate open slots based on the above 3 info. But, time part is confusing when we store that in UTC. What is the best way to handle this?
Day
forStTime
and anotherDay
for theEndTime
– Emergence