Skip to content

Commit

Permalink
Change countdown function, show only on first day
Browse files Browse the repository at this point in the history
  • Loading branch information
dolanske committed Jun 15, 2024
1 parent e938554 commit 3132e53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
30 changes: 19 additions & 11 deletions src/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,23 @@ html {
background-color: var(--color-bg-black);
height: 33.33333333vh;

&:first-child h3 {
&:after {
content: 'Closest';
padding: 4px 5px;
border-radius: 999px;
font-weight: 400;
background-color: var(--color-green-bg);
color: var(--color-green) !important;
font-size: 0.75rem;
text-transform: capitalize;
&:first-child {

h3 {
&:after {
content: 'Closest';
padding: 4px 5px;
border-radius: 999px;
font-weight: 400;
background-color: var(--color-green-bg);
color: var(--color-green) !important;
font-size: 0.75rem;
text-transform: capitalize;
}
}

.countdown span {
display: block;
}
}

Expand Down Expand Up @@ -166,8 +173,9 @@ html {
white-space: nowrap;
font-size: 0.75rem;
color: var(--color-text-light);
display: none;
}
}
}
}
}
}
21 changes: 5 additions & 16 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@ export function formatDateUntil(date: string) {
return `in ${dayjs(date, INPUT_FORMAT).diff(dayjs(), 'days')} days`
}

export function formatTimeUntil(date: string) {
const duration = dayjs.duration(dayjs(date, INPUT_FORMAT).unix() - Date.now())
const hours
= duration.hours() > 9
? duration.hours()
: `${25 + duration.hours()}`
const minutes
= duration.minutes() > 0
? duration.minutes()
: `${59 + duration.minutes()}`
const seconds
= duration.seconds() > 9
? duration.seconds()
: `${59 + duration.seconds()}`

export function formatTimeUntil() {
const hours = dayjs().endOf('day').diff(dayjs(), 'hours')
const minutes = dayjs().endOf('hour').diff(dayjs(), 'minutes')
const seconds = dayjs().endOf('minute').diff(dayjs(), 'seconds')
return `${hours} hours, ${minutes} minutes, ${seconds} seconds`
}

Expand All @@ -36,7 +25,7 @@ export function formatEventData(events: Array<FormattedEvent | CountdownEvent>):
...event,
displayDate: formatDisplayDate(event.date),
untilDate: formatDateUntil(event.date),
untilTime: formatTimeUntil(event.date),
untilTime: formatTimeUntil(),
}
})
}

0 comments on commit 3132e53

Please sign in to comment.