Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DateFormat + create Utils funtions #169

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/containers/global/Timestamp.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Tooltip } from 'antd'
import moment from 'moment'
import { Component } from 'react'
import Utils from '../../utils/Utils'

export default class Timestamp extends Component<{ timestamp: string }, {}> {
render() {
const timestamp = this.props.timestamp

return (
<Tooltip title={moment(new Date(timestamp)).fromNow()}>
<span>
{/* 'L' represents localized date format, 'LT' represents localized time format */}
{moment(new Date(timestamp)).format('L, LT')}
</span>
<Tooltip title={Utils.getRelativeDateTime(timestamp)}>
<span>{Utils.getLocalizedDateTime(timestamp)}</span>
</Tooltip>
)
}
Expand Down
16 changes: 16 additions & 0 deletions src/utils/Utils.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import moment from 'moment'
import React, { ReactElement } from 'react'

// eslint-disable-next-line import/no-anonymous-default-export
Expand Down Expand Up @@ -171,4 +172,19 @@ export default {

return newObject
},

getLocalizedDateTime(timestamp: string) {
const formattedDate = new Date(timestamp).toLocaleString('default', {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
return formattedDate
},

getRelativeDateTime(timestamp: string) {
return moment(new Date(timestamp)).fromNow()
},
}
Loading