From 893e7fbb1b529f719a238db97c2b80685e9136c6 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 12 Dec 2019 11:20:17 -0500 Subject: [PATCH] round dates down for months and days --- static/app-strings.json | 13 +++++++++++-- ui/component/dateTime/view.jsx | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/static/app-strings.json b/static/app-strings.json index 92ebab092..fb7124da6 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -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.", "Loading 3D model.": "Loading 3D model.", "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" +} \ No newline at end of file diff --git a/ui/component/dateTime/view.jsx b/ui/component/dateTime/view.jsx index 3ee450866..8636b7113 100644 --- a/ui/component/dateTime/view.jsx +++ b/ui/component/dateTime/view.jsx @@ -25,7 +25,7 @@ class DateTime extends React.PureComponent { // 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'); + const numberOfYearsSincePublish = Math.floor(moment().diff(date, 'years')); if (numberOfYearsSincePublish === 1) { return {__('%numberOfYearsSincePublish% year ago', { numberOfYearsSincePublish })}; @@ -33,6 +33,21 @@ class DateTime extends React.PureComponent { return {__('%numberOfYearsSincePublish% years ago', { numberOfYearsSincePublish })}; } + const numberOfMonthsSincePublish = Math.floor(moment().diff(date, 'months')); + if (numberOfMonthsSincePublish === 1) { + return {__('%numberOfMonthsSincePublish% month ago', { numberOfMonthsSincePublish })}; + } else if (numberOfMonthsSincePublish > 1) { + return {__('%numberOfMonthsSincePublish% months ago', { numberOfMonthsSincePublish })}; + } + + const numberOfDaysSincePublish = Math.floor(moment().diff(date, 'days')); + if (numberOfDaysSincePublish === 1) { + return {__('%numberOfDaysSincePublish% day ago', { numberOfDaysSincePublish })}; + } else if (numberOfDaysSincePublish > 1) { + return {__('%numberOfDaysSincePublish% days ago', { numberOfDaysSincePublish })}; + } + + // "just now", "a few minutes ago" return {moment(date).from(moment())}; }