Skip to content

Commit

Permalink
Update security-monitor.component.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkhanh-axonivy committed Dec 17, 2024
1 parent cd4f397 commit 90a1f61
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class SecurityMonitorComponent {
if (sessionData) {
this.repos = JSON.parse(sessionData) as ProductSecurityInfo[];
this.isAuthenticated = true;
}
}
}
catch (error) {
this.clearSessionData();
Expand Down Expand Up @@ -114,23 +114,26 @@ export class SecurityMonitorComponent {
formatCommitDate(date: string): string {
const now = new Date().getTime();
const targetDate = new Date(date).getTime();
console.log('now ' + now);
console.log('targetDate ' + targetDate);
const diffInSeconds = Math.floor((now - targetDate) / 1000);

console.log(diffInSeconds);

if (diffInSeconds < 60) {
return 'just now';
}
for (const { SECONDS, SINGULAR, PLURAL } of TIME_UNITS) {
if (diffInSeconds < SECONDS) {
const value = Math.floor(diffInSeconds / (SECONDS / 60));

for (const [index, { SECONDS, SINGULAR, PLURAL }] of TIME_UNITS.entries()) {
if (index < TIME_UNITS.length - 1 && diffInSeconds < TIME_UNITS[index + 1].SECONDS) {
const value = Math.floor(diffInSeconds / SECONDS);
if (value === 1) {
return `${value} ${SINGULAR} ago`;
} else {
return `${value} ${PLURAL} ago`;
}
}
}

const years = Math.floor(diffInSeconds / TIME_UNITS[TIME_UNITS.length - 1].SECONDS);
if (years === 1) {
return `${years} year ago`;
Expand Down

0 comments on commit 90a1f61

Please sign in to comment.