Skip to content

Conversation

dipikabh
Copy link
Contributor

@dipikabh dipikabh commented Oct 6, 2025

Description

Addressing the issue raised in https://github.com/orgs/mdn/discussions/836.

This PR adds a new example to toLocaleString() to demo how to control single- vs double-digits in the day/month output.

For the existing example, I noticed slightly different outputs in my time zone, so I've added comments to clarify why that might happen.

@dipikabh dipikabh requested a review from a team as a code owner October 6, 2025 22:08
@dipikabh dipikabh requested review from Josh-Cena and removed request for a team October 6, 2025 22:08
@github-actions github-actions bot added Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed labels Oct 6, 2025
…alestring/index.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

github-actions bot commented Oct 6, 2025

Preview URLs

(comment last updated: 2025-10-08 17:43:40)

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toLocaleString page is intentionally thin because substantial documentation about the options should go into Intl.DateTimeFormat(). Could you move it there?

@dipikabh
Copy link
Contributor Author

dipikabh commented Oct 8, 2025

I've removed the example I had added previously. Instead I've tweaked an existing example to show results with single-digit day and month. That covers the case raised in the linked discussion.
I've also added two instances to mention/hint at the use of 2-digit.

Comment on lines -72 to -73
// toLocaleString() without arguments depends on the
// implementation, the default locale, and the default time zone
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seemed like a repeat of the prose before the code.
I've removed it and reconciled the text with prose.

@dipikabh dipikabh requested a review from Josh-Cena October 8, 2025 17:46

- `options` {{optional_inline}}
- : An object adjusting the output format. Corresponds to the [`options`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options) parameter of the `Intl.DateTimeFormat()` constructor. If `weekday`, `year`, `month`, `day`, `dayPeriod`, `hour`, `minute`, `second`, and `fractionalSecondDigits` are all undefined, then `year`, `month`, `day`, `hour`, `minute`, `second` will be set to `"numeric"`.
- : An object adjusting the output format. Corresponds to the [`options`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options) parameter of the `Intl.DateTimeFormat()` constructor. If `weekday`, `year`, `month`, `day`, `dayPeriod`, `hour`, `minute`, `second`, and `fractionalSecondDigits` are all undefined, then `year`, `month`, `day`, `hour`, `minute`, `second` will be set to `"numeric"`. To show leading zeros, use `"2-digit"` for the relevant field.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't think this should be documented on this page because it opens an bottomless hole about what kind of options should be documented on this page. The existing sentence about "If weekday, year, month, day, dayPeriod, hour, minute, second, and fractionalSecondDigits are all undefined, then year, month, day, hour, minute, second will be set to "numeric"." is because this behavior is specific to toLocaleString. All behaviors shared by Intl.DateTimeFormat and toLocaleString should be documented in the former.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants