Pages

Fin TD : 📅 calendrier / logique

 Logique


code 1 


Date

Array

Set()

boucle

test

code 2



attention aux variables et constantes

code 3


Array.from

Array.splice

Math.ceil|floor

Array of Array

code 4

Map()





const calendrier = [],
OFFSET_MONTH = new Map([[1, 6], [2, 0], [3, 1], [4, 2], [5, 3], [6, 4], [0, 5],]),
MONTH = 2,
YEAR = 2025,
firstOfMonth = new Date(YEAR, MONTH, 1),
dayFirst = firstOfMonth.getDay(),// Sunday - Saturday : 0 - 6
dec = OFFSET_MONTH.get(dayFirst);
console.log(dayFirst)
for (let i = 0; i < 42; i++) {
calendrier.push({ date: new Date(YEAR, MONTH, i - dec) })
}
console.table(calendrier);
const options = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' };
console.log(`📅 ${firstOfMonth.toLocaleDateString('fr-CA', { month: 'short', year: 'numeric' })}
Du ${calendrier[0].date.toLocaleDateString('fr-CA', options)}
au ${calendrier[41].date.toLocaleDateString('fr-CA', options)}`)
view raw calendrier4.js hosted with ❤ by GitHub