I have a series of Appointments where the date and time is stored under `start_date` as DateTime. I'd like to categorize them as starting in the Morning, Daytime, or Evening. I created an array of hashes with labels and ranges I used for a SQL statement where I convert the `start_date` records into seconds using `CAST(EXTRACT (EPOCH FROM start_time) AS INT)`

```
TIME_RANGES = [
    {label: "Morning", min: 0, max: 32399},
    {label: "Daytime", min: 32400, max: 61199},
    {label: "Evening", min: 61200, max: 86399}
]

cases = TIME_RANGES.map do |r|
    "when CAST (EXTRACT (EPOCH FROM start_date) AS INT) % 86400 between '#{r[:min]}' and '#{r[:max]}' then '#{r[:label]}'"
end

time_ranges = Appointment.select("count(*) as n, case #{time_cases.join(' ')} end as time_range").group('time_range')

```

This takes the number of seconds in a day (86400) and labels the appointments based on the modulo of the `start_date` with 86400. However, a number of appointments take place in different timezones, but they're all stored as UTC. So an appointment at 08:00 AM EST is equivalent to one at 07:00 AM CST, but both are stored internally as 12:00 PM UTC. This would cause the appointments to be incorrectly labelled as "Daytime" when they're intended to be "Morning" (from the perspective of the User booking it).

Ideally, I would like some way to convert the `start_date` based on the User's timezone to make it look like it occurred in UTC. So I would want a 12:00 PM EST appointment to be labelled as if it were a 12:00 PM UTC appointment instead of 04:00 PM UTC. More specifically, I would like to subtract 14400 seconds from the converted `start_date` before performing the modulo. 

I can join Appoinments to Users, which contains the User's timezone. How can I incorporate this information into my query above, so that a modified `start_date` is used for each record, depending on the User's timezone in that same record?

I know I could accomplish this with a loop of each timezone and adding/substracting a specific amount of seconds in each loop, then combining the results of all the loops, but I was wondering if there was a way to do it in one query.