Skip to content

IntlDateFormatter returns incorrect week number for an invalid locale (and doesn't throw an exception either) #12282

Description

@campbell-m

Description

The following code:

<?php
$date = DateTimeImmutable::createFromFormat('Y-m-d', '2023-09-23', new DateTimeZone('Europe/London'));

foreach (['en', 'xx'] as $locale)
{
    $formatter = new IntlDateFormatter(
        $locale,
        IntlDateFormatter::FULL,
        IntlDateFormatter::FULL,
        null,
        null,
        'w'
    );
    
    echo "Locale: $locale, Week number: " . $formatter->format($date) . "<br>\n";
}

Resulted in this output:

Locale: en, Week number: 38
Locale: xx, Week number: 39

But I expected this output instead:

Locale: en, Week number: 38
Locale: xx, Week number: 38

or else for an exception to be thrown when trying to use 'xx'.

This problem happens on all versions of PHP and all operating systems I have tested.

PHP Version

PHP 8.3.0RC2

Operating System

Windows NT 10.0 build 22621 (Windows 11) AMD64

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions