import React from 'react' type TimestampProps = { publishedTimestamp: string textCase?: 'sentence' } const TimeStamp: React.FC = ({ publishedTimestamp, textCase, }) => { const now = new Date() const oneDay = 24 * 60 * 60 * 1000 const date = new Date(publishedTimestamp) const formatted = date.toLocaleString() let format: string if (now.getTime() - date.getTime() < oneDay) { // display published date in 'xx minutes ago' format // and render exact time next to it format = 'time-ago-no-seconds' } else { // don't display time string if the post is older than one day // because it is already included in the formatted timestamp format = 'MMM dd, HH:mm' } return ( ) } export default TimeStamp