Skip to content

Commit

Permalink
feat: [pipe-24076]: fix issue with future time
Browse files Browse the repository at this point in the history
Signed-off-by: Calvin Lee <[email protected]>
  • Loading branch information
cjlee1 committed Jan 24, 2025
1 parent 9f6df25 commit 42e1170
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/gitness/src/pages/pipeline-edit/utils/time-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export const timeAgoFromISOTime = (timestamp: string, maxDiff: number = 2): stri
const now = new Date()

const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000)
const diffInDays = diffInSeconds / (3600 * 24)
// Always treat time differences as past events
const absDiffInSeconds = Math.abs(diffInSeconds)
const diffInDays = absDiffInSeconds / (3600 * 24)

if (diffInDays <= maxDiff) {
return formatRelativeTime(diffInSeconds)
return formatRelativeTime(absDiffInSeconds)
} else {
return date.toLocaleDateString('en', { dateStyle: 'medium' })
}
Expand Down

0 comments on commit 42e1170

Please sign in to comment.