Skip to content

Commit

Permalink
added moment to format message time stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
bhubie committed Jul 20, 2017
1 parent 3fd87ca commit 6a359d0
Show file tree
Hide file tree
Showing 5 changed files with 4,473 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.15.3",
"moment": "^2.18.1",
"socket.io": "^2.0.3"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h3>People</h3>

<script = src="socket.io/socket.io.js"> </script>
<script = src="/js/libs/jquery-3.2.1.min.js"> </script>
<script = src="/js/libs/moment.js"> </script>
<script src="/js/index.js"> </script>
</body>
</html>
6 changes: 4 additions & 2 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ socket.on('disconnect', function() {
});

socket.on('newMessage', function(message){
var formattedTime = moment(message.createdAt).format('h:mm a');
var li = jQuery('<li></li>');
li.text(`${message.from}: ${message.text}`);
li.text(`${message.from} ${formattedTime}: ${message.text}`);

jQuery('#messages').append(li);
});

socket.on('newLocationMessage', function(message){
var formattedTime = moment(message.createdAt).format('h:mm a');
var li = jQuery('<li></li>');
var a = jQuery('<a target="_blank">My Current Location</a>');
li.text(`${message.from}: `);
li.text(`${message.from} ${formattedTime}: `);
a.attr('href', message.url);
li.appent(a);

Expand Down
Loading

0 comments on commit 6a359d0

Please sign in to comment.