Skip to content

Commit

Permalink
feat(timer40k): display day, hour and minutes until deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
sabinmarcu committed Aug 16, 2024
1 parent e4d5fd8 commit 5fbd715
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions apps/timer40k/app/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ export type DisplayProperties = {
releaseDate: string,
earlyReleaseDate: string,
};

const getNumber = (input: number) => Number.parseInt(`${Math.abs(input)}`, 10);

const computeDisplayDiff = (
now: number,
input: string,
) => {
let current = dayjs(now);
const target = dayjs(input);
const days = current.diff(target, 'day');
current = current.add(Math.abs(days), 'day');
const hours = current.diff(target, 'hour');
current = current.add(Math.abs(hours), 'hour');
const minutes = current.diff(target, 'minute');
return [
(days && `${getNumber(days)} days`),
(hours && `${getNumber(hours)} hours`),
(minutes && `${getNumber(minutes)} minutes`),
].filter(Boolean).join(', ');
};

export function Display({
releasedImage,
earlyReleaseImage,
Expand Down Expand Up @@ -43,6 +64,10 @@ export function Display({
|| (earlyReleaseDiff >= 0 && earlyReleaseImage)
|| upcomingImage
) as any;
const releaseText = computeDisplayDiff(time, releaseDate);
const earlyReleaseText = earlyReleaseDate
? computeDisplayDiff(time, earlyReleaseDate)
: undefined;
return (
<>
<div className="background">
Expand All @@ -53,13 +78,13 @@ export function Display({
<h1>
{releaseDiff >= 0
? String.raw`It's released, what are you doing here?`
: `Releasing in ${Number.parseInt(`${0 - releaseDiff}`, 10)} days`}
: `Releasing in ${releaseText}`}
</h1>
{earlyReleaseDate && (
<h2>
{earlyReleaseDiff >= 0
? String.raw`It's in early release. Go have fun, you wealthy git.`
: `Early release in in ${Number.parseInt(`${0 - earlyReleaseDiff}`, 10)} days`}
: `Early release in in ${earlyReleaseText}`}
</h2>
)}
</div>
Expand Down

0 comments on commit 5fbd715

Please sign in to comment.