Reputation: 3
Here is the code:
const calendar = google.calendar({ version: 'v3', auth });
const meetingsResponse = await calendar.events.list({
calendarId: 'primary',
timeMin: new Date(new Date().setHours(0,0,0,0)).toISOString(),
maxResults: 1,
singleEvents: true,
orderBy: 'startTime',
});
Output: ?
Do someone know where is the problem?
Upvotes: 0
Views: 586
Reputation: 5953
You can set the timeMax to the current datetime to get a list of ended events. If you really want to get only 1 result (latest ended event) you can retain maxResults to 1
timeMax
timeMin
For Example:
timeMax = 2020-12-23T11:00:00Z (datetime now)
Event 1 start time = 2020-12-22T08:00:00Z
Event 2 start time = 2020-12-23T14:00:00Z
In your code, when you use timeMin to filter the dates, you are saying that the minimum datetime that the event's end time should be now. Hence, events.list() will return the events that has end time greater than the timeMin(now) which are events that are not yet ended.
Sample:
timeMax = 2020-12-23T11:00:00Z
Response (deleted some unnecessary information):
{
....
"items": [
{
"kind": "calendar#event",
"summary": "ended event 1",
"start": {
"dateTime": "2020-12-22T20:30:00+08:00"
},
"end": {
"dateTime": "2020-12-22T21:00:00+08:00"
}
},
{
"kind": "calendar#event",
"summary": "ended event 2",
"start": {
"dateTime": "2020-12-20T16:00:00+08:00"
},
"end": {
"dateTime": "2020-12-20T16:30:00+08:00"
}
},
{
"kind": "calendar#event",
"summary": "ended event 3",
"start": {
"dateTime": "2020-12-21T11:00:00+08:00"
},
"end": {
"dateTime": "2020-12-21T11:30:00+08:00"
}
}
]
}
Upvotes: 1