Contao 3.4.5 datepicker Date.parse error on german short date
Shows that the datepicker is not able to handle german short date format "d.m.y". Suggests a patch with new date parsers. Resource here is mootools.js by Contao 3.4.5. Try it on firefox as chrome has trouble with loading external JS resources from github.
by Andreas Burg
HTML
<script src="https://rawgit.com/contao/core/3.4.5/assets/mootools/core/1.5.1/mootools.js"></script>
<!--
Shows that the datepicker is not able to handle german short date format "d.m.y". Suggests a patch with new date parsers.
Resource here is mootools.js by Contao 3.4.5. Within this patched mootools.js all default parsers are deleted and some new ones are created.
-->
<pre id="output"></pre>
CSS
.invalid {
color: red;
}
b {
display: block;
margin: .5em 0;
}
JavaScript
// german date format should be date first - d.m.Y, d.m.y
var
output = $('output'),
formatOut = '%Y %d %B',
dates = [
'03.12.2015', // December
'31.12.2015', // December
'12.03.2015', // March
'03.12.15', // December
'31.12.15', // December
'12.03.15' // March
],
date = new Date(),
dateIn = new Element('span.in'),
dateOut = new Element('span.out'),
invalid
;
Date.defineFormat('out', formatOut);
generate = function() {
dates.each(function(item) {
dateIn.set('text', item + '\t=> ');
dateOut.set('text', date.parse(item).format('out') + '\n');
invalid = '';
if(date.get('year') == 1970) {
invalid = 'invalid';
}
dateIn.clone().inject(output);
dateOut.clone().inject(output).addClass(invalid);
});
};
output.appendHTML('<b>Output always should be:\n\tDecember\n\tDecember\n\tMarch</b>');
output.appendHTML('<b>With patched Contao 3.4.5 parsers</b>');
generate();
output.appendHTML('<b>With additional 2 digits year parsers</b>');
// additional parsers - same as above with 2 digits year
Date.defineParsers(
'%y(-%m(-%d( %H:%M(:%S)?( ?%p)?)?)?)?', // 99-12-31, 99-12-31 11:59pm, 99-12-31 23:59:59
'%m(/%d(/%y( %H:%M(:%S)?( ?%p)?)?)?)?', // 12/31/99, 12/31/99 11:59pm, 12/31/99 23:59:59
'%d(.%m(.%y( %H:%M(:%S)?)?)?)?' // 31.12.99, 31.12.99 11:59, 31.12.99 23:59:59
);
generate();