好的,所以我用 Google Apps Script 深入了解了一下。在工作中,我们有一周的固定时间轮班。三种类型的班次可以是早班(上午 7 点至下午 3.30)、中班(上午 8 点至下午 5 点)和晚班(上午 10.30 至晚上 7 点)。
我要做的是生成一个带有日期选择器和 3 个按钮的 UI,每个班次一个。这个想法是您在日期选择器上单击星期一,然后单击一个班次按钮,它会生成 5 个班次(一周中的每一天一个班次)并将它们作为事件添加到我的 Google 日历中。
我可以获得生成事件的函数,但我无法将日期选择器的输入与每个函数的日期联系起来。有什么方法可以分割事件的日期和时间吗?理想情况下,时间将“硬编码”到脚本中,因此无法更改,但用户可以选择日期。
我希望这一切都有意义,代码如下:
// loads the UI
function doGet() {
var app = UiApp.createApplication();
var label1 = app.createLabel("To use this application, select a Monday and then hit the Early Middle or Late button");
app.add(label1);
var label2 = app.createLabel("5 events will be created from the start date across five days");
app.add(label2);
var picker = app.createDatePicker().setId("picker");
var handler = app.createServerHandler("change");
app.add(picker);
var button1 = app.createButton("Early").setId("button1");
button1.addClickHandler(app.createServerHandler("early"));
app.add(button1);
var button2 = app.createButton("Middle").setId("button2");
button2.addClickHandler(app.createServerHandler("middle"));
app.add(button2);
var button3 = app.createButton("Late").setId("button3");
button3.addClickHandler(app.createServerHandler("late"));
app.add(button3);
return app;
};
//Handles date picker changes
function change(eventInfo) {
var app = UiApp.getActiveApplication();
app.add(app.createLabel("The value of the date picker changed to " + eventInfo.parameter.picker));
return app;
};
//Generates the events
function early(){
var cal = CalendarApp.getDefaultCalendar();
var title = "Computacenter";
var start = new Date("July 21, 2012 07:00:00");
var end = new Date("July 21, 2012 15:30:00");
var loc = "Unspecified";
var recurrence = CalendarApp.newRecurrence().addDailyRule().times(5);
var event = cal.createEventSeries(title, start, end, recurrence, {location : loc});
};
function middle(){
var cal = CalendarApp.getDefaultCalendar();
var title = "Computacenter";
var start = new Date("July 21, 2012 08:30:00");
var end = new Date("July 21, 2012 17:00:00");
var loc = "Unspecified";
var recurrence = CalendarApp.newRecurrence().addDailyRule().times(5);
var event = cal.createEventSeries(title, start, end, recurrence, {location : loc});
};
function late(){
var cal = CalendarApp.getDefaultCalendar();
var title = "Computacenter";
var start = new Date("July 21, 2012 10:30:00");
var end = new Date("July 21, 2012 19:00:00");
var loc = "Unspecified";
var recurrence = CalendarApp.newRecurrence().addDailyRule().times(5);
var event = cal.createEventSeries(title, start, end, recurrence, {location : loc});
};