Add the payday countdown widget

React · React · beginner · greenfield

Adds the payday countdown for the home screen. Payday math lives in two small exported helpers so the screens can reuse them; the widget itself just formats the day count. Verified the countdown ticks down correctly through the back half of the month.

Requirements

Files touched

--- src/components/PaydayCountdown.jsx
+const PAYDAY_DOM = 15;
+const MS_PER_DAY = 86400000;
+
+export function nextPayday(today) {
+  // Paydays land mid-month, so the next one is in next month's cycle.
+  return new Date(today.getFullYear(), today.getMonth() + 1, PAYDAY_DOM);
+}
+
+export function daysUntilPayday(today) {
+  const startOfToday = new Date(
+    today.getFullYear(),
+    today.getMonth(),
+    today.getDate(),
+  );
+  return Math.round((nextPayday(today) - startOfToday) / MS_PER_DAY);
+}
+
+export default function PaydayCountdown() {
+  const days = daysUntilPayday(new Date());
+  return (
+    <p className="payday-countdown">
+      Payday in {days} {days === 1 ? 'day' : 'days'}
+    </p>
+  );
+}
+

Review this PR

React practice