Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

DateParser fails when locale changes #4415

Closed
tobigun opened this issue Sep 14, 2015 · 4 comments
Closed

DateParser fails when locale changes #4415

tobigun opened this issue Sep 14, 2015 · 4 comments

Comments

@tobigun
Copy link
Contributor

tobigun commented Sep 14, 2015

The dateParser (ui.bootstrap.dateparser) caches previosuly used parsers in "this.parsers". A new parser is only created, if no parser exists for the current date format.

This is a problem if two locales use the same date format and the dateParser was previously used with another language (e.g. with the DatePicker). The parser for the previous locale (with wrong month names, ...) is used in this case instead of creating a new one.

In this case for example the datepicker will not be able to select a different date, as it cannot parse the date in the input field (as e.g. the month names of the current language are different than those of the previous language).

A workaround is to reset dateParser.parsers manually whenever the locale changes:

dateParser.parsers = {}
@tobigun
Copy link
Contributor Author

tobigun commented Sep 14, 2015

Seems as if also formatCodeToRegex must be set according to the new locale, as the regex is set fixed to the locale that was active when the dateParser service was started.

@almeidaalex
Copy link

Hello, I don't know if is the same issue, but since I've changed version from 0.12.0 to 0.13.5 and got problems
For example, my date model has value "2015-12-21T20:59:00" and I use dateFormat as "yyyy/MM/dd HH:mm" and the result was 2014/12/21 20:59.

However now I get have invalid model state, because when it tries to parse dateFormat ( var date = dateParser.parse(value, dateFormat);), returns undefined

Is it the same issue?

@tobigun
Copy link
Contributor Author

tobigun commented Sep 19, 2015

@almeidaalex: as you did not change the locale, it is probably not related to this issue.

I am not a member of the bootstrap dev-team. But from what I saw, older versions of the datepicker had a workaround to use "new Date(date)" to parse the date. This is gone now. So as "2015-12-21T20:59:00" does not match "yyyy/MM/dd HH:mm" (because of '/' vs '-') the dateparser will fail. In previous versions "new Date("2015-12-21T20:59:00")" was called which might have been able to parse it. Now it fails.

I think you just had luck that it worked and it was not the expected behavior.

As you did not use the datepiecker but dateparser directly, the above might not be the reason.
Open a new issue report if you think that this must be fixed. A bootstrap dev should comment on this.

@tobigun
Copy link
Contributor Author

tobigun commented Sep 19, 2015

The issue is fixed with the now merged pull-request #4425.

@tobigun tobigun closed this as completed Sep 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants