From 4b6030d11f90e6a1a56d3ea84decd5a9ae84d6d2 Mon Sep 17 00:00:00 2001 From: Ruslan Bayandinov <45530296+wazsone@users.noreply.github.com> Date: Tue, 25 Apr 2023 06:56:28 +0400 Subject: [PATCH] update month passed calculation (#3063) Signed-off-by: Ruslan Bayandinov --- packages/ui/src/components/TimeSince.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/TimeSince.svelte b/packages/ui/src/components/TimeSince.svelte index 5f6415b6e0..01156b15a4 100644 --- a/packages/ui/src/components/TimeSince.svelte +++ b/packages/ui/src/components/TimeSince.svelte @@ -32,6 +32,17 @@ let time: string = '' + function calculateMonthsPassed (now: number, value: number): number { + const startDate: Date = new Date(value) + const endDate: Date = new Date(now) + const startYear = startDate.getFullYear() + const startMonth = startDate.getMonth() + const endYear = endDate.getFullYear() + const endMonth = endDate.getMonth() + + return (endYear - startYear) * 12 + (endMonth - startMonth) + } + async function formatTime (now: number, value: number) { let passed = now - value if (passed < 0) passed = 0 @@ -42,7 +53,7 @@ } else if (passed < MONTH) { time = await translate(ui.string.Days, { days: Math.floor(passed / DAY) }) } else if (passed < YEAR) { - time = await translate(ui.string.Months, { months: Math.floor(passed / MONTH) }) + time = await translate(ui.string.Months, { months: calculateMonthsPassed(now, value) }) } else { time = await translate(ui.string.Years, { years: Math.floor(passed / YEAR) }) }