From 503901bfa447cbc33b9c7b8419bcef452c4f8589 Mon Sep 17 00:00:00 2001 From: Ivn Nv Date: Mon, 4 Nov 2024 10:57:38 +0200 Subject: [PATCH 1/3] fix DateFormat + create Utils funtions --- src/containers/global/Timestamp.tsx | 14 +++++++------- src/utils/Utils.tsx | 26 +++++++++++++++++++++----- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/containers/global/Timestamp.tsx b/src/containers/global/Timestamp.tsx index f410c58d..9d25431f 100644 --- a/src/containers/global/Timestamp.tsx +++ b/src/containers/global/Timestamp.tsx @@ -1,15 +1,15 @@ -import { Tooltip } from 'antd' -import moment from 'moment' -import { Component } from 'react' +import { Tooltip } from 'antd'; +import { Component } from 'react'; +import Utils from '../../utils/Utils'; export default class Timestamp extends Component<{ timestamp: string }, {}> { render() { - const timestamp = this.props.timestamp + const timestamp = this.props.timestamp; + return ( - + - {/* 'L' represents localized date format, 'LT' represents localized time format */} - {moment(new Date(timestamp)).format('L, LT')} + {Utils.getLocalizedDateTime(timestamp)} ) diff --git a/src/utils/Utils.tsx b/src/utils/Utils.tsx index 2c3195f1..88c6db29 100644 --- a/src/utils/Utils.tsx +++ b/src/utils/Utils.tsx @@ -1,3 +1,4 @@ +import moment from 'moment' import React, { ReactElement } from 'react' // eslint-disable-next-line import/no-anonymous-default-export @@ -118,11 +119,11 @@ export default { return !raw ? '' : decodeURIComponent( - raw - .substring(8, raw.length) - .replace(/\s+/g, '') - .replace(/[0-9a-f]{2}/g, '%$&') - ) + raw + .substring(8, raw.length) + .replace(/\s+/g, '') + .replace(/[0-9a-f]{2}/g, '%$&') + ) }, formatText( @@ -171,4 +172,19 @@ export default { return newObject }, + + getLocalizedDateTime(ts: string) { + const formattedDate = new Date(ts).toLocaleString('default', { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' + }) + return formattedDate + }, + + getRelativeDateTime(ts: string) { + return moment(new Date(ts)).fromNow() + }, } From c7cecad66e5d3897935922b8876d800afab16dea Mon Sep 17 00:00:00 2001 From: Ivn Nv Date: Mon, 4 Nov 2024 11:00:52 +0200 Subject: [PATCH 2/3] prettier format --- src/containers/global/Timestamp.tsx | 12 +++++------- src/utils/Utils.tsx | 12 ++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/containers/global/Timestamp.tsx b/src/containers/global/Timestamp.tsx index 9d25431f..ac5581dd 100644 --- a/src/containers/global/Timestamp.tsx +++ b/src/containers/global/Timestamp.tsx @@ -1,16 +1,14 @@ -import { Tooltip } from 'antd'; -import { Component } from 'react'; -import Utils from '../../utils/Utils'; +import { Tooltip } from 'antd' +import { Component } from 'react' +import Utils from '../../utils/Utils' export default class Timestamp extends Component<{ timestamp: string }, {}> { render() { - const timestamp = this.props.timestamp; + const timestamp = this.props.timestamp return ( - - {Utils.getLocalizedDateTime(timestamp)} - + {Utils.getLocalizedDateTime(timestamp)} ) } diff --git a/src/utils/Utils.tsx b/src/utils/Utils.tsx index 88c6db29..4bbe4e13 100644 --- a/src/utils/Utils.tsx +++ b/src/utils/Utils.tsx @@ -119,11 +119,11 @@ export default { return !raw ? '' : decodeURIComponent( - raw - .substring(8, raw.length) - .replace(/\s+/g, '') - .replace(/[0-9a-f]{2}/g, '%$&') - ) + raw + .substring(8, raw.length) + .replace(/\s+/g, '') + .replace(/[0-9a-f]{2}/g, '%$&') + ) }, formatText( @@ -179,7 +179,7 @@ export default { month: 'numeric', day: 'numeric', hour: '2-digit', - minute: '2-digit' + minute: '2-digit', }) return formattedDate }, From 498e377582b04fcb1e2aa2aee9fd1cf1edd14eef Mon Sep 17 00:00:00 2001 From: Ivn Nv Date: Mon, 4 Nov 2024 11:08:28 +0200 Subject: [PATCH 3/3] f --- src/utils/Utils.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/Utils.tsx b/src/utils/Utils.tsx index 4bbe4e13..098f1c3f 100644 --- a/src/utils/Utils.tsx +++ b/src/utils/Utils.tsx @@ -173,8 +173,8 @@ export default { return newObject }, - getLocalizedDateTime(ts: string) { - const formattedDate = new Date(ts).toLocaleString('default', { + getLocalizedDateTime(timestamp: string) { + const formattedDate = new Date(timestamp).toLocaleString('default', { year: 'numeric', month: 'numeric', day: 'numeric', @@ -184,7 +184,7 @@ export default { return formattedDate }, - getRelativeDateTime(ts: string) { - return moment(new Date(ts)).fromNow() + getRelativeDateTime(timestamp: string) { + return moment(new Date(timestamp)).fromNow() }, }