The default JavaScript `new Date(string)` code is not ISO8601 compliant
The XML-RPC spec states that dateTimes must be encoded in ISO8601 format. Producing ISO dates in JavaScript is easy enough, with Date.prototype.toISOString() into a native JavaScript date. Parsing ISO dates is also easy, new Date(string). However, both of these have problems.
The spec says that dateTimes should not have a timezone set. Working out timezones is not part of the spec. However, the default Date.prototype.toISOString() implementation has a timezone of 'Z' (Zulu, same as UTC). This is against spec.
Additionally, the default new Date(string) can not parse ISO8601 shorthand dates, as mentioned in the spec, and clarified in this document.
This means that this library does not yet conform to the XML-RPC spec. However, everything that I have seen that uses XML-RPC does not have any issues with these restrictions. If any one comes across a server where this is an issue, leave a comment here and I will look in to fixing it.
I meet this issue too.
I add some code, like it work fine.
var year = text.slice(0,4);
var month = text.slice(4,6);
var day = text.slice(6,8);
var hour = text.slice(9,11);
var minute = text.slice(12,14);
var sec = text.slice(15,17);
return new Date(year,month,day,hour,minute,sec);
Hi!
I've run into this problem as well. The Django XMLRPC server uses the shorthand date so instead of "2013-05-13T11:33:12" it sends "20130513T11:33:12". For now, I have modified the date decode method to do this:
xmlrpc.makeType('dateTime.iso8601', true, function(d) {
return [
d.getUTCFullYear(), '-', _pad(d.getUTCMonth()+1), '-',
_pad(d.getUTCDate()), 'T', _pad(d.getUTCHours()), ':',
_pad(d.getUTCMinutes()), ':', _pad(d.getUTCSeconds()), 'Z'
].join('');
}, function(text, node) {
// ISO 8601 dates can be either YYYY-MM-DD _or_
// YYYYMMDD. Added check for the latter case, since it's
// not handled by FireFox's Date constructor. jfuller
// 2013-05-13
if (!/-/.test(text)) {
text = text.replace(/(\d{4})(\d{2})(\d{2})(.+)/, "$1-$2-$3$4");
}
return new Date(text);
});
There's probably a nicer way to handle it, but this is working for me.
Thanks very much for the library!
Thanks for the patch! If you put this in a pull request, I will merge it in. While it is not a complete implementation as you said, it covers off one important missing case, which is better than the current code!