aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmlrpc.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-04-17 08:44:49 +0200
committerMatěj Cepl <mcepl@redhat.com>2011-06-05 14:44:43 +0200
commit0ccc730b8cf0f66a8e9a15cc07b5b6613fc0e015 (patch)
tree3dece2704b161fce5ef4e963a18aec624a782ee9 /lib/xmlrpc.js
parent4d29c8b4eb1f3e66da8d60fd1f42f3e4c06d2b39 (diff)
downloadbugzilla-triage-0ccc730b8cf0f66a8e9a15cc07b5b6613fc0e015.tar.gz
Auch! Say NO to the copy&paste inheritance!
* leadingZero made into special function exported from xmlrpc module (it is now able to accept either number of string as its parameter) * added tests for leadingZero
Diffstat (limited to 'lib/xmlrpc.js')
-rw-r--r--lib/xmlrpc.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/xmlrpc.js b/lib/xmlrpc.js
index 6576f31..e038c4e 100644
--- a/lib/xmlrpc.js
+++ b/lib/xmlrpc.js
@@ -26,15 +26,27 @@
* not an instance of SAME Array.
*/
-var dateToISO8601 = exports.dateToISO8601 = function dateToISO8601(date) {
- function leadingZero(n) {
- // pads a single number with a leading zero. Heh.
- if (n.length === 1) {
- n = "0" + n;
- }
+/**
+ * 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();