Skip to content

Access to parsed DateFormat pattern data #665

@NilsAtGoogle

Description

@NilsAtGoogle

Is your feature request related to a problem? Please describe.

We are building an AngularDart implementation of the Material Datepicker for web which includes a free text field for users to type in a date:

https://m2.material.io/components/date-pickers#anatomy

The component needs to work for any locale and we are using DateFormat#parseLoose to handle the text, which works well enough and is certainly better than reinventing the parsing wheel.

The spec also requires hint text that guides the correct use for free-text entry; for example which would be "MM/DD/YYYY" for en_US and "DD/MM/YYYY" for en_UK. Since text is parsed using the date format's pattern, we'd like to be able to reliably produce the correct hint text based on that same pattern.

Describe the solution you'd like

Something like the test-only / internal-only parsePattern would mostly meet our needs but with public types for inspecting which kind of pattern token something is (literal vs quoted vs pattern). Using this we could build out the correct hint text.

Describe alternatives you've considered

Since we're using dart/i18n this felt like the natural fit. We could rewrite a simpler parser since we're only dealing with DateFormat#yMd but I'm worried about divergent code between DateFormat and a custom solution

Additional context
https://m2.material.io/components/date-pickers#anatomy
https://github.com/dart-lang/i18n/blob/main/pkgs/intl/lib/src/intl/date_format.dart#L915

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions