diff --git a/src/pages/common/Post.js b/src/pages/common/Post.js index 886fc3c..4b9a16a 100644 --- a/src/pages/common/Post.js +++ b/src/pages/common/Post.js @@ -1,6 +1,6 @@ import React from 'react' import { Link } from 'react-router-dom' -import { prettyScore, prettyDate, prettyTimeDiff, parse, redditThumbnails, isDeleted, isRemoved } from '../../utils' +import { prettyScore, prettyDate, prettyTimeDiff, exactDateTime, parse, redditThumbnails, isDeleted, isRemoved } from '../../utils' export default (props) => { if (!props.title) { @@ -54,7 +54,7 @@ export default (props) => { } ({props.domain})
- submitted {prettyDate(props.created_utc)} by  + submitted {prettyDate(props.created_utc)} by  {props.author}  to /r/{props.subreddit}
diff --git a/src/pages/thread/Comment.js b/src/pages/thread/Comment.js index 3278895..a39f531 100644 --- a/src/pages/thread/Comment.js +++ b/src/pages/thread/Comment.js @@ -1,6 +1,6 @@ import React, { useState } from 'react' import { Link } from 'react-router-dom' -import { prettyScore, prettyDate, prettyTimeDiff, parse, isRemoved } from '../../utils' +import { prettyScore, prettyDate, prettyTimeDiff, exactDateTime, parse, isRemoved } from '../../utils' const Comment = (props) => { let commentStyle = 'comment ' @@ -54,9 +54,10 @@ const Comment = (props) => { {prettyScore(props.score)} point{(props.score !== 1) && 's'} - {prettyDate(props.created_utc)} + {prettyDate(props.created_utc)} {props.hasOwnProperty('edited_body') && - * (last edited {prettyDate(props.edited ? props.edited : props.created_utc)})} + * (last edited {prettyDate(props.edited ? props.edited : props.created_utc)})}
diff --git a/src/utils.js b/src/utils.js index 8956be1..abb36c0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -54,12 +54,22 @@ export const prettyDate = createdUTC => { if (secondDiff < 7200) return 'an hour ago' if (secondDiff < 86400) return `${Math.floor(secondDiff / 3600)} hours ago` } + if (dayDiff < 2) return `1 day ago` if (dayDiff < 7) return `${dayDiff} days ago` if (dayDiff < 31) return `${Math.floor(dayDiff / 7)} weeks ago` if (dayDiff < 365) return `${Math.floor(dayDiff / 30)} months ago` return `${Math.floor(dayDiff / 365)} years ago` } +// The date and time, to the second, formatted in the user's locale +export const exactDateTime = utc => { + const datetime = new Date(utc * 1000) + if (new Date().toDateString() == datetime.toDateString()) + return datetime.toLocaleTimeString([], {timeStyle: 'long'}) + else + return datetime.toLocaleString([], {dateStyle: 'medium', timeStyle: 'long'}) +} + // Time difference in seconds to text, rounded up by default (e.g. x seconds/minutes/hours) export const prettyTimeDiff = (secondDiff, roundDown = false) => { if (secondDiff < 2) return `1 second`