Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Last active January 5, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/f14b99c7c10aad1a0966d2c247ce2307 to your computer and use it in GitHub Desktop.
Save cosminpopescu14/f14b99c7c10aad1a0966d2c247ce2307 to your computer and use it in GitHub Desktop.
const neatCsv = require('neat-csv');
const fs = require('fs')
const file = "C:\\Users\\cosmi\\Desktop\\events.csv";
fs.readFile(file, async (err, data) => {
if (err) {
console.error(err)
return
}
let content = await neatCsv(data)
const weekly = content.filter(f => f.Schedule.includes("Weekly"));
const monthly = content.filter(f => f.Schedule.includes("Monthly"));
const recurrence = {
"weekly" : 7,
"monthly30" : 30,
"monthly31" : 31
};
const weaklyBasisEvents = weekly.map((element => getDates(new Date(), new Date("June 29, 2020 13:00:00"), recurrence.weekly)));
const monthlyBasisEvents = monthly.map((element => getDates(new Date(), new Date("June 29, 2020 13:00:00"), recurrence.monthly30)));
console.log(weaklyBasisEvents);
console.log("------------------");
console.log(monthlyBasisEvents);
});
function getDates(start, end, recurrence) {
let date = start;
let dates = [];
while((date = addDays(date, recurrence)) < end) {
dates.push(date);
}
return dates;
}
function addDays(date, days) {
let newDate = new Date(date);
newDate.setDate(date.getDate() + days);
return newDate;
}
Starts Ends Schedule
9/23/2019 12:00:00 PM 9/23/2019 1:00:00 PM Weekly on Monday, until June 29, 2020
1/8/2020 12:00:00 PM 1/8/2020 1:00:00 PM Once
10/17/2019 12:00:00 PM 10/17/2019 1:00:00 PM Weekly on Thursday, until April 2
10/18/2019 12:00:00 PM 10/18/2019 1:00:00 PM Weekly on Friday, until April 10
1/31/2020 12:00:00 PM 1/31/2020 1:00:00 PM Once
1/17/2020 12:00:00 PM 1/17/2020 1:00:00 PM Once
1/24/2020 12:00:00 PM 1/24/2020 1:00:00 PM Once
10/3/2019 12:00:00 PM 10/3/2019 1:00:00 PM Weekly on Thursday, until April 30, 2020
1/24/2019 9:30:00 AM 1/24/2019 11:30:00 AM Weekly on Thursday, for a year
9/17/2019 1:00:00 PM 9/17/2019 3:00:00 PM Weekly on Tuesday, until May 26, 2020
1/14/2020 4:00:00 PM 1/14/2020 5:00:00 PM Once
10/22/2019 11:30:00 AM 10/22/2019 1:00:00 PM Weekly on Tuesday, until May 19, 2020
2/20/2019 6:00:00 PM 2/20/2019 9:00:00 PM Weekly on Wednesday, for a year
1/20/2020 12:00:00 AM 1/21/2020 12:00:00 AM Once
9/3/2019 12:00:00 PM 9/3/2019 1:00:00 PM Weekly on Tuesday, until May 19, 2020
9/9/2019 12:00:00 PM 9/9/2019 1:00:00 PM Weekly on Monday, until May 18, 2020
1/1/2020 12:00:00 AM 1/2/2020 12:00:00 AM Once
9/18/2019 12:00:00 PM 9/18/2019 1:00:00 PM Weekly on Wednesday, until May 27, 2020
1/29/2020 4:00:00 PM 1/29/2020 5:00:00 PM Once
1/24/2020 1:15:00 PM 1/24/2020 2:15:00 PM Once
1/10/2020 1:15:00 PM 1/10/2020 2:15:00 PM Once
1/8/2019 5:30:00 PM 1/8/2019 6:30:00 PM Weekly on Tuesday, until January 19, 2021
1/17/2019 1:00:00 PM 1/17/2019 2:30:00 PM Monthly on the third Thursday, until January 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment