Skip to content

Commit

Permalink
fix: updated badge (nsdonato#24)
Browse files Browse the repository at this point in the history
* fix: updated badge

* update: template pr

* fix: spanglish on date utils
  • Loading branch information
nsdonato committed Jan 28, 2024
1 parent e761d21 commit 2119a59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
> Checklist a modo recordatorio. Tildar lo que corresponda
[] - Te agregaste como contribuidor/a, en el archivo mdx que tocaste?
[] - Verificaste que createdAt y updatedAt del recurso y del menu, esten actualizados? (Si corresponde)
[] - Verificaste que createdAt y updatedAt del recurso esten actualizados? (Si corresponde)
[] - Verifica si corresponde actualizar createdAt en menu.mdx (para secciones nuevas)
[] - Verifica si corresponde actualizar updatedAt en menu.mdx (para recursos nuevos o actualizados)
[] - Agregué un link y funciona correctamente.
[] - Agregaste test para cubrir la nueva funcionalidad (Solo al modificar código)
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 today = new Date()

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

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

return isSameWeek
return updatedAt >= limitDate && updatedAt <= today
}

0 comments on commit 2119a59

Please sign in to comment.