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:
parent
d537d6a91f
commit
28290477f4
9 changed files with 5749 additions and 30 deletions
2857
js/components.js
2857
js/components.js
File diff suppressed because it is too large
Load diff
|
@ -36,24 +36,11 @@ var Whisper = Whisper || {};
|
|||
contact_name: this.model.get('name'),
|
||||
contact_avatar: this.model.get('image'),
|
||||
last_message: this.model.get('lastMessage'),
|
||||
last_message_timestamp: this.formatTimestamp()
|
||||
last_message_timestamp: moment(this.model.get('timestamp')).format('MMM M')
|
||||
})
|
||||
);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue