Skip to content

Commit

Permalink
[fixes sj26#24] Javascript adjusts timestamp according to locale's ti…
Browse files Browse the repository at this point in the history
…mezone
  • Loading branch information
sachinr authored and sj26 committed Jan 2, 2012
1 parent 0a083c0 commit 3d6f2a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion public/javascripts/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
16 changes: 12 additions & 4 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
};

Expand Down Expand Up @@ -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");
});
}
Expand All @@ -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) {
Expand Down

0 comments on commit 3d6f2a4

Please sign in to comment.