Skip to content

Instantly share code, notes, and snippets.

@jdgabriel
Created January 21, 2022 20:43
Show Gist options
  • Save jdgabriel/05cea56ac0db6c3b4e80109c73ad9129 to your computer and use it in GitHub Desktop.
Save jdgabriel/05cea56ac0db6c3b4e80109c73ad9129 to your computer and use it in GitHub Desktop.
Calendar with MomentJS
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