Permalink
Browse files

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

  • Loading branch information...
1 parent 0a083c0 commit 3d6f2a4b6acb2b703712be599cf1be02e92c84ff @sachinr sachinr committed with Dec 30, 2011
Showing with 18 additions and 5 deletions.
  1. +6 −1 public/javascripts/application.coffee
  2. +12 −4 public/javascripts/application.js
@@ -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) ->
@@ -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) {

0 comments on commit 3d6f2a4

Please sign in to comment.