]> git.example.dev Git - binbsis50.git/commitdiff
use the ISO 8601 extended format to store users' join-dates
authorLuigi Pinca <luigipinca@gmail.com>
Mon, 25 Mar 2013 13:18:41 +0000 (14:18 +0100)
committerLuigi Pinca <luigipinca@gmail.com>
Mon, 25 Mar 2013 13:18:41 +0000 (14:18 +0100)
lib/utils.js
package.json
routes/user.js

index 2c74f35b0a54570486e3329b602d19f32614120e..367e60115b993233c387010dc56e7ca5a8c2d314 100644 (file)
@@ -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.
  */
index 1022196e933b78c009d208c9174ffe616137b066..c6aa8f7c15bdd817822016dee64969ac7e4af2ec 100644 (file)
@@ -24,5 +24,5 @@
     "start": "node app.js"
   },
   "subdomain": "binb",
-  "version": "0.3.5-12"
+  "version": "0.3.5-14"
 }
index 4e8812b3776f94678a606765267596a6fe0c3b19..d0916ae6fc4cd891dc0efb81ad2185911db38d6f 100644 (file)
@@ -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;