fix date rounding

This commit is contained in:
Sean Yesmunt 2019-12-10 14:09:10 -05:00
parent 2042d256f0
commit 208fe57ed7
2 changed files with 17 additions and 1 deletions

View file

@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Always round down dates on claim previews for better yotube parity ([#3353](https://github.com/lbryio/lbry-desktop/pull/3353))
## [0.37.2] - [2019-11-21]
### Fixed

View file

@ -19,7 +19,21 @@ class DateTime extends React.PureComponent<Props> {
const show = this.props.show || DateTime.SHOW_BOTH;
if (timeAgo) {
return date ? <span>{moment(date).from(moment())}</span> : <span />;
if (!date) {
return null;
}
// Moment is very liberal with it's rounding
// Wait to show "two years ago" until it's actually been two years (or higher)
const numberOfYearsSincePublish = moment().diff(date, 'years');
if (numberOfYearsSincePublish === 1) {
return <span>{__('%numberOfYearsSincePublish% year ago', { numberOfYearsSincePublish })}</span>;
} else if (numberOfYearsSincePublish > 1) {
return <span>{__('%numberOfYearsSincePublish% years ago', { numberOfYearsSincePublish })}</span>;
}
return <span>{moment(date).from(moment())}</span>;
}
return (