From 668f768a63cf46c6fb55ddd705d016e9fff370b5 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sun, 7 Apr 2013 23:16:03 +0200 Subject: [PATCH] updated date parsing in util and cleaned up webserver --- server.js | 21 ++++----------------- src/js/crypto/util.js | 28 ++++++++++++++++++++++++++++ test/unit/util-test.js | 6 ++++-- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/server.js b/server.js index ceba203..02550ed 100644 --- a/server.js +++ b/server.js @@ -4,30 +4,17 @@ var express = require('express'), fs = require('fs'), - port, app, prot, dev; + port, app, dev; port = (process.argv[2]) ? process.argv[2] : 8585; dev = (process.argv[3] === '--dev'); - -if (dev) { - // development server - console.log(' > Starting in development mode ...'); - prot = 'http'; - app = express(); -} else { - // production server - prot = 'https'; - app = express({ - ca: fs.readFileSync('./ssl/sub.class1.server.ca.pem'), - key: fs.readFileSync('./ssl/ssl.key'), - cert: fs.readFileSync('./ssl/ssl.crt') - }); -} +app = express(); // Server setup app.configure(function() { if (dev) { // serve test files in development mode + console.log(' > Starting in development mode ...'); app.use(express['static'](__dirname + '/test')); } else { @@ -46,4 +33,4 @@ app.configure(function() { // start server app.listen(port); -console.log(' > listening on ' + prot + '://localhost:' + port); \ No newline at end of file +console.log(' > listening on http://localhost:' + port); \ No newline at end of file diff --git a/src/js/crypto/util.js b/src/js/crypto/util.js index f5e029d..cb5018a 100644 --- a/src/js/crypto/util.js +++ b/src/js/crypto/util.js @@ -92,6 +92,34 @@ var Util = function(window, uuid, crypt) { return new Date(parts[0], parts[1] - 1, parts[2], parts[3], parts[4], parts[5]); }; + /** + * Returns a string representation of a date in the format "1900-01-31 18:17:53" + */ + this.formatDate = function(date) { + var year = "" + date.getFullYear(); + var month = "" + (date.getMonth() + 1); + if (month.length == 1) { + month = "0" + month; + } + var day = "" + date.getDate(); + if (day.length == 1) { + day = "0" + day; + } + var hour = "" + date.getHours(); + if (hour.length == 1) { + hour = "0" + hour; + } + var minute = "" + date.getMinutes(); + if (minute.length == 1) { + minute = "0" + minute; + } + var second = "" + date.getSeconds(); + if (second.length == 1) { + second = "0" + second; + } + return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; + }; + /** * Converts a binary String (e.g. from the FileReader Api) to an ArrayBuffer * @param str [String] a binary string with integer values (0..255) per character diff --git a/test/unit/util-test.js b/test/unit/util-test.js index e00ef1c..06e63d7 100644 --- a/test/unit/util-test.js +++ b/test/unit/util-test.js @@ -28,8 +28,10 @@ test("random", 3, function() { test("Parse Date", 1, function() { var util = new app.crypto.Util(window, uuid); - var date = util.parseDate('1900-01-31 18:17:53'); - ok(date, "Date: " + date); + var str = '1900-01-31 18:17:53'; + var date = util.parseDate(str); + var formated = util.formatDate(date); + equal(formated, str, "Date: " + date); }); test("String -> Uint8Array -> String", 3, function() {