Skip to content

Commit

Permalink
fix DateFormat + create Utils funtions (#169)
Browse files Browse the repository at this point in the history
* fix DateFormat + create Utils funtions

* prettier format

* f
  • Loading branch information
ivnnv authored Nov 5, 2024
1 parent 28b4cd3 commit df22c8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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()
},
}

0 comments on commit df22c8f

Please sign in to comment.