1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00

updated date parsing in util and cleaned up webserver

This commit is contained in:
Tankred Hase 2013-04-07 23:16:03 +02:00
parent 2480ac0036
commit 668f768a63
3 changed files with 36 additions and 19 deletions

View File

@ -4,30 +4,17 @@
var express = require('express'), var express = require('express'),
fs = require('fs'), fs = require('fs'),
port, app, prot, dev; port, app, dev;
port = (process.argv[2]) ? process.argv[2] : 8585; port = (process.argv[2]) ? process.argv[2] : 8585;
dev = (process.argv[3] === '--dev'); dev = (process.argv[3] === '--dev');
if (dev) {
// development server
console.log(' > Starting in development mode ...');
prot = 'http';
app = express(); 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')
});
}
// Server setup // Server setup
app.configure(function() { app.configure(function() {
if (dev) { if (dev) {
// serve test files in development mode // serve test files in development mode
console.log(' > Starting in development mode ...');
app.use(express['static'](__dirname + '/test')); app.use(express['static'](__dirname + '/test'));
} else { } else {
@ -46,4 +33,4 @@ app.configure(function() {
// start server // start server
app.listen(port); app.listen(port);
console.log(' > listening on ' + prot + '://localhost:' + port); console.log(' > listening on http://localhost:' + port);

View File

@ -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]); 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 * 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 * @param str [String] a binary string with integer values (0..255) per character

View File

@ -28,8 +28,10 @@ test("random", 3, function() {
test("Parse Date", 1, function() { test("Parse Date", 1, function() {
var util = new app.crypto.Util(window, uuid); var util = new app.crypto.Util(window, uuid);
var date = util.parseDate('1900-01-31 18:17:53'); var str = '1900-01-31 18:17:53';
ok(date, "Date: " + date); var date = util.parseDate(str);
var formated = util.formatDate(date);
equal(formated, str, "Date: " + date);
}); });
test("String -> Uint8Array -> String", 3, function() { test("String -> Uint8Array -> String", 3, function() {