Skip to content

Read UNIX timestamps in the application timezone - #257

Merged
LukeTowers merged 1 commit into
wintercms:wip/1.3from
JonasPardon:fix/timestamp-dates-app-timezone
Oct 22, 2026
Merged

LukeTowers merged 1 commit into
wintercms:wip/1.3from
JonasPardon:fix/timestamp-dates-app-timezone

Conversation

@JonasPardon

@JonasPardon JonasPardon commented Oct 8, 2026 •

Copy link
Copy Markdown

With a non-UTC app.timezone, a UNIX timestamp assigned to a date attribute is stored shifted by the UTC offset on wip/1.3:

// app.timezone = 'Europe/Brussels'
$model->published_at = 1700000000; // 2023-11-14 22:13:20 UTC

// 1.2: stored as '2023-11-14 23:13:20'
// wip/1.3: stored as '2023-11-14 22:13:20', which reads back an hour earlier

Model::asDateTime() calls Argon::createFromTimestamp($value) without a timezone. Carbon 2 used PHP's default timezone for that, which Storm sets from app.timezone. Carbon 3 uses UTC instead. Laravel hit the same regression and fixed it the same way in laravel/framework@8c61f50 (#50751), which is still how HasAttributes::asDateTime() reads on 12.x. Projects on the default UTC timezone are not affected.

  • Pass date_default_timezone_get(), like Laravel.
  • Add a test that assigns a timestamp with Europe/Brussels as the default timezone and checks that the stored value and the timestamp read back are correct. It fails without the change.

asDateTime() is the only numeric-timestamp cast in Storm. Laravel's commit also covered its other createFromTimestamp() call sites; the equivalent ones in Winter core are fixed in wintercms/winter#1579.

🤖 Generated with Claude Code

Carbon 3 creates a date from a timestamp in UTC unless a timezone is given, so with a non-UTC app.timezone a numeric value assigned to a date attribute was stored as UTC wall-clock time and shifted by the offset. Laravel 12 passes date_default_timezone_get() for the same reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3fe812f2-28ae-4322-b4fe-a2491167cd71

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LukeTowers
LukeTowers merged commit 28f5bbe into wintercms:wip/1.3 Oct 22, 2026
10 checks passed
LukeTowers added a commit to wintercms/winter that referenced this pull request Oct 22, 2026
Carbon 2 read a bare Carbon::createFromTimestamp() in PHP's default timezone, which Laravel sets from app.timezone; Carbon 3 reads it as UTC. On wip/1.3 that converts every numeric UNIX timestamp an offset out for any project whose app.timezone is not UTC. Pass date_default_timezone_get() at each call site, as Laravel did in laravel/framework@8c61f50 (laravel/framework#50751). Companion to wintercms/storm#257, which fixed Model::asDateTime() the same way.

System\Helpers\DateTime::makeCarbon() — Backend::dateTime() writes the result into <time datetime="…"> and winter.datetime.js reads it back with moment.tz(datetime, appTimezone), so a UTC wall time was reinterpreted as app-local and every backend list date column displayed an offset out. timeTense() and the CMS editor's last-modified tooltip format it directly, with the same result.
System\Classes\MediaLibraryItem::lastModifiedAsString() — a file touched after local midnight was listed under the previous day.
Backend\FormWidgets\DatePicker — integer minDate/maxDate bounds landed an offset away from their string equivalents.
Backend::makeCarbon() needed no change: it calls setTimezone() afterwards, which preserves the instant.

Eight tests across four classes, every one failing without the change, sharing a fixture instant of 23:30 UTC — the next day at 00:30 in Europe/Brussels, so a timezone slip moves the date as well as the clock. Full suite on wip/1.3: 882 tests green.
bennothommo pushed a commit to wintercms/wn-system-module that referenced this pull request Oct 22, 2026
Carbon 2 read a bare Carbon::createFromTimestamp() in PHP's default timezone, which Laravel sets from app.timezone; Carbon 3 reads it as UTC. On wip/1.3 that converts every numeric UNIX timestamp an offset out for any project whose app.timezone is not UTC. Pass date_default_timezone_get() at each call site, as Laravel did in laravel/framework@8c61f50 (laravel/framework#50751). Companion to wintercms/storm#257, which fixed Model::asDateTime() the same way.

System\Helpers\DateTime::makeCarbon() — Backend::dateTime() writes the result into <time datetime="…"> and winter.datetime.js reads it back with moment.tz(datetime, appTimezone), so a UTC wall time was reinterpreted as app-local and every backend list date column displayed an offset out. timeTense() and the CMS editor's last-modified tooltip format it directly, with the same result.
System\Classes\MediaLibraryItem::lastModifiedAsString() — a file touched after local midnight was listed under the previous day.
Backend\FormWidgets\DatePicker — integer minDate/maxDate bounds landed an offset away from their string equivalents.
Backend::makeCarbon() needed no change: it calls setTimezone() afterwards, which preserves the instant.

Eight tests across four classes, every one failing without the change, sharing a fixture instant of 23:30 UTC — the next day at 00:30 in Europe/Brussels, so a timezone slip moves the date as well as the clock. Full suite on wip/1.3: 882 tests green.
bennothommo pushed a commit to wintercms/wn-backend-module that referenced this pull request Oct 22, 2026
Carbon 2 read a bare Carbon::createFromTimestamp() in PHP's default timezone, which Laravel sets from app.timezone; Carbon 3 reads it as UTC. On wip/1.3 that converts every numeric UNIX timestamp an offset out for any project whose app.timezone is not UTC. Pass date_default_timezone_get() at each call site, as Laravel did in laravel/framework@8c61f50 (laravel/framework#50751). Companion to wintercms/storm#257, which fixed Model::asDateTime() the same way.

System\Helpers\DateTime::makeCarbon() — Backend::dateTime() writes the result into <time datetime="…"> and winter.datetime.js reads it back with moment.tz(datetime, appTimezone), so a UTC wall time was reinterpreted as app-local and every backend list date column displayed an offset out. timeTense() and the CMS editor's last-modified tooltip format it directly, with the same result.
System\Classes\MediaLibraryItem::lastModifiedAsString() — a file touched after local midnight was listed under the previous day.
Backend\FormWidgets\DatePicker — integer minDate/maxDate bounds landed an offset away from their string equivalents.
Backend::makeCarbon() needed no change: it calls setTimezone() afterwards, which preserves the instant.

Eight tests across four classes, every one failing without the change, sharing a fixture instant of 23:30 UTC — the next day at 00:30 in Europe/Brussels, so a timezone slip moves the date as well as the clock. Full suite on wip/1.3: 882 tests green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants