-
Notifications
You must be signed in to change notification settings - Fork 22.9k
Add single-digit example to toLocaleString() #41410
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
base: main
Are you sure you want to change the base?
Conversation
files/en-us/web/javascript/reference/global_objects/date/tolocalestring/index.md
Outdated
Show resolved
Hide resolved
…alestring/index.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Preview URLs (comment last updated: 2025-10-08 17:43:40) |
There was a problem hiding this 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?
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. |
// toLocaleString() without arguments depends on the | ||
// implementation, the default locale, and the default time zone |
There was a problem hiding this comment.
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.
|
||
- `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. |
There was a problem hiding this comment.
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.
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.