From be749876145401b56fb9aea7d61580d4e8f4b562 Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Tue, 22 Mar 2022 13:31:18 -0400 Subject: [PATCH] FriendlyDate component - Round dates to nearest 10th before taking floor (#6082) * round dates to nearest 10th before taking floor * round dates to nearest 10th before taking floor * lint --- app/components/friendly_date/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/components/friendly_date/index.tsx b/app/components/friendly_date/index.tsx index f66c0a783..d9d41d62a 100644 --- a/app/components/friendly_date/index.tsx +++ b/app/components/friendly_date/index.tsx @@ -37,7 +37,7 @@ export function getFriendlyDate(intl: typeof intlShape, inputDate: number | Date // Message: Minutes Ago if (difference < DateTypes.SECONDS.HOUR) { - const minutes = Math.floor(difference / DateTypes.SECONDS.MINUTE); + const minutes = Math.floor(Math.round((10 * difference) / DateTypes.SECONDS.MINUTE) / 10); return intl.formatMessage({ id: 'friendly_date.minsAgo', defaultMessage: '{count} {count, plural, one {min} other {mins}} ago', @@ -48,7 +48,7 @@ export function getFriendlyDate(intl: typeof intlShape, inputDate: number | Date // Message: Hours Ago if (difference < DateTypes.SECONDS.DAY) { - const hours = Math.floor(difference / DateTypes.SECONDS.HOUR); + const hours = Math.floor(Math.round((10 * difference) / DateTypes.SECONDS.HOUR) / 10); return intl.formatMessage({ id: 'friendly_date.hoursAgo', defaultMessage: '{count} {count, plural, one {hour} other {hours}} ago', @@ -67,7 +67,7 @@ export function getFriendlyDate(intl: typeof intlShape, inputDate: number | Date } const completedAMonth = today.getMonth() !== date.getMonth() && today.getDate() >= date.getDate(); if (!completedAMonth) { - const days = Math.floor(difference / DateTypes.SECONDS.DAY) || 1; + const days = Math.floor(Math.round((10 * difference) / DateTypes.SECONDS.DAY) / 10) || 1; return intl.formatMessage({ id: 'friendly_date.daysAgo', defaultMessage: '{count} {count, plural, one {day} other {days}} ago', @@ -83,7 +83,7 @@ export function getFriendlyDate(intl: typeof intlShape, inputDate: number | Date today.getMonth() >= date.getMonth() && today.getDate() >= date.getDate(); if (!completedAnYear) { - const months = Math.floor(difference / DateTypes.SECONDS.DAYS_30) || 1; + const months = Math.floor(Math.round((10 * difference) / DateTypes.SECONDS.DAYS_30) / 10) || 1; return intl.formatMessage({ id: 'friendly_date.monthsAgo', defaultMessage: '{count} {count, plural, one {month} other {months}} ago', @@ -94,7 +94,7 @@ export function getFriendlyDate(intl: typeof intlShape, inputDate: number | Date } // Message: Years Ago - const years = Math.floor(difference / DateTypes.SECONDS.DAYS_365) || 1; + const years = Math.floor(Math.round((10 * difference) / DateTypes.SECONDS.DAYS_365) / 10) || 1; return intl.formatMessage({ id: 'friendly_date.yearsAgo', defaultMessage: '{count} {count, plural, one {year} other {years}} ago',