From d27d4a798f259030e8bb27fc716c429e0d495a64 Mon Sep 17 00:00:00 2001 From: Ahmad Karlam Date: Sun, 4 Oct 2020 09:01:46 +0700 Subject: [PATCH] Remove moment js and use standard library date from javascript --- webroot/index.html | 3 --- webroot/js/components/chat/message.js | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/webroot/index.html b/webroot/index.html index 231b710fb..79c199c64 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -35,9 +35,6 @@ - - - diff --git a/webroot/js/components/chat/message.js b/webroot/js/components/chat/message.js index bd1d0ca8d..2e5fc7695 100644 --- a/webroot/js/components/chat/message.js +++ b/webroot/js/components/chat/message.js @@ -1,21 +1,23 @@ -import { h, Component } from 'https://unpkg.com/preact?module'; +import {Component, h} from 'https://unpkg.com/preact?module'; import htm from 'https://unpkg.com/htm?module'; -const html = htm.bind(h); +import {messageBubbleColorForString} from '../../utils/user-colors.js'; +import {formatMessageText} from '../../utils/chat.js'; +import {generateAvatar} from '../../utils/helpers.js'; +import {SOCKET_MESSAGE_TYPES} from '../../utils/websocket.js'; -import { messageBubbleColorForString } from '../../utils/user-colors.js'; -import { formatMessageText } from '../../utils/chat.js'; -import { generateAvatar } from '../../utils/helpers.js'; -import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js'; +const html = htm.bind(h); export default class Message extends Component { formatTimestamp(sentAt) { - sentAt = moment(sentAt); + sentAt = new Date(sentAt); - if (moment().diff(sentAt, 'days') >= 1) { - return `${sentAt.format('MMM D HH:mm:ss')}` + let diffInDays = ((new Date()) - sentAt) / (24 * 3600 * 1000); + if (diffInDays >= -1) { + return `${sentAt.toLocaleDateString('en-US', {dateStyle: 'medium'})} at ` + + sentAt.toLocaleTimeString(); } - return sentAt.format("HH:mm:ss"); + return sentAt.toLocaleTimeString(); } render(props) { @@ -30,7 +32,6 @@ export default class Message extends Component { const authorColor = messageBubbleColorForString(author); const avatarBgColor = { backgroundColor: authorColor }; const authorTextColor = { color: authorColor }; - return ( html`