I have a service where users can create events and participate in said events. On event creation, users can assign the start, end dates and times and then fill in the timezone that the event is going to take place in. Upon completion they can invite other users to participate in the event.
When members visit the event page a piece of backend logic checks current time against the event's start time. If the current time (of the user/user's timezone) is within the start and end time of the event, the user will then be able to attend the event (giving them access to a hallway page where they can video conference).
My issue is with the comparison of dates with different timezones. I'm saving all the dates with the default UTC timezone. Example of a start date being
date: 2019-07-27 11:00:00.0 UTC (+00:00)
And then comparing $now with it. $now being the below for example
date: 2019-07-27 18:11:18.747797 Asia/Beirut (+03:00)
$now is being assigned as such
$now = Carbon::now()->tz($userProfile->timezone->key);
But when I do a comparison such as
$now->lte($event->ends_at)
I'm getting a wrong evaluation where even if $now is later than $event->ends_at it is still evaluating as true. Is it a matter of evaluating dates with different timezones?