DateTime Errors
I've learned a few lessons lately, one of them regards when not to make something multi-tenant. I started a project and thought, "Yes, Multi-tenancy sounds like a good idea." I know that multi-tenancy can be a good idea, but it turned out to be too much for this project, so now I'm unwinding multi-tenancy. Just having a tenant landing page isn't enough for a multi-tenancy application.
The other issue I have was invisible until just a few days ago. I ran some tests after 8:00 pm on the US east coast, and
tests that had never failed before were suddenly failing. In this project, I want the user to select a date, and the
backend converts it to a timestamp corresponding to the start of day in the Organization's timezone. So someone in Los
Angeles picks 2026-08-09, and the system converts it to 2026-08-09 00:00:00.0 America/Los_Angeles, then converts that
to UTC for the database. In this case, I didn't want the user to pick a date less than today in whatever timezone
they're in. My FormRequest contained code similar to
$date = Carbon::parse((int) $this->server('REQUEST_TIME'), $this->organization->timezone)->format('Y-m-d');
This code worked before, but now, after 8:00 pm, it fails. It's tomorrow UTC, so I know that there's something with the dates.
Big Pickle tells me:
When you pass an integer Unix timestamp to Carbon::parse (), it treats the timestamp as absolute and ignores the
timezone argument (verified: Carbon::parse (time (), 'America/Chicago') stays +00:00). So "earliest start" is
computed in UTC, not the org's timezone.
So my form validation files were failing because the earliest start couldn't be less than tomorrow.
The solution is to use
$date = Carbon::createFromTimestamp(
(int) $this->server('REQUEST_TIME'),
$this->organization->timezone,
)->format('Y-m-d');
createFromTimestamp() honors the timezone (2026-08-06 in both NY and Chicago, verified above), so "earliest start" =
today in the org's timezone.
The test case isn't really deterministic, and it can be modified to be. This allows creating tests at any time, testing
all edges. Instead of relying on the real REQUEST_TIME, it should be pinned via withServerVariables()
$response = $this
->withServerVariables(['REQUEST_TIME' => Carbon::parse('2026-08-07 01:00:00', 'UTC')->getTimestamp()])
->post(route('model.store'));
If you have a numeric timestamp, Carbon::parse() will ignore a timezone, and it's what you want. If you have a numeric
timestamp and a timezone, Carbon::createFromTimeStamp() is your friend.