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

Get the formats for a given locale #809

Open
dgreene1 opened this issue Jul 21, 2023 · 2 comments
Open

Get the formats for a given locale #809

dgreene1 opened this issue Jul 21, 2023 · 2 comments
Labels
c: datetime Component: dates, times, timezones Proposal Larger change requiring a proposal s: comment Status: more info is needed to move forward

Comments

@dgreene1
Copy link

dgreene1 commented Jul 21, 2023

I'd like to propose a way to get the date formats for a given locale so that when we're parsing and formatting a string into a date, we can provide a label to the user that explains the format that we will accept.

So imagine that we have an date input. Here's some terrible ASCII art of the label and the input:

Preferred Pickup Time (MM/dd/yyyy, hh:mm:ss a)
[                              ]

So we can use Intl to format what they type in or what they select from the calendar dropdown:

new Intl.DateTimeFormat('en-US', { dateStyle: 'short', timeStyle: 'long'}).format(new Date())
'7/21/23, 1:21:35 PM EDT'

But... we have no browser API for which we can get that format that we want to put in the label. And without that, there's no way to communicate to the user what we expect.

Unless someone is aware of a way to get the format from Intl?

@FrankYFTang
Copy link
Contributor

Here is the problem of providing such feature

  1. users won't be able to understand what is "MM/dd/yyyy, hh:mm:ss a" (what is "a" ? for example)
  2. user won't be able to understand the differences between d and dd m and mm h, H, hh, HH, k, kk, K, KK, j, JJ etc.

@FrankYFTang FrankYFTang transferred this issue from tc39/proposal-intl-locale-info Jul 25, 2023
@sffc sffc added s: comment Status: more info is needed to move forward c: datetime Component: dates, times, timezones Proposal Larger change requiring a proposal labels Jul 25, 2023
@dgreene1
Copy link
Author

@FrankYFTang I understand that, but if code has the format, then it can map those to a readable format.

KendoUI does this so the placeholder says:
month/day/year at hour:minute:seconds AM

But without a way to get the format from Intl, we have no choice but to not use Globelize and to therefore use the CLDR data directly.

@FrankYFTang FrankYFTang added this to Other Issues in ECMA-402 Meeting Topics Jul 31, 2023
@sffc sffc moved this from Other Issues to Previously Discussed in ECMA-402 Meeting Topics Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: datetime Component: dates, times, timezones Proposal Larger change requiring a proposal s: comment Status: more info is needed to move forward
Projects
ECMA-402 Meeting Topics
Previously Discussed
Development

No branches or pull requests

3 participants