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

In custom date/time format add support for using local date and time sepraters #36752

Open
goyaltushar92 opened this issue Apr 22, 2020 · 8 comments

Comments

@goyaltushar92
Copy link

@goyaltushar92 goyaltushar92 commented Apr 22, 2020

πŸš€ feature request

Relevant Package

This feature request is for @angular/common

Description

According to location date separators varies between
  • "/" – stroke (slash)
  • "." – dots or full stops/points (periods)
  • "-" – hyphens or dashes
  • " " – spaces
    similarly time separator also changes according to location.

Currently, Angular does not provide any way to use localized date and time separators in custom formats. Due to this if a user wants to customize date/time format then he/she can't have location-specific separators.

Describe the solution you'd like

Angular can reserve some format pattern for specifying date separator and time separator. Like
  • D -> date separator
  • T -> time separator

Describe alternatives you've considered

I don't; think above pattern are good enough as `d` & `D` can be confusing and someone may be using `T` in his/her custom format (as T is part of ISO format).

I also thought about

  • ds -> date separator
  • ts -> time separator
    but, Angular is already using s so it can lead to confusion. Maybe we can discuss a right pattern here.
@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 22, 2020

Thanks for the issue.
Can you tell me, is this information available in the CLDR data source that we use for our localisation information? I cant find any information about it.

If this info isn't available then we would not be able to support it.

Generally we are not adding custom format codes to our date/time formatting features.

@goyaltushar92
Copy link
Author

@goyaltushar92 goyaltushar92 commented Apr 27, 2020

I checked in CLDR data, it looks like time separate is available there (and it looks like angular reads it too, I checked gulp script that extracts localization data). However, the date separator is not available. But, a lot of other frameworks (like .net) make the value of date separator avail (I think they also use CLDR data, however not sure, maybe they parsed date format from CLDR to make that value available).

https://www.unicode.org/reports/tr35/tr35-dates.html#dfst-sep

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 27, 2020

When I looked at the .NET framework, I saw a function that you could use to provide your own separator, but I did not see that it was set automatically from the locale. Given that the date separator is not available, I don't think this is something we will implement.

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 27, 2020

You could work around this, if you had the data, by pre-processing the format string using a custom pipe that sits on top of the DatePipe class: https://ng-run.com/edit/IWdEjBMUloVDMMqezxqZ?open=app%2Fapp.component.html

@goyaltushar92
Copy link
Author

@goyaltushar92 goyaltushar92 commented Apr 27, 2020

yes, that would work. But, while I was going through CLDR data I found there are few other formats available in availableFormats tag. If, these extra formats are made available then maybe we do not need this workaround. Actually I am interested in MEd and Hm formats available there. To achieve the same, I was looking for date and time separators.

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 27, 2020

If MEd and Hm are common/standard then we could consider adding those.

@goyaltushar92
Copy link
Author

@goyaltushar92 goyaltushar92 commented Apr 28, 2020

https://www.unicode.org/reports/tr35/tr35-55/tr35-dates.html#availableFormats_appendItems describes what was the purpose of availableFormats and appendItems

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 28, 2020

I tried reading that section of spec that you linked. It is pretty dense stuff, and I struggled to understand how it would be implemented to solve your problem. Could you put together an explanation of what would be involved to support this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.