Created
January 21, 2022 20:43
-
-
Save jdgabriel/05cea56ac0db6c3b4e80109c73ad9129 to your computer and use it in GitHub Desktop.
Calendar with MomentJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const moment = require("moment"); | |
| const fs = require("fs"); | |
| let calendar = []; | |
| const today = moment(); | |
| const startDay = today.clone().startOf("month").startOf("week"); | |
| const endDay = today.clone().endOf("month").endOf("week"); | |
| let date = startDay.clone().subtract(1, "day"); | |
| while (date.isBefore(endDay, "day")) | |
| calendar.push( | |
| Array(7) | |
| .fill(0) | |
| .map(() => date.add(1, "day").clone()) | |
| ); | |
| let days = []; | |
| calendar.map((week) => { | |
| return week.map((day) => { | |
| days.push({ | |
| day: moment(day).format("D").toString(), | |
| actions: [], | |
| }); | |
| }); | |
| }); | |
| // Export in JSON File the result of days in month | |
| // fs.writeFileSync("calendar.json", JSON.stringify(days)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment