Skip to content

Commit

Permalink
Render "Data updated" as a relative date
Browse files Browse the repository at this point in the history
To us humans, "Data updated 3 years ago" is more interpretable than
"Data updated 2020-12-11". Time flies!
  • Loading branch information
victorlin committed Dec 12, 2023
1 parent 97089b7 commit ba52ef5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/info/byline.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { headerFont } from "../../globalStyles";
*/
@connect((state) => {
return {
metadata: state.metadata
metadata: state.metadata,
language: state.general.language
};
})
class Byline extends React.Component {
Expand All @@ -23,7 +24,7 @@ class Byline extends React.Component {
{renderAvatar(t, this.props.metadata)}
{renderBuildInfo(t, this.props.metadata)}
{renderMaintainers(t, this.props.metadata)}
{renderDataUpdated(t, this.props.metadata)}
{renderDataUpdated(t, this.props.metadata, this.props.language)}
{renderDataProvenance(t, this.props.metadata)}
</>
);
Expand Down Expand Up @@ -107,11 +108,12 @@ function renderMaintainers(t, metadata) {
* Returns a React component detailing the date the data was last updated.
* Renders a <span> containing "Data updated X", where X derives from `metadata.updated`
*/
function renderDataUpdated(t, metadata) {
if (DateTime.fromISO(metadata.updated).isValid) {
function renderDataUpdated(t, metadata, language) {
const date = DateTime.fromISO(metadata.updated);
if (date.isValid) {
return (
<span>
{`${t("Data updated")} ${metadata.updated}. `}
{`${t("Data updated")} ${date.toRelativeCalendar({locale: language})}. `}
</span>
);
}
Expand Down

0 comments on commit ba52ef5

Please sign in to comment.