Table of Contents

PHP RFC: intl_date_format

Introduction

This proposal introduces a new procedural function intl_date_format() to the ext/intl extension. The goal is to provide a simplified, developer-friendly interface for formatting date and time using IntlDateFormatter's capabilities, without the overhead of instantiating and configuring objects for simple use cases.

Motivation

Currently, using IntlDateFormatter for standard formatting requires significant boilerplate code: instantiating an object, setting the timezone and calendar, and finally calling the format method. Adding a procedural function, similar to the core date() function, will improve ergonomics and development speed for internationalized applications.

Proposed Function Signature

function intl_date_format(
    DateTimeInterface|int|string|float $datetime,
    ?string $locale = null,
    int $dateType = IntlDateFormatter::MEDIUM,
    int $timeType = IntlDateFormatter::MEDIUM,
    IntlTimeZone|DateTimeZone|string|null $timezone = null,
    IntlCalendar|int|null $calendar = null,
    string $pattern = ""
): string {}

Parameters

Error Handling

This function adheres to modern PHP 8.7 error handling standards:

Examples

1. Quick format with defaults

echo intl_date_format(new DateTime(), 'fa_IR');
// Output example: ۷ مهر ۱۴۰۵، ۱۸:۳۰:۰۰

2. Full Persian date (no time) using Traditional calendar

echo intl_date_format(
    datetime: '2026-09-28',
    locale: 'fa_IR',
    dateType: IntlDateFormatter::FULL,
    timeType: IntlDateFormatter::NONE,
    calendar: IntlDateFormatter::TRADITIONAL
);
// Output example: دوشنبه ۷ مهر ۱۴۰۵

3. Timestamp with specific timezone

echo intl_date_format(
    datetime: 1790610000,
    locale: 'en_US',
    timezone: 'America/New_York'
);
// Output example: Sep 28, 2026, 10:00:00 AM

4. Using a custom pattern

echo intl_date_format(
    datetime: '2026-09-28 15:30:00',
    locale: 'fa_IR@calendar=persian',
    pattern: 'yyyy/MM/dd'
);
// Output: ۱۴۰۵/۰۷/۰۷

Backward Compatibility

This is a new function and does not introduce any breaking changes.

Performance

To avoid overhead caused by frequently instantiating formatters in tight loops, the implementation utilizes an internal C-level LRU Cache to store and reuse formatter instances.