Nicer timestamps with momentjs

This dependency may be a little heavy for our current use case, but we can
roll with it for now and find something slimmer if it turns out yagni.

Closes #77
Closes #40
This commit is contained in:
lilia 2014-11-11 00:35:18 -08:00
parent d537d6a91f
commit 28290477f4
9 changed files with 5749 additions and 30 deletions

View file

@ -22,7 +22,7 @@ var Whisper = Whisper || {};
this.$el.html(
Mustache.render(this.template, {
message: this.model.get('body'),
date: this.formatTimestamp(),
timestamp: moment(this.model.get('timestamp')).fromNow(),
attachments: this.model.get('attachments'),
bubble_class: this.model.get('type') === 'outgoing' ? 'sent' : 'incoming',
sender: this.model.thread().get('type') === 'group' ? this.model.get('person') : ''
@ -30,21 +30,8 @@ var Whisper = Whisper || {};
);
return this;
},
formatTimestamp: function() {
var timestamp = this.model.get('timestamp');
var now = new Date().getTime();
var date = new Date();
date.setTime(timestamp*1000);
if (now - timestamp > 60*60*24*7) {
return date.toLocaleDateString('en-US',{month: 'short', day: 'numeric'});
}
if (now - timestamp > 60*60*24) {
return date.toLocaleDateString('en-US',{weekday: 'short'});
}
return date.toTimeString();
}
});
})();