Reputation: 273
i will manage my calender about a simply script which is moving calender items 60 minutes further.
For this feature is take this Google Apps Script:
function myFunction() {
var cal = CalendarApp.getCalendarById("[email protected]");
cal.createEvent("TTIITTEELL", new Date("02/06/2018 18:00:00"), new Date("02/06/2018 19:00:00"));
var events = cal.getEvents(new Date("02/05/2018"), new Date("02/07/2018"));
for (var i=0;i<events.length;i++) {
if (events[i].getTitle() == "TTIITTEELL") {
var t = events[i].getEndTime();
var text = new Date(events[i].getEndTime()+.........);
}
}
}
The script is running, but i don´t find the logig to create a new Time.
When i take a "+" it is calculation a minus and so - here are some examples:
Take: +5 = from: Tue Feb 06 2018 19:00:00 GMT+0100 (MEZ) --> to: Tue Feb 06 2018 18:55:00 GMT+0100 (MEZ)
Take: -5 = from: Tue Feb 06 2018 19:00:00 GMT+0100 (MEZ) --> to: Tue Feb 06 2018 18:59:59 GMT+0100 (MEZ)
Take: +60 = from: Tue Feb 06 2018 19:00:00 GMT+0100 (MEZ) --> to: Invalid Date
Take: -60*60*24*1000*1000 = from: Tue Feb 06 2018 19:00:00 GMT+0100 (MEZ) --> to: Wed May 13 2015 20:00:00 GMT+0200 (MESZ)
Take: +60*60*24*1000*1000 = from: Tue Feb 06 2018 19:00:00 GMT+0100 (MEZ) --> to: Invalid Date
Where is my mistake?
Upvotes: 0
Views: 97
Reputation: 201438
How about this answer? In your script, events[i].getEndTime()
is an object for date. So when the number is added to the object, it dosn't become the result what you want. When you want the addition and subtraction, you can use the following script. Please modify as follows.
var t = events[i].getEndTime();
var text = new Date(events[i].getEndTime()+.........);
In this case, as a sample, I set the unit of +5, -5, +60, -60
to "minutes".
var num = 5; // Please input 5, -5, 60, -60, ...
var t = events[i].getEndTime().getTime();
var text = new Date(t + num * 60 * 1000);
If I misunderstand your question, I'm sorry.
Upvotes: 1