-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.gs
77 lines (68 loc) · 2.34 KB
/
Helper.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function initUI()
{
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Insert Duties", functionName: "insertDuties"});
menuEntries.push({name: "Insert Away Dates", functionName: "insertAwayDates"});
menuEntries.push({name: "Insert Away Date Constraints", functionName: "insertAwayDateContraints"});
menuEntries.push({name: "Update Duty Constraints", functionName: "updateDutyConstraints"})
menuEntries.push({name: "Update Candidates for Duties", functionName: "updateCandidatesForDuties2"});
menuEntries.push({name: "Calculate Plan", functionName: "calculatePlan"});
menuEntries.push({name: "Write Away Date Summary", functionName: "awayDateSummary"});
spreadsheet.addMenu('Plan', menuEntries);
}
function onOpen()
{
this.initUI();
}
function getStartDate(){
var sheet = spreadsheet.getSheetByName('Options');
var dateString = sheet.getRange(1, 2).getValue();
var startDate = new Date(dateString);
return startDate;
}
function getEndDate(){
var sheet = spreadsheet.getSheetByName('Options');
var dateString = sheet.getRange(2, 2).getValue();
var endDate = new Date(dateString);
return endDate;
}
function getFirstGivenDayOfWeekAfterDate(dayOfWeek,date){
while (date.getDay() != dayOfWeek)
{
date = addDaysToDate(1,date);
}
return date;
}
function addDaysToDate(days,date){
var newDate = new Date(date);
newDate.setTime(newDate.getTime() + 86400000 * days);
newDate.setTime(newDate.getTime() + 43200000); //add half a day
newDate.setHours(0); //and set the hour to zero (to account for daylight savings)
return newDate;
}
function datesAreEqual(date1,date2) {
if ((date1.getDate() == date2.getDate()) && (date1.getMonth() == date2.getMonth()) && (date1.getFullYear() && date2.getFullYear())) {
return true;
}
else {
return false;
}
}
function writeArrayToSheet(dataArray,sheetName) {
var sheet = spreadsheet.getSheetByName(sheetName);
for (var i = 0; i < dataArray.length; i++) {
for (var j = 0; j < dataArray[i].length; j++) {
sheet.getRange(i + 1, j + 1).setValue(dataArray[i][j]);
}
}
}
function readArrayFromSheet(sheetName) {
var sheet = spreadsheet.getSheetByName(sheetName);
if (sheet.getLastRow() > 0) {
return sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();
}
else {
return [];
}
}