Skip to content

Commit

Permalink
fix: updated badge
Browse files Browse the repository at this point in the history
  • Loading branch information
nsdonato committed Jan 28, 2024
1 parent e761d21 commit 13c1f44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 3 additions & 1 deletion components/badge/badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ describe('<Badge />', () => {
const today = new Date().toISOString()
const yesterday = new Date(Date.now() - 86400000).toISOString()
const lastWeek = new Date(Date.now() - 604800000).toISOString()

console.log(today)
console.log(yesterday)
console.log(lastWeek)
test('renders the new badge', () => {
const { getByText } = render(
<Badge createdAt={today} updatedAt={yesterday} />
Expand Down
24 changes: 11 additions & 13 deletions lib/date-utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
export const isToday = (date: Date) => {
const today = new Date()
const today = new Date()

return (
today.getFullYear() === date.getFullYear() &&
today.getMonth() === date.getMonth() &&
today.getDate() === date.getDate()
)
return (
today.getFullYear() === date.getFullYear() &&
today.getMonth() === date.getMonth() &&
today.getDate() === date.getDate()
)
}

// Show updated badge if updatedAt is within the last 3 days
export const isUpdated = (updatedAt: Date) => {
if(isToday(updatedAt)) return true
const fechaActual = new Date()

const today = new Date()
const fechaLimite = new Date(fechaActual)
fechaLimite.setDate(fechaActual.getDate() - 3)

const isSameWeek =
updatedAt.getDate() - today.getDate() >= -today.getDay() &&
updatedAt.getDate() - today.getDate() <= 6 - today.getDay()

return isSameWeek
return updatedAt >= fechaLimite && updatedAt <= fechaActual
}

0 comments on commit 13c1f44

Please sign in to comment.