Skip to content

Instantly share code, notes, and snippets.

@pnmcosta
Created February 7, 2018 11:13
Show Gist options
  • Save pnmcosta/6624ec3fc077370a9e7b439e0548aee0 to your computer and use it in GitHub Desktop.
Save pnmcosta/6624ec3fc077370a9e7b439e0548aee0 to your computer and use it in GitHub Desktop.
Get all sundays from current month till years end (Node.js)
var template = `Dia: {0}
Hora inicio: 08h00
Briefing: 08h30
Fim: 12h30
Duração: 04h00m
\r\n`;
var monthNames = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
"Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
];
const fs = require('fs');
var d = new Date();
var m = d.getMonth();
var y = d.getFullYear();
var stream = fs.createWriteStream("calendario.txt", { flags: 'a' });
for (; m < 12; m++) {
var t = new Date(y, m + 1, 0).getDate();
for (var i = 1; i <= t; i++) {
var ds = new Date(y + "-" + (m + 1) + "-" + i);
if (ds.getDay() == 0) {
console.log("Sunday", ds.toISOString());
stream.write(template.replace('{0}', ds.getDate() + ' ' + monthNames[ds.getMonth()] + ' ' + ds.getFullYear()));
}
}
}
stream.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment