mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
implemented date formatter
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
"eslint": "^8.34.0",
|
||||
"eslint-config-react-app": "^7.0.1",
|
||||
"ext-name": "^5.0.0",
|
||||
"moment": "^2.29.4",
|
||||
"postcss": "^8.4.21",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
||||
@@ -6,7 +6,7 @@ import ImageBanner from './ImageBanner';
|
||||
import { useFeed, useAccountsActions } from '@plebbit/plebbit-react-hooks';
|
||||
import InfiniteScroll from 'react-infinite-scroller';
|
||||
import { Tooltip } from 'react-tooltip';
|
||||
import moment from 'moment';
|
||||
import getDate from '../utils/getDate';
|
||||
|
||||
|
||||
const Board = ({ setBodyStyle }) => {
|
||||
@@ -501,7 +501,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
: <span key={`n-${thread.cid}`} className="name">
|
||||
Anonymous</span>}
|
||||
|
||||
(User:
|
||||
(u/
|
||||
{thread.author.address.length > 15 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${thread.cid}`} id="tt-address-mobile" className="tooltip" />
|
||||
@@ -516,7 +516,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
{thread.author.address}
|
||||
</span>})
|
||||
|
||||
<span key={`dt-${thread.cid}`} className="date-time" data-utc="data">{moment(thread.timestamp * 1000).fromNow()}</span>
|
||||
<span key={`dt-${thread.cid}`} className="date-time" data-utc="data">{getDate(thread.timestamp)}</span>
|
||||
|
||||
<span key={`pn-${thread.cid}`} className="post-number">
|
||||
<a key={`pl1-${thread.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
@@ -578,7 +578,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
Anonymous</span>}
|
||||
|
||||
<span key={`pa-${reply.cid}`} className="poster-address">
|
||||
(User:
|
||||
(u/
|
||||
{reply.author.address.length > 12 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${reply.cid}`} id="tt-address" className="tooltip" />
|
||||
@@ -596,7 +596,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span key={`dt-${reply.cid}`} className="date-time" data-utc="data">{moment(reply.timestamp * 1000).fromNow()}</span>
|
||||
<span key={`dt-${reply.cid}`} className="date-time" data-utc="data">{getDate(reply.timestamp)}</span>
|
||||
|
||||
<span key={`pn-${reply.cid}`} className="post-number">
|
||||
<a key={`pl1-${reply.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
@@ -654,7 +654,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
Anonymous</span>}
|
||||
|
||||
<span key={`mob-pa-${thread.cid}`} className="poster-address-mobile">
|
||||
(User:
|
||||
(u/
|
||||
{thread.author.address.length > 15 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${thread.cid}`} id="tt-address-mobile" className="tooltip" />
|
||||
@@ -688,7 +688,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
: null}
|
||||
</span>
|
||||
<span key={`mob-dt-${thread.cid}`} className="date-time-mobile">
|
||||
{moment(thread.timestamp * 1000).fromNow()}
|
||||
{getDate(thread.timestamp)}
|
||||
|
||||
<a key={`mob-no-${thread.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
<a key={`mob-no2-${thread.cid}`} href={handleVoidClick} title="Reply to this post">{thread.cid.slice(0, 8)}</a>
|
||||
@@ -746,7 +746,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
Anonymous</span>}
|
||||
|
||||
<span key={`mob-pa-${reply.cid}`} className="poster-address-mobile">
|
||||
(User:
|
||||
(u/
|
||||
{reply.author.address.length > 10 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${reply.cid}`} id="tt-address-mobile" className="tooltip" />
|
||||
@@ -765,7 +765,7 @@ const Board = ({ setBodyStyle }) => {
|
||||
<br key={`mob-br-${reply.cid}`} />
|
||||
</span>
|
||||
<span key={`mob-dt-${reply.cid}`} className="date-time-mobile">
|
||||
{moment(reply.timestamp * 1000).fromNow()}
|
||||
{getDate(reply.timestamp)}
|
||||
<a key={`mob-pl1-${reply.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
<a key={`mob-pl2-${reply.cid}`} href={handleVoidClick} title="Reply to this post">{reply.cid.slice(0, 8)}</a>
|
||||
</span>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BoardContext } from '../App';
|
||||
import { useComment } from '@plebbit/plebbit-react-hooks';
|
||||
import ImageBanner from './ImageBanner';
|
||||
import { Tooltip } from 'react-tooltip';
|
||||
import moment from 'moment';
|
||||
import getDate from '../utils/getDate';
|
||||
|
||||
|
||||
const Thread = ({ setBodyStyle }) => {
|
||||
@@ -404,7 +404,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
|
||||
|
||||
<span className="poster-address">
|
||||
(User:
|
||||
(u/
|
||||
{comment.author.address.length > 20 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${comment.cid}`} id="tt-address-mobile" className="tooltip" />
|
||||
@@ -420,7 +420,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
</span>})
|
||||
</span>
|
||||
|
||||
<span className="date-time" data-utc="data">{moment(comment.timestamp * 1000).fromNow()}</span>
|
||||
<span className="date-time" data-utc="data">{getDate(comment.timestamp)}</span>
|
||||
|
||||
<span className="post-number">
|
||||
<a href={handleVoidClick} title="Link to this post">c/</a>
|
||||
@@ -467,7 +467,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
Anonymous</span>}
|
||||
|
||||
<span key={`pa-${reply.cid}`} className="poster-address">
|
||||
(User:
|
||||
(u/
|
||||
{reply.author.address.length > 20 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${reply.cid}`} id="tt-address" className="tooltip" />
|
||||
@@ -484,7 +484,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span key={`dt-${reply.cid}`} className="date-time" data-utc="data">{moment(reply.timestamp * 1000).fromNow()}</span>
|
||||
<span key={`dt-${reply.cid}`} className="date-time" data-utc="data">{getDate(reply.timestamp)}</span>
|
||||
|
||||
<span key={`pn-${reply.cid}`} className="post-number">
|
||||
<a key={`pl1-${reply.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
@@ -528,7 +528,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
Anonymous</span>}
|
||||
|
||||
<span key={`mob-pa-${comment.cid}`} className="poster-address-mobile">
|
||||
(User:
|
||||
(u/
|
||||
{comment.author.address.length > 15 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${comment.cid}`} id="tt-address-mobile" className="tooltip" />
|
||||
@@ -561,7 +561,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
</span>) : null}
|
||||
</span>
|
||||
<span key={`mob-dt-${comment.cid}`} className="date-time-mobile">
|
||||
{moment(comment.timestamp * 1000).fromNow()}
|
||||
{getDate(comment.timestamp)}
|
||||
|
||||
<a key={`mob-no-${comment.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
<a key={`mob-no2-${comment.cid}`} href={handleVoidClick} title="Reply to this post">{comment.cid.slice(0, 8)}</a>
|
||||
@@ -609,7 +609,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
Anonymous</span>}
|
||||
|
||||
<span key={`mob-pa-${reply.cid}`} className="poster-address-mobile">
|
||||
(User:
|
||||
(u/
|
||||
{reply.author.address.length > 12 ?
|
||||
<>
|
||||
<Tooltip key={`mob-tt-am-${reply.cid}`} id="tt-address-mobile" className="tooltip" />
|
||||
@@ -628,7 +628,7 @@ const Thread = ({ setBodyStyle }) => {
|
||||
<br key={`mob-br-${reply.cid}`} />
|
||||
</span>
|
||||
<span key={`mob-dt-${reply.cid}`} className="date-time-mobile">
|
||||
{moment(reply.timestamp * 1000).fromNow()}
|
||||
{getDate(reply.timestamp)}
|
||||
<a key={`mob-pl1-${reply.cid}`} href={handleVoidClick} title="Link to this post">c/</a>
|
||||
<a key={`mob-pl2-${reply.cid}`} href={handleVoidClick} title="Reply to this post">{reply.cid.slice(0, 8)}</a>
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const getDate = (commentTimestamp) => {
|
||||
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
|
||||
const string = new Intl.DateTimeFormat(locale, {
|
||||
hour12: false,
|
||||
year: '2-digit',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
weekday: 'short',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
}).format(new Date(commentTimestamp * 1000));
|
||||
if (locale.startsWith('ar')) {
|
||||
return string
|
||||
}
|
||||
const items = string.split(/,* /)
|
||||
if (items.length === 3) {
|
||||
const itemIsNumber = [
|
||||
items[0][0].match(/[0-9]/),
|
||||
items[1][0].match(/[0-9]/)
|
||||
]
|
||||
if (itemIsNumber[0] && itemIsNumber[1]) {
|
||||
return `${items[0]}(${items[2]})${items[1]}`
|
||||
}
|
||||
if (itemIsNumber[0] && !itemIsNumber[1]) {
|
||||
return `${items[0]}(${items[1]})${items[2]}`
|
||||
}
|
||||
if (!itemIsNumber[0] && itemIsNumber[1]) {
|
||||
return `${items[1]}(${items[0]})${items[2]}`
|
||||
}
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
export default getDate;
|
||||
@@ -8566,11 +8566,6 @@ mkdirp@~0.5.1:
|
||||
dependencies:
|
||||
minimist "^1.2.6"
|
||||
|
||||
moment@^2.29.4:
|
||||
version "2.29.4"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
|
||||
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
|
||||
|
||||
ms@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||
|
||||
Reference in New Issue
Block a user