Do not try to load date format when custom date format is provided but not declared

Created on 20 April 2025, 2 days ago

Problem/Motivation

When you call \Drupal::service('date.formatter')->format($timestamp, $type = '', $format = 'd.d.d.d') Drupal tries to load the date format based on the type because it is not custom but will not found any format for empty string. This can lead to unnecessary calls.
See profiler images before/after in 🐛 Set missing datetime type Active .

Steps to reproduce

Proposed resolution

Teach people via phpdoc non-empty-string (phpstan) and set internal the type to custom when format is provided or medium, when not.

Remaining tasks

-

User interface changes

-

Introduced terminology

-

API changes

-

Data model changes

-

Release notes snippet

-

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

datetime.module

Created by

🇩🇪Germany tobiasb Berlin

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024