-
Notifications
You must be signed in to change notification settings - Fork 0
/
spreadsheet.gs
50 lines (42 loc) · 1.67 KB
/
spreadsheet.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function getCurrentDeadline(seed) {
const topLeftStartingCellOfDeadlines = {
column: 7,
row: 2
};
const currentCellOfDeadline = SpreadsheetApp.getActiveRange().getCell(1, 1);
const currentCellOfDeadlinesNormalizedAddress = {
column: currentCellOfDeadline.getColumn() - topLeftStartingCellOfDeadlines.column,
row: currentCellOfDeadline.getRow() - topLeftStartingCellOfDeadlines.row
};
const currentUserShift = {
rowsToAdd: Math.floor(currentCellOfDeadlinesNormalizedAddress.column / 2),
columnsToAdd: 0
};
const topLeftStartingCellOfChallengeStarts = {
column: 25,
row: 2
}
const topLeftStartingCellOfTasksPerDay = {
column: 26,
row: 2
};
const currentCellOfChallengeStarts =
SpreadsheetApp.getActiveSheet().getRange(
topLeftStartingCellOfChallengeStarts.row + currentUserShift.rowsToAdd,
topLeftStartingCellOfChallengeStarts.column + currentUserShift.columnsToAdd
);
const challengeStartedAt = currentCellOfChallengeStarts.getValue();
const currentCellOfTasksPerDay =
SpreadsheetApp.getActiveSheet().getRange(
topLeftStartingCellOfTasksPerDay.row + currentUserShift.rowsToAdd,
topLeftStartingCellOfTasksPerDay.column + currentUserShift.columnsToAdd
);
const tasksPerDayAmount = currentCellOfTasksPerDay.getValue();
const daysToAddToChallengeStartDate = Math.floor(
currentCellOfDeadlinesNormalizedAddress.row / tasksPerDayAmount
);
const isLastTaskOfDay = currentCellOfDeadlinesNormalizedAddress.row % tasksPerDayAmount === tasksPerDayAmount - 1;
if(isLastTaskOfDay) {
return new Date(challengeStartedAt.getTime() + daysToAddToChallengeStartDate * 24 * 60 * 60 * 1000)
}
}