From 04f24cf0785cdd84cd86bb0af748cfdb27c530af Mon Sep 17 00:00:00 2001 From: zenparsing Date: Tue, 23 Nov 2021 16:19:43 -0500 Subject: [PATCH] Correct month-end date for rewards NTP widget --- .../resources/shared/components/newtab/rewards_card.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/brave_rewards/resources/shared/components/newtab/rewards_card.tsx b/components/brave_rewards/resources/shared/components/newtab/rewards_card.tsx index 751d8538c761..7a4a3f45a2e3 100644 --- a/components/brave_rewards/resources/shared/components/newtab/rewards_card.tsx +++ b/components/brave_rewards/resources/shared/components/newtab/rewards_card.tsx @@ -35,7 +35,13 @@ const monthDayFormatter = new Intl.DateTimeFormat(undefined, { function renderDateRange () { const now = new Date() const start = new Date(now.getFullYear(), now.getMonth(), 1) - const end = new Date(start.getFullYear(), start.getMonth() + 1, -1) + + // To get the last day of the month, we can create a date for the next month, + // (months greater than 11 wrap around) with the day part set to 0 (one before + // the first day of the month). The Date constructor will perform the offset + // for us. + const end = new Date(start.getFullYear(), start.getMonth() + 1, 0) + return ( <>{monthDayFormatter.format(start)} - {monthDayFormatter.format(end)} )