round dates down for months and days

This commit is contained in:
Sean Yesmunt 2019-12-12 11:20:17 -05:00
parent 208fe57ed7
commit 893e7fbb1b
2 changed files with 27 additions and 3 deletions

View file

@ -915,5 +915,14 @@
"Any amount will give you the highest bid, but larger amounts help your content be trusted and discovered.": "Any amount will give you the highest bid, but larger amounts help your content be trusted and discovered.", "Any amount will give you the highest bid, but larger amounts help your content be trusted and discovered.": "Any amount will give you the highest bid, but larger amounts help your content be trusted and discovered.",
"Loading 3D model.": "Loading 3D model.", "Loading 3D model.": "Loading 3D model.",
"Click here": "Click here", "Click here": "Click here",
"PDF opened externally. %click_here% to open it again.": "PDF opened externally. %click_here% to open it again." "PDF opened externally. %click_here% to open it again.": "PDF opened externally. %click_here% to open it again.",
} "%numberOfMonthsSincePublish% years ago": "%numberOfMonthsSincePublish% years ago",
"%numberOfYearsSincePublish% years ago": "%numberOfYearsSincePublish% years ago",
"%numberOfYearsSincePublish% year ago": "%numberOfYearsSincePublish% year ago",
"%numberOfMonthsSincePublish% year ago": "%numberOfMonthsSincePublish% year ago",
"Followers": "Followers",
"%numberOfMonthsSincePublish% month ago": "%numberOfMonthsSincePublish% month ago",
"%numberOfMonthsSincePublish% months ago": "%numberOfMonthsSincePublish% months ago",
"%numberOfDaysSincePublish% months ago": "%numberOfDaysSincePublish% months ago",
"%numberOfDaysSincePublish% days ago": "%numberOfDaysSincePublish% days ago"
}

View file

@ -25,7 +25,7 @@ class DateTime extends React.PureComponent<Props> {
// Moment is very liberal with it's rounding // Moment is very liberal with it's rounding
// Wait to show "two years ago" until it's actually been two years (or higher) // Wait to show "two years ago" until it's actually been two years (or higher)
const numberOfYearsSincePublish = moment().diff(date, 'years'); const numberOfYearsSincePublish = Math.floor(moment().diff(date, 'years'));
if (numberOfYearsSincePublish === 1) { if (numberOfYearsSincePublish === 1) {
return <span>{__('%numberOfYearsSincePublish% year ago', { numberOfYearsSincePublish })}</span>; return <span>{__('%numberOfYearsSincePublish% year ago', { numberOfYearsSincePublish })}</span>;
@ -33,6 +33,21 @@ class DateTime extends React.PureComponent<Props> {
return <span>{__('%numberOfYearsSincePublish% years ago', { numberOfYearsSincePublish })}</span>; return <span>{__('%numberOfYearsSincePublish% years ago', { numberOfYearsSincePublish })}</span>;
} }
const numberOfMonthsSincePublish = Math.floor(moment().diff(date, 'months'));
if (numberOfMonthsSincePublish === 1) {
return <span>{__('%numberOfMonthsSincePublish% month ago', { numberOfMonthsSincePublish })}</span>;
} else if (numberOfMonthsSincePublish > 1) {
return <span>{__('%numberOfMonthsSincePublish% months ago', { numberOfMonthsSincePublish })}</span>;
}
const numberOfDaysSincePublish = Math.floor(moment().diff(date, 'days'));
if (numberOfDaysSincePublish === 1) {
return <span>{__('%numberOfDaysSincePublish% day ago', { numberOfDaysSincePublish })}</span>;
} else if (numberOfDaysSincePublish > 1) {
return <span>{__('%numberOfDaysSincePublish% days ago', { numberOfDaysSincePublish })}</span>;
}
// "just now", "a few minutes ago"
return <span>{moment(date).from(moment())}</span>; return <span>{moment(date).from(moment())}</span>;
} }