'How can I receive the current displayed week of google calendar with app-script?
I cannot find any property receiving the currently for the user displayed calendar week with google apps-script here
What I want to do is: Extract the start and end date of the days displayed for the user in google-calendar.
What I already archive is to get events of the current week's Monday (so from the perspective of today):
getEventsOfThisWeek(calendarId) {
calendar = CalendarApp.getCalendarById(calendarId);
let referenceDay = new Date(); //here I would like to get a day from displayed week
let monday = this.getMondayMidnightAM(referenceDay);
let friday = theís.getFridayMidnightPM(referenceDay)
let events = calendar.getEvents(monday, friday );
return events
}
getMondayMidnightAM(ref) {
let day = ref.getDay();
let diff = ref.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday
ref.setDate(diff);
let mondayMidnight = new Date(ref.toISOString().replace(/T\S{8}/, "T00:00:00"));
return mondayMidnight;
}
So far I understood, that isSelected()
tells me not if the event is on screen in the current view, but rather if the display in all the calendar option is on.
Solution 1:[1]
In Short: It is not possible.
- The problem with the calendar page you see as a user is that if multiple users have access to the same (e.g. group) calendar, every user might look at at different week.
- The script can only access server-side data that is the same for every user (e.g. event name, guests etc.).
- Only an Addon can access some specific information that only the user who installed the Addon sees.
- This information is contained in object events that become available when a manifest or contextual trigger get fired - e.g. when a user creates or edits an event
- However, as you can see in the documentation the Calendar Event Objects do not comprise any information about the currently open week, so there is no way to get this information programamtically
- Maybe it is possible to get this data through webscraping, whereby I would not be able to tell you if and how this can be done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | helle |