From 4668ce159c8a2cfb59a686fc293f2fd16059cad2 Mon Sep 17 00:00:00 2001 From: Khanh Nguyen Date: Mon, 16 Dec 2024 11:31:13 +0700 Subject: [PATCH] Fix sonar UI --- .../security-monitor.component.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/marketplace-ui/src/app/modules/security-monitor/security-monitor.component.ts b/marketplace-ui/src/app/modules/security-monitor/security-monitor.component.ts index 0f423b45..ba009469 100644 --- a/marketplace-ui/src/app/modules/security-monitor/security-monitor.component.ts +++ b/marketplace-ui/src/app/modules/security-monitor/security-monitor.component.ts @@ -123,15 +123,18 @@ export class SecurityMonitorComponent { const now = new Date().getTime(); const targetDate = new Date(date).getTime(); const diffInSeconds = Math.floor((now - targetDate) / 1000); - + const DAYS_IN_WEEK = 7; + const DAYS_IN_MONTH = 30; + const MONTHS_IN_YEAR = 12; const SECONDS_IN_A_MINUTE = 60; const SECONDS_IN_AN_HOUR = 60 * SECONDS_IN_A_MINUTE; const SECONDS_IN_A_DAY = 24 * SECONDS_IN_AN_HOUR; - const SECONDS_IN_A_WEEK = 7 * SECONDS_IN_A_DAY; - const SECONDS_IN_A_MONTH = 30 * SECONDS_IN_A_DAY; - const SECONDS_IN_A_YEAR = 12 * SECONDS_IN_A_MONTH; + const SECONDS_IN_A_WEEK = DAYS_IN_WEEK * SECONDS_IN_A_DAY; + const SECONDS_IN_A_MONTH = DAYS_IN_MONTH * SECONDS_IN_A_DAY; + const SECONDS_IN_A_YEAR = MONTHS_IN_YEAR * SECONDS_IN_A_MONTH; - const formatDuration = (diff: number, unit: number, singular: string, plural: string): string | null => { + const formatDuration = (diff: number, unit: number, singular: string): string | null => { + const plural = singular + 's'; const value = Math.floor(diff / unit); if (value < unit) { if (value === 1) { @@ -148,11 +151,11 @@ export class SecurityMonitorComponent { } const formattedDuration = - formatDuration(diffInSeconds, SECONDS_IN_A_MINUTE, 'minute', 'minutes') || - formatDuration(diffInSeconds, SECONDS_IN_AN_HOUR, 'hour', 'hours') || - formatDuration(diffInSeconds, SECONDS_IN_A_DAY, 'day', 'days') || - formatDuration(diffInSeconds, SECONDS_IN_A_WEEK, 'week', 'weeks') || - formatDuration(diffInSeconds, SECONDS_IN_A_MONTH, 'month', 'months'); + formatDuration(diffInSeconds, SECONDS_IN_A_MINUTE, 'minute') ?? + formatDuration(diffInSeconds, SECONDS_IN_AN_HOUR, 'hour') ?? + formatDuration(diffInSeconds, SECONDS_IN_A_DAY, 'day') ?? + formatDuration(diffInSeconds, SECONDS_IN_A_WEEK, 'week') ?? + formatDuration(diffInSeconds, SECONDS_IN_A_MONTH, 'month'); if (formattedDuration) { return formattedDuration;