Christophe
Christophe

Reputation: 28114

Reference for dayPeriod in Intl.DateTimeFormat

What is dayPeriod in JavaScript Intl.DateTimeFormat, and what values can in take in the en-US locale? Also, does it have broad support in recent browsers?

I can't seem to find any reference.

Upvotes: 1

Views: 944

Answers (1)

Christophe
Christophe

Reputation: 28114

The only reference I could find was this Unicode Common Locale Data Repository (CLDR) table, and the associated downloads page. I am not sure how browsers implement it.

Fun fact, the number of day periods varies across locales. English has 4 (morning, afternoon, evening, night), while for example German has 6.

An excerpt from the xml file:

<dayPeriodRules locales="root">
    <dayPeriodRule type="am" from="00:00" before="12:00"/>  <!-- AM -->
    <dayPeriodRule type="pm" from="12:00" before="24:00"/>  <!-- PM -->
</dayPeriodRules>
<dayPeriodRules locales="en">
    <dayPeriodRule type="midnight" at="00:00"/> <!-- midnight -->
    <dayPeriodRule type="noon" at="12:00"/> <!-- noon -->
    <dayPeriodRule type="morning1" from="06:00" before="12:00"/>    <!-- morning -->
    <dayPeriodRule type="afternoon1" from="12:00" before="18:00"/>  <!-- afternoon -->
    <dayPeriodRule type="evening1" from="18:00" before="21:00"/>    <!-- evening -->
    <dayPeriodRule type="night1" from="21:00" before="06:00"/>  <!-- night -->
</dayPeriodRules>

Upvotes: 1

Related Questions