8000 Angular deprecates `getLocaleDayNames` without providing a compatible alternative in `Intl.DateTimeFormat` · Issue #57193 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
Angular deprecates getLocaleDayNames without providing a compatible alternative in Intl.DateTimeFormat #57193
@ptu14

Description

@ptu14

Which @angular/* package(s) are the source of the bug?

localize

Is this a regression?

No

Description

In Angular 18, the getLocaleDayNames function has been deprecated in favor of using the Intl API for internationalization. This change is intended to make the framework lighter by relying on built-in browser capabilities. However, I've encountered an issue where Intl.DateTimeFormat does not provide equivalent short day names as Angular's getLocaleDayNames.

Using Angular:

import { getLocaleDayNames, FormStyle, TranslationWidth } from '@angular/common';

const angularDayNames = getLocaleDayNames('en-US', FormStyle.Standalone, TranslationWidth.Short);
console.log(angularDayNames); // ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]

Using Intl:

const intlFormatter = new Intl.DateTimeFormat('en-US', { weekday: 'short' });
const intlDayNames = [];
for (let i = 0; i < 7; i+=1) {
  const date = new Date(Date.UTC(2021, 0, i + 3)); // 3th January 2021 is a Sunday
  intlDayNames.push(intlFormatter.format(date));
}
console.log(intlDayNames); // ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]

In my native language Polish situation is worse, in Intl for Sunday get e.g. "niedz." (small letter, dot) instead of Angular, 3 letters "nie".

Where Did This Come From?

In the ECMAScript Internationalization API (ecma402) specification, there is a note:

It is recommended that implementations use the locale and calendar dependent strings provided by the Common Locale Data Repository (available at https://cldr.unicode.org/), and use CLDR "abbreviated" strings for DateTimeFormat "short" strings, and CLDR "wide" strings for DateTimeFormat "long" strings.

This explains why Intl.DateTimeFormat uses the "abbreviated" format for "short" strings. The ICU library, which Intl relies on, follows these guidelines. You can check these values in the ICU data files, such as this one for English.
Unfortunately, there is no way to get the "Short" values from Intl as its "short" always returns "abbreviated".

What I Expect

I doubt that ECMA or ICU will change their behavior regarding these formats. Therefore, I would like Angular to provide a solution that is compatible with the old behavior.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular Version: 18.0.6

Anything else?

Adding a weekdaysICU option to Intl.DateTimeFormat would provide a much-needed compatibility layer for developers transitioning from Angular's getLocaleDayNames to the Intl API, ensuring that day names are formatted as expected without requiring additional libraries or workarounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: i18nIssues related to localization and internationalization

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0