Open jirihelmich opened 8 years ago
Would you mind filing a PR for this? :)
I'm currently trying to find a fix...
+ var designatorMatch = dates[language].meridiem[1].match(this.nonpunctuation);
+ var crazyDesignator = designatorMatch && designatorMatch.length > 1;
+ var crazyDesignatorFound = null;
+ if (crazyDesignator) {
+ _.each(dates[language].meridiem, function(designator, idx) {
+ if (date.toLowerCase().indexOf(designator.toLowerCase()) > -1) {
+ date = date.replace(designator.toLowerCase(), '');
+ date = date.replace(designator.toUpperCase(), '');
+ crazyDesignatorFound = idx;
+ format.parts = _.without(format.parts, 'P', 'p');
+ }
+ });
+ }
- var meridian = Math.max(format.parts.indexOf("P"), format.parts.indexOf("p"))
- if (meridian != -1) {
- if (parts[meridian].toLowerCase() == dates[language].meridiem[1].toLowerCase()) {
+ var meridian = Math.max(format.parts.indexOf("P"), format.parts.indexOf("p"));
+ if (meridian != -1 || crazyDesignatorFound === 1) {
+ if (crazyDesignatorFound === 1 || parts[meridian].toLowerCase() == dates[language].meridiem[1].toLowerCase()) {
date.setTime(date.getTime() + (12 * 60 * 60 * 1000));
}
}
This is my patch so far. If the solution seems OK-ish to you, I can file a PR on the latest version of the lib.
As the Peruvian culture has rather strange designators for Meridian (
a. m.
andp. m.
), the library internals fail to parse manually written datetime:E.g.
25/01/2016 01:00 P. M.
is not parsed as a valid date, as there is no matching part in case of the corresponding patternd/mm/yyyy H:ii P
because the partP
standing for meridian designator is not matched with parts of the date as parts are parsed in a way that instead of last part beingP. M.
it has two parts:P
andM
.That is caused by matching the regex
nonpunctuation
(/[^ -\/:-@\[-
{-~\t\n\rTZ]+/g`).