From: Luigi Pinca Date: Mon, 25 Mar 2013 13:18:41 +0000 (+0100) Subject: use the ISO 8601 extended format to store users' join-dates X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=a6c90c2a1811ba839a468dd74801eed26e0eef34;p=binbsis50.git use the ISO 8601 extended format to store users' join-dates --- diff --git a/lib/utils.js b/lib/utils.js index 2c74f35..367e601 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -21,6 +21,24 @@ exports.buildLeaderboards = function(pointsresults, timesresults) { return obj; }; +/** + * Return the string representation of a given date in the 'DD/MM/YYYY' format. + */ + +exports.britishFormat = function(date) { + var day = date.getDate() + , month = date.getMonth() + 1 + , year = date.getFullYear(); + + if (day < 10) { + day = '0'+day; + } + if (month < 10) { + month = '0'+month; + } + return day+'/'+month+'/'+year; +}; + /** * Check whether a given string is a valid email address. */ diff --git a/package.json b/package.json index 1022196..c6aa8f7 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,5 @@ "start": "node app.js" }, "subdomain": "binb", - "version": "0.3.5-12" + "version": "0.3.5-14" } diff --git a/routes/user.js b/routes/user.js index 4e8812b..d0916ae 100644 --- a/routes/user.js +++ b/routes/user.js @@ -251,19 +251,9 @@ exports.createAccount = function(req, res) { , mailkey = 'email:'+req.body.email , salt = crypto.randomBytes(6).toString('base64') , hash = crypto.createHash('sha256').update(salt+req.body.password).digest('hex') - , date = new Date() - , day = date.getDate() - , month = date.getMonth() + 1 - , year = date.getFullYear(); + , date = new Date().toISOString() + , user = new User(req.body.username, req.body.email, salt, hash, date); - if (day < 10) { - day = '0' + day; - } - if (month < 10) { - month = '0' + month; - } - var joindate = day+'/'+month+'/'+year; - var user = new User(req.body.username, req.body.email, salt, hash, joindate); // Add new user in the db db.hmset(userkey, user); db.set(mailkey, userkey); @@ -390,10 +380,11 @@ exports.profile = function(req, res) { if (data === 1) { db.hgetall(key, function(e, obj) { obj.bestguesstime = (obj.bestguesstime/1000).toFixed(1); - obj.worstguesstime = (obj.worstguesstime/1000).toFixed(1); + obj.joindate = utils.britishFormat(new Date(obj.joindate)); if (obj.guessed !== '0') { obj.meanguesstime = ((obj.totguesstime/obj.guessed)/1000).toFixed(1); } + obj.worstguesstime = (obj.worstguesstime/1000).toFixed(1); delete obj.email; delete obj.password; delete obj.salt;