Skip to content

Commit

Permalink
fix: check if lunch date is this week
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
Adam Simpson committed Mar 24, 2016
1 parent a2e203c commit b4180c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
25 changes: 15 additions & 10 deletions src/generalAnnouncement.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ const getData = () => {
const parseData = (data) => {
const dates = getDateColumn(data);
const next = getNextLunch(dates);
const names = parseNames(data, next);
const slackNames = returnSlackNames(names, namesObj);
const formattedNames = formatSlackNames(slackNames).toString();
const msg = `
<@dayton> ${formattedNames} are scheduled to help with lunch on Friday.
${process.env.sheetUrl}
`;

postToSlack('#general', msg);
const today = new Date();
//1000 * 3600 * 24 is milliseconds in 1 day
const dayInMilliseconds = 1000 * 3600 * 24;
if ((next - today) / (dayInMilliseconds) < 7) {
const names = parseNames(data, next);
const slackNames = returnSlackNames(names, namesObj);
const formattedNames = formatSlackNames(slackNames).toString();
const msg = `
<@dayton> ${formattedNames} are scheduled to help with lunch on Friday.
${process.env.sheetUrl}
`;

postToSlack('#general', msg);
}
};

const formatSlackNames = (names) => {
Expand Down
25 changes: 15 additions & 10 deletions src/privateReminder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ const getData = () => {
const parseData = (data) => {
const dates = getDateColumn(data);
const next = getNextLunch(dates);
const names = parseNames(data, next);
const slackNames = returnSlackNames(names, namesObj);
const msg = `
You are scheduled to help with lunch on Friday with ${names}.\n If you are unable to do so please find a replacement and update the spreadsheet.
${process.env.sheetUrl}
`;
const today = new Date();
//1000 * 3600 * 24 is milliseconds in 1 day
const dayInMilliseconds = 1000 * 3600 * 24;
if ((next - today) / (dayInMilliseconds) < 7) {
const names = parseNames(data, next);
const slackNames = returnSlackNames(names, namesObj);
const msg = `
You are scheduled to help with lunch on Friday with ${names}.\n If you are unable to do so please find a replacement and update the spreadsheet.
slackNames.forEach((helper) => {
postToSlack(`@${helper}`, msg);
});
${process.env.sheetUrl}
`;

slackNames.forEach((helper) => {
postToSlack(`@${helper}`, msg);
});
}
};

const date = new Date();
Expand Down

0 comments on commit b4180c2

Please sign in to comment.