Skip to content

Use CoreExtension's date methods instead of Twig's deprecated date helpers - #1600

Merged
LukeTowers merged 2 commits into
developfrom
fix/twig-date-deprecations
Nov 11, 2026
Merged

LukeTowers merged 2 commits into
developfrom
fix/twig-date-deprecations

Conversation

@LukeTowers

@LukeTowers LukeTowers commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Winter's date() Twig function and |date filter (modules/system/ServiceProvider.php) call twig_date_converter() and twig_date_format_filter(). Twig deprecated both helpers in 3.9, so every template that uses |date logs this on every render:

Since twig/twig 3.9: Using the internal "twig_date_format_filter" function is deprecated.

The helpers only forward to CoreExtension::convertDate() and CoreExtension::formatDate(). This PR calls those methods directly. Winter requires twig/twig ^3.21, so they're always available, and the output is identical.

Removing those two calls exposed one more deprecation. {{ date() }} passed null to DateTime::makeCarbon(), and makeCarbon()'s preg_match() deprecates a null subject. It now passes 'now'. makeCarbon() already resolved null to now (through Carbon::parse(null)), so the result is the same.

Follow-up to #1595, which fixed the tag, filter and list deprecations from the same production logs but not these two helpers.

Side note, not changed here: in the date() function, the is_null($value) || $value === 'now' branch can never run, because $value has already been replaced by a DateTime at that point.

Testing

  • Fixture: the CMS tags fixture (modules/cms/tests/fixtures/twig/tags.htm, from Fix Twig 3.x and PHP 8.3 deprecations from core Twig tags, filters and lists #1595) gets a line 20. It calls date() with and without an argument, and applies |date to a string, a Carbon instance and a DateInterval. TagsTest passes in the last two as template variables. That test already renders the fixture through a CMS controller, in both the normal and use_yield environments, and fails on any deprecation.
    • Without this change, both TagsTest tests fail on twig_date_converter, twig_date_format_filter and preg_match(): Passing null.
    • With it, both pass.
  • Full modules/system suite: run locally on develop with and without the change. It reports the same set of errors and failures, all from my local environment.
  • phpcs: clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GMxdgmMTLxfALWSSvtBYYR

Summary by CodeRabbit

  • Bug Fixes
    • Updated Twig date and time formatting to correctly handle empty date values and current-time output.
    • Improved consistency for rendering dates, relative dates, and intervals.

The date() function and |date filter called twig_date_converter() and
twig_date_format_filter(), deprecated since Twig 3.9; every template using
|date logged a deprecation per render. Call CoreExtension::convertDate() and
::formatDate(), which those helpers wrap (Winter requires twig/twig ^3.21).

date() with no argument also passed null to DateTime::makeCarbon(), whose
preg_match() deprecates null; pass 'now' instead (makeCarbon already treated
null as now, so the output is unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GMxdgmMTLxfALWSSvtBYYR
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Twig date function now substitutes 'now' for a null non-DateInterval value and uses CoreExtension::convertDate. The date filter uses CoreExtension::formatDate. The Twig tag fixture and test context now cover date formatting for literals, variables, and an interval.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • wintercms/winter#1595: This PR also updates Twig integration for Twig 3.x deprecations and adds coverage to the shared CMS TagsTest fixture.
Merge Risk: Minimal · up to f50ed

The date helpers use the current Twig API without an established behavior regression. No merge-blocking issue was found.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: replacing Twig's deprecated date helpers with CoreExtension date methods.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (2 skipped: 2 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53e96403-01f7-4a6b-a53f-0142aa8a1475
Commits

Reviewing files that changed from the base of the PR and between fe0867d and f50ed27.

Files selected for processing: 3

  • modules/cms/tests/fixtures/twig/tags-expected.txt
  • modules/cms/tests/fixtures/twig/tags.htm
  • modules/cms/tests/twig/TagsTest.php

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

The CMS tags fixture already renders everything through a controller and
fails on any deprecation, in both the normal and use_yield environments.
Add a line exercising date() (with and without an argument) and |date on a
string, a Carbon instance and a DateInterval, and drop DateTest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GMxdgmMTLxfALWSSvtBYYR
@LukeTowers
LukeTowers merged commit f9bc204 into develop Nov 11, 2026
16 checks passed
@LukeTowers
LukeTowers deleted the fix/twig-date-deprecations branch November 11, 2026 06:36
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.

1 participant