Skip to content
Snippets Groups Projects

Fix: open correct month for newsletter editing

Merged Rémi PAILHAREY requested to merge dev into master
1 file
+ 11
7
Compare changes
  • Side-by-side
  • Inline
@@ -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())
Loading