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

[Bug] Datepicker showed date is not the same format as written #5700

Closed
raugaral opened this issue Jul 12, 2017 · 5 comments
Closed

[Bug] Datepicker showed date is not the same format as written #5700

raugaral opened this issue Jul 12, 2017 · 5 comments

Comments

@raugaral
Copy link

raugaral commented Jul 12, 2017

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Select a date using the calendar, show date format dd/mm/yyyy.
Written date using format dd/mm/yyyy should be accepted.

What is the current behavior?

Written date using format dd/mm/yyyy is not accepted, the only valid format is mm/dd/yyy.

What are the steps to reproduce?

At the docs website.
image
Select a date in the calendar, the format is dd/mm/yyyy. That is correct.
image

But, if i write a date manually, the date is not in accepted as valid and the ngModel is empty.
image

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 4.2.6
@angular/material@2.0.0-beta.8
typescript@2.3.4
OS: Ubuntu 17.04
Google Chrome 59.0.3071.115 (Build oficial) (64 bits)

Is there anything else we should know?

I'm using the locale id de-DE in my app module
{ provide: LOCALE_ID, useValue: "de-DE" }

@raugaral raugaral changed the title Datepicker showed date is not the same format as written [Bug] Datepicker showed date is not the same format as written Jul 12, 2017
@julianobrasil
Copy link
Contributor

julianobrasil commented Jul 12, 2017

This is not a bug. You must build a custom date adapter if your locale date format is different from MM/dd/yyyy.

Take a look at this plunk for brazilian portuguese (same date format as you want): https://plnkr.co/edit/jPZWMB?p=preview

Also it's explained in more details over here.

@jelbourn
Copy link
Member

What @julianobrasil said

@raugaral
Copy link
Author

That doesn't help. It's not posible override a private function.

Class 'CustomDateAdapter' incorrectly extends base class 'NativeDateAdapter'. Types have separate declarations of a private property '_createDateWithOverflow'.

@julianobrasil
Copy link
Contributor

julianobrasil commented Jul 13, 2017

@raugaral, the _createDateWithOverflow isn't overriding anything. It's a function of the CustomDateAdapter class only. I just copied that of the NativeDateAdapter because I liked the organzation of the functions over there (in fact it's so tiny that you can put all it's logic inside the createDate, which is, in fact, the one that must be overriden).

When you extends a class (or implements an interface), it's not forbbiden to create your own private/public functions. You're not restricted to override/implement the functions of the superclass/interface.

But I think the real confusion here is about what is being done. You don't have to extend NativeDateAdapter to customize the datepicker's formats. What you must do is implement the DateAdapter interface. You can build your own implementation from scratch if you really want to (and it's not difficult - take a look at #675 (comment) from @arlowhite). But I think that, in this specific case, it's easier to extend one that is already working fine and adapt it by including some things and overriding others just to make it work the way you want it to.

I'll modify the plunk's date adapter to avoid this confusion in the future.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants