tc39 / ecma402

Status, process, and documents for ECMA 402

Home Page:https://tc39.es/ecma402/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get the formats for a given locale

dgreene1 opened this issue · comments

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?

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 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.