Closed anttileppa closed 7 years ago
Workaround for this is to replace SimpleDateFormat quotes with square brackets before passing the formatString into formatWithJDF method.
e.g.
var end = false;
var fixed = formatString.replace(/\'/g, function(match) {
return (end = !end) ? '[' : ']';
});
hey @anttileppa - thanks a lot for raising this issue and sorry for the long delay on answering your question/issue. if you have already an existing solution to the problem I'd ask you to open a PR so that we can include your fix into our next release - this would be awesome :+1:
the workaround doesn't work for the following pattern
yyyy-MM-dd[T]HH:mm:ss.SSS[Z]
the 'Z' is translated to ZZ
I can't see any quotes in the pattern you posted @gerpres ? The workaround @anttileppa posted was for "escaping" quotes 😃
sorry for that :-)
the pattern:
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
doesn't work. neither with '' nor with []
the Z inside the quotation is always replaced by ZZ
ah, I see! thank you - I'll take a look at it and see what I can come up with in order to make the string escaping work 👍
have a look at...
moment.fn.toMomentFormatString = function (formatString) { if (!javaDateFormats[formatString]) {
var mapped = "";
var regexp = /[^']+|('[^']*')/g;
while((part = regexp.exec(formatString))) {
part = part[0];
if(part.match(/'.?'/)) {
mapped+="["+part.substring(1,part.length-1)+"]";
} else {
mapped+=translateFormat(part, javaFormatMapping)
}
}
javaDateFormats[formatString] = mapped
}
return javaDateFormats[formatString];
};
closing due to the merge of PR #19 🥇
Quoted strings are interpret incorrectly.
SimpleDateFormat:
prints out _14. of Feb_ when:
prints _14.' of 'Feb_