Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing text and the same code output #37609

Open
antracer opened this issue Jan 11, 2025 · 2 comments
Open

Missing text and the same code output #37609

antracer opened this issue Jan 11, 2025 · 2 comments
Labels
Content:JS JavaScript docs

Comments

@antracer
Copy link

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts

What specific section or headline is this issue about?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts#named_years_and_mixed_calendars

What information was incorrect, unhelpful, or incomplete?

"Setting an entry in the bag for year (with any value) will yield both the and the yearName Gregorian relatedYear:"

Also the same output of 2 code blocks below the text:

// return value
[
  { type: "relatedYear", value: "2012" },
  { type: "literal", value: "年" },
  { type: "month", value: "十一月" },
  { type: "day", value: "4" },
];

What did you expect to see?

Maybe "Setting an entry in the bag for year (with any value) will yield both the yearName and the Gregorian relatedYear:"

Then, for the first code block:

// return value
[
+ { type: "yearName", value: "zh-u-ca-chinese" },
  { type: "relatedYear", value: "2012" },
  { type: "literal", value: "年" },
  { type: "month", value: "十一月" },
  { type: "day", value: "4" },
];

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

MDN metadata

Page report details
@antracer antracer added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Jan 11, 2025
@github-actions github-actions bot added the Content:JS JavaScript docs label Jan 11, 2025
@Josh-Cena
Copy link
Member

Good spot of the typo. However, { year: "numeric", month: "numeric", day: "numeric" } will not yield the yearName entry, because it's not a supported combination for the Chinese calendar. You need to set { year: "numeric" } alone to be able to see it.

@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Jan 11, 2025
@SurajKharkwal
Copy link
Contributor

SurajKharkwal commented Jan 12, 2025

Hi @antracer , @Josh-Cena

I can fix this issue, but I need clarification on the exact desired output. Here’s what I suggest for the desired result:

[
  { type: "yearName", value: "zh-u-ca-chinese" },   // Extra
  { type: "relatedYear", value: "2012" },
  { type: "literal", value: "年" },
  { type: "month", value: "十一月" },
  { type: "day", value: "4" }
]

To achieve this, you’ll need to adjust the opts options as follows:

const opts = { year: "numeric", month: "long", day: "numeric" };

This configuration sets the month to "long", which ensures that the month name is correctly returned in the desired format (e.g., "十一月" for November). You may want to update the documentation to reflect this change, as the current statement:

"Setting an entry in the bag for year (with any value) will yield both the yearName and the relatedYear (Gregorian year)"

is not accurate in this context. This statement needs correction because it doesn't account for the fact that setting the month and day alongside the year can result in different formatting outcomes, as shown in the example.

Also, if you want to follow the approach that @Josh-Cena specified, the correct opt settings would be:

const opts = { year: "numeric" };

With this, the output would look like this:

[
  { type: 'relatedYear', value: '2012' },
  { type: 'yearName', value: '壬辰' },  // Example of the year name based on the sexagenary cycle
  { type: 'literal', value: '年' }
]

Let me know if this matches your expectations, and what you desire then I’ll proceed with the final fixes accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs
Projects
None yet
Development

No branches or pull requests

3 participants