diff --git a/src/components/Newsletter/Newsletter.tsx b/src/components/Newsletter/Newsletter.tsx index 774fe1ddfba6cf336ecf02de25fadb3caac4c340..410ca99964aadb383e29812f98b7d46347093b76 100644 --- a/src/components/Newsletter/Newsletter.tsx +++ b/src/components/Newsletter/Newsletter.tsx @@ -30,14 +30,18 @@ export type ContentItems = | '' const Newsletter: React.FC = () => { - // Functional rule : - // Display next month after the 3rd of the current month + /** + * Display previous month until the newsletter is sent on the 3rd day of the month + */ const getCurrentNewsletterDate = (): Date => { - const newsletterDate = new Date() - if (newsletterDate.getDate() >= 3) { - newsletterDate.setMonth(newsletterDate.getMonth() + 1) - } - return newsletterDate + const today = new Date() + const currentDay = today.getDate() + const currentMonth = today.getMonth() + const currentYear = today.getFullYear() + + return currentDay < 3 + ? new Date(currentYear, currentMonth, 1) + : new Date(currentYear, currentMonth + 1, 1) } const [date, setDate] = useState<Date>(getCurrentNewsletterDate())