diff options
Diffstat (limited to 'lib/xmlrpc.js')
-rw-r--r-- | lib/xmlrpc.js | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/lib/xmlrpc.js b/lib/xmlrpc.js index 8b71f32..e038c4e 100644 --- a/lib/xmlrpc.js +++ b/lib/xmlrpc.js @@ -26,6 +26,41 @@ * not an instance of SAME Array. */ +/** + * pads a single number with a leading zero. Heh. + * + * @param n String or Number + * @return String with leading zero added if necessary + * + * If the real parameter is not numerical, it is just returned as it is. + */ +var leadingZero = exports.leadingZero = function leadingZero(n) { + if (isNaN(Number(n))) { + return n; + }; + + var s = "0" + n; + if (s.length > 2) { + s = s.slice(1); + } + return s; +}; + +var dateToISO8601 = exports.dateToISO8601 = function dateToISO8601(date) { + // wow I hate working with the Date object + console.log("date = " + date); + var year = date.getYear(); + var month = leadingZero(date.getMonth()); + var day = leadingZero(date.getDate()); + var time = leadingZero(date.getHours()) + + ":" + leadingZero(date.getMinutes()) + + ":" + leadingZero(date.getSeconds()); + + var converted = year + month + day + "T" + time; + console.log("date = " + converted); + return converted; +}; + var XMLRPCMessage = exports.XMLRPCMessage = function XMLRPCMessage(methodname) { this.method = methodname || "system.listMethods"; this.params = []; @@ -115,26 +150,6 @@ XMLRPCMessage.prototype.doBooleanXML = function (data) { }; XMLRPCMessage.prototype.doDateXML = function (data) { - function leadingZero(n) { - // pads a single number with a leading zero. Heh. - if (n.length === 1) { - n = "0" + n; - } - return n; - } - function dateToISO8601(date) { - // wow I hate working with the Date object - var year = date.getYear(); - var month = this.leadingZero(date.getMonth()); - var day = this.leadingZero(date.getDate()); - var time = this.leadingZero(date.getHours()) + - ":" + this.leadingZero(date.getMinutes()) + - ":" + this.leadingZero(date.getSeconds()); - - var converted = year + month + day + "T" + time; - return converted; - } - var xml = "<dateTime.iso8601>"; xml += dateToISO8601(data); xml += "</dateTime.iso8601>"; |