Permalink
Browse files

Changed how timestamps are handled, now they are always PST

  • Loading branch information...
1 parent c246903 commit b459fe5090ae598751e8da257e0fedab83acc9c0 @zquestz committed Jul 29, 2012
Showing with 29 additions and 23 deletions.
  1. +1 −1 simplechat.html
  2. +28 −22 simplechat.js
View
@@ -37,7 +37,7 @@ <h1 id="title">SimpleChat</h1>
<div id="chat">
{{#each messages}}
<div>
- <span class="sidebar"><span class="time">{{formatted_date}}</span><span class="user">&lt;{{user}}&gt;</span></span>
+ <span class="sidebar"><span class="time">{{formatted_date date}}</span><span class="user">&lt;{{user}}&gt;</span></span>
<span class="msg">{{text}}</span>
<div class='clearfix' />
</div>
View
@@ -3,7 +3,7 @@ Users = new Meteor.Collection("users");
if (Meteor.is_client) {
Template.chat.messages = function () {
- var messages = Messages.find({user: { $exists: true }, text: { $exists: true }, date: { $exists: true}, formatted_date: { $exists: true} }, { sort: {date: 1} });
+ var messages = Messages.find({user: { $exists: true }, text: { $exists: true }, date: { $exists: true} }, { sort: {date: 1} });
var handle = messages.observe({
added: function (message) {
$('#chat').stop();
@@ -21,6 +21,30 @@ if (Meteor.is_client) {
return messages;
};
+ Template.chat.formatted_date = function(date) {
+ var date = new Date(date)
+ date.setHours(date.getHours() - 7);
+
+ var hours = date.getUTCHours(),
+ minutes = date.getUTCMinutes(),
+ suffix = "AM";
+
+ if (hours >= 12) {
+ suffix = "PM";
+ hours = hours - 12;
+ }
+
+ if (hours == 0) {
+ hours = 12;
+ }
+
+ if (minutes < 10) {
+ minutes = "0" + minutes;
+ }
+
+ return (hours + ":" + minutes + " " + suffix);
+ };
+
Template.chat.users = function () {
var users = Users.find({name: { $exists: true }}, { sort: {name: 1} });
return users;
@@ -62,29 +86,11 @@ if (Meteor.is_client) {
Template.chat.events = {
'submit form': function (event) {
var inputbox = $('#input'),
- new_message = inputbox.val().replace(/\n/g, '<br />'),
- date = new Date(),
- hours = date.getHours(),
- minutes = date.getMinutes(),
- suffix = "AM";
-
- if (hours >= 12) {
- suffix = "PM";
- hours = hours - 12;
- }
-
- if (hours == 0) {
- hours = 12;
- }
-
- if (minutes < 10) {
- minutes = "0" + minutes;
- }
-
- var formatted_date = hours + ":" + minutes + " " + suffix;
+ new_message = inputbox.val(),
+ date = new Date();
if (new_message !== '') {
- Messages.insert({user: Session.get("user"), text: new_message, date: date, formatted_date: formatted_date});
+ Messages.insert({user: Session.get("user"), text: new_message, date: date});
}
inputbox.val('');

0 comments on commit b459fe5

Please sign in to comment.