Skip to content

Commit

Permalink
Render "Data updated" as a human-readable relative date
Browse files Browse the repository at this point in the history
To us humans, "3 years ago" is more interpretable than "2020-12-11".
Time files!
  • Loading branch information
victorlin committed Dec 12, 2023
1 parent 4e29303 commit 492ea99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"react-hot-loader": "^4.8.4",
"react-i18next": "^11.15.6",
"react-icons": "^3.9.0",
"react-moment": "^1.1.3",
"react-redux": "^7.2.6",
"react-select": "^5.2.2",
"react-tooltip": "^4.2.10",
Expand Down
12 changes: 8 additions & 4 deletions src/components/info/byline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { connect } from "react-redux";
import Moment from 'react-moment';
import { withTranslation } from 'react-i18next';
import styled from 'styled-components';
import moment from "moment";
Expand All @@ -12,7 +13,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 +25,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 +109,13 @@ 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) {
function renderDataUpdated(t, metadata, language) {
if (moment(metadata.updated).isValid()) {
return (
<span>
{`${t("Data updated")} ${metadata.updated}. `}
{`${t("Data updated")} `}
<Moment locale={language} date={metadata.updated} fromNow />
{` `}
</span>
);
}
Expand Down

0 comments on commit 492ea99

Please sign in to comment.