Date
The date utility provides a useRelativeTime, formatter (deprecated), and isCredibleDate (deprecated) utility
Usage - useRelativeTime
Use the useRelativeTime method with your date string to recieve a formatted string relative to now that updates every 60 seconds.
import { useRelativeTime } from '@scoir/date';
const ExampleComp = () => {
const formattedDate = useRelativeTime('2024-01-05T19:17:39.875Z')
render (
<Typography>{formattedDate}</Typography>
...
)
...
}
Usage - formatter - deprecated
Use the format method with your date and an option configuration object. The configuration can take defaultText, inputFormat, and an outputFormat.
import { formatter } from '@scoir/date';
class ExampleComp extends React.Component {
static propTypes = { someDate: PropTypes.string }
render () {
const formattedDate = formatter.format(this.props.someDate, {
defaultText: '—',
inputFormat: 'MM-DD-YYYY',
outputFormat: 'ddd, hA',
})
...
}
...
}
Usage - isCredibleDate - deprecated
A method returning a boolean for a non-falsy and non-zero-date date input
import { isCredibleDate } from '@scoir/date';
class ExampleComp extends React.Component {
static propTypes = { someDate: PropTypes.string }
render () {
const isNotTrashGarbage = isCredibleDate(this.props.someDate)
...
}
...
}