简体   繁体   English

来自工作表脚本的 Google 日历活动提前一天结束

[英]Google Calendar event from sheets script ends a day early

I have a sheets file that creates a calendar event when a button is clicked.我有一个工作表文件,当单击按钮时会创建一个日历事件。 The calendar event is based off of a user entered due date, and script created start date, a entered location, and an entered description all pulled from certain cells in the spreadsheet.日历事件基于用户输入的截止日期、脚本创建的开始日期、输入的位置和输入的描述,这些都是从电子表格中的某些单元格中提取的。 The problem is that when I go to the calendar the event ends a day before the due date (or beginning of the day of the due date) and I want it to show for the entire due date.问题是当我 go 到日历时,事件在截止日期前一天(或截止日期的开始)结束,我希望它显示整个截止日期。 For example if I enter a due date of july 17th into the spreadsheet, when I create the calendar event it only runs through the 16th.例如,如果我在电子表格中输入了 7 月 17 日的截止日期,那么当我创建日历事件时,它只会运行到 16 日。 Is there a way to get the events to schedule to the end of the day or an easy way to just offset the end date by one day in the script.有没有办法让事件安排到一天结束,或者有一种简单的方法可以在脚本中将结束日期偏移一天。

  var Description = sheetTemplate.getRange('B12').getValue(); //gets discription from Cell B12
  var Location = sheetTemplate.getRange('C5') .getValue();  //gets location of work order from cell C5
  var StartDate = sheetTemplate.getRange('C4').getValue();  //Start Date from Cell C4
  var DueDate = sheetTemplate.getRange('E5').getValue();    //Gets Due Date From Cell E5


     //This portion of the code schedules the WO on the calendar//

var eventCal = CalendarApp.getCalendarById("XXXXX") ;//Get the Maintenance Calendar
var options = { 'location': Location, 
             'description':Description
            } //sets event details

var WOevent = eventCal.createAllDayEvent(WOname,StartDate,DueDate,options);//creates a calendar event

WOevent.setColor('10') // sets the color of the calendar event to green

You have two options你有两个选择

  • Either you manually add a day to the dueDate您可以手动将一天添加到到期日期

This can be done with new Date(ms) :这可以通过new Date(ms)来完成:

var DueDate = sheetTemplate.getRange('E5').getValue(); 
DueDate = new Date(DueDate.getTime() + 24*60*60*1000);

This allows you to specify the end time on the DueDate:这允许您指定 DueDate 的结束时间:

var DueDate = sheetTemplate.getRange('E5').getValue();
DueDate = new Date(DueDate);
DueDate.setHours(23);
DueDate.setMinutes(59);
var WOevent = eventCal.createEvent(WOname,StartDate,DueDate,options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM