-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Date parsing problem when Day's format code is defined before a literal d ('d') #5620
Comments
This appears to be a legitimate bug. |
I did some investigation into this a week or so ago - this will be a difficult bug to fix. How we construct the formatter is wrong for going from date with format to formatted date. I could not think of a way to do this right when I took a look at this since we need to create a more robust parsing mechanism than what we have available. This will require some dedicated time to fix this, and I will look into this at some point, but if this is of any urgency for anyone, I highly recommend trying to dedicate resources to fix this right, as I cannot guarantee how fast this will get fixed by me. |
After typing this out, I have a mental solution sketched out if someone wants to implement. In the dateparser The formatting of the string will then use this new construction, which will then slice off the string from the original format string each time and apply the appropriate measure (if literal, just append to new format string, if regex, then apply regex replacing). This approach should fix this bug correctly, instead of the current hacky implementation. |
I created a PEG.js expression from uibDateparser's format codes (to test it, paste the code at http://pegjs.org/online). It generates a matrix for the input format. I'm still trying to reduce the result to an array, but I could not figure it out how yet. https://gist.github.com/flaviocysne/eb2b8197d00dc1adbaa8ceeb481dfa30 |
As explained at Array.prototype.reduce() - JavaScript | MDN, the result of the PEG.js parser created (see my previous comment) could be reduced to an ordinary array using Array.prototype.concat() function. Extracted from the mentioned link:
|
@wesleycho I updated the code on gist and added the Javascript created by PEG.js online tool. I also added more examples on http://plnkr.co/edit/ZoWfeb?p=preview (as mentioned in Issue #5665). I'll try to merge Could give me some advice on a better way to merge those two codes or, if the answer would be to not merge them, how to start porting PEG.js code to better feet uibDateParser code rules? I'm not an experienced Javascript developer, although I know some aspects of the language. Best regards. |
Bug description:
When using a format where Day's format code is defined before a literal d, the parser is replacing the very last d (format code or literal) with all parsed content.
Ex.:
format string: d 'd'
parsing result: d '10'
format string: 'd' d
parsing result: d 10
Link to minimally-working plunker that reproduces the issue:
http://plnkr.co/edit/ZoWfeb?p=preview
Version of Angular, UIBS, and Bootstrap
Angular: 1.5.0
UIBS: 1.2.4
Bootstrap: 3.3.6
The text was updated successfully, but these errors were encountered: