ecma402 icon indicating copy to clipboard operation
ecma402 copied to clipboard

Get the formats for a given locale

Open dgreene1 opened this issue 2 years ago • 2 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?

dgreene1 avatar Jul 21 '23 17:07 dgreene1

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 avatar Jul 25 '23 19:07 FrankYFTang

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

dgreene1 avatar Jul 25 '23 21:07 dgreene1