[fixes #24] Javascript adjusts timestamp according to locale's timezone

This commit is contained in:
Sachin Ranchod 2011-12-30 10:29:52 +02:00 committed by Samuel Cochran
parent 0a083c0300
commit 3d6f2a4b6a
2 changed files with 18 additions and 5 deletions

View File

@ -57,8 +57,13 @@ class MailCatcher
if match = @parseDateRegexp.exec(date)
new Date match[1], match[2] - 1, match[3], match[4], match[5], match[6], 0
offsetTimeZone: (date) ->
offset = Date.now().getTimezoneOffset()*60000 #convert timezone difference to milliseconds
date.setTime(date.getTime() - offset)
date
formatDate: (date) ->
date &&= @parseDate(date) if typeof(date) == "string"
date &&= @offsetTimeZone(@parseDate(date)) if typeof(date) == "string"
date &&= date.toString("dddd, d MMM yyyy h:mm:ss tt")
haveMessage: (message) ->

View File

@ -79,8 +79,17 @@
}
};
MailCatcher.prototype.offsetTimeZone = function(date) {
var offset;
offset = Date.now().getTimezoneOffset() * 60000;
date.setTime(date.getTime() - offset);
return date;
};
MailCatcher.prototype.formatDate = function(date) {
if (typeof date === "string") date && (date = this.parseDate(date));
if (typeof date === "string") {
date && (date = this.offsetTimeZone(this.parseDate(date)));
}
return date && (date = date.toString("dddd, d MMM yyyy h:mm:ss tt"));
};
@ -165,7 +174,6 @@
return $form = $iframe.find('form').submit(function(e) {
e.preventDefault();
$(this).find('input[type="submit"]').attr('disabled', 'disabled').end().find('.loading').show();
console.log($('#message iframe').contents().find('body'));
return $('#message iframe').contents().find('body').xslt("/messages/" + id + "/analysis.xml", "/stylesheets/analysis.xsl");
});
}
@ -189,8 +197,8 @@
};
MailCatcher.prototype.subscribeWebSocket = function() {
var secure;
var _this = this;
var secure,
_this = this;
secure = window.location.scheme === 'https';
this.websocket = new WebSocket("" + (secure ? 'wss' : 'ws') + "://" + window.location.host + "/messages");
return this.websocket.onmessage = function(event) {