0

I'm using Node (specifically the node-outlook npm module) to pull through my Outlook.com calendar and the base request is working. I'm getting back results from the API, but I'm having trouble with the oData request parameters to only reutrn results for today. Here's what I've got:

 var queryParams = {
    '$select': 'Subject,Start,End',
    '$orderby': 'Start/DateTime desc',
    //'$top': 10,
    'startDateTime': startDateString,
    'endDateTime': endDateString
    //'$filter': "Start/DateTime ge " + startDateString + " and Start/DateTime le " + endDateString

};

outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');
outlook.base.setAnchorMailbox(<my email address>);
outlook.base.setPreferredTimeZone('Europe/London');

outlook.calendar.getEvents({token:token, odataParams: queryParams},function(error, result){
    //Do some stuff with the event data here
}

However, if I use the parameters are shown above (where startDateString is 2016-10-28T00:00:00 and endDateString is 2016-10-28T23:59:59) I'm still getting back events both in the past and in the future.

This isn't what I want - what I was hoping to do was just pull through the current days events (hence the attempt at useing the oData $filter, but the API doesn't seem to like that and it moans about incompatible binary operators).

Can anyone advise what I need to amend in the params to just get back events scheduled for today?

Thanks

EDIT: Here's an example of what I'm getting returned:enter image description here

LDJ
  • 6,896
  • 9
  • 52
  • 87

2 Answers2

1

StartDateTime and EndDateTime properties are represented as DateTimeTimeZone values When creating or updating event the value (which includes time zone information):

"StartDateTime": {
   "DateTime": "2016-10-28T00:00:00",
   "TimeZone": "Europe/London" //current time zone
}  

is getting converted to UTC value:

"StartDateTime": {
   "DateTime": "2016-10-27T23:00:00",  
   "TimeZone": "UTC" 
}  

The same applies to filtering operation. That is the reason why startDateString and endDateTime values should be converted from local time to UTC for getting today events.

For example, using Moment.js library:

var startDateStringUtc = moment(startDateString).toISOString();
var endDateStringUtc= moment(endDateString).toISOString();

var queryParams = {
    '$select': 'Subject,Start,End',
    '$orderby': 'Start/DateTime desc',
    //'$top': 10,
    'startDateTime': startDateStringUtc,
    'endDateTime': endDateStringUtc
    //'$filter': "Start/DateTime ge " + startDateString + " and Start/DateTime le " + endDateString

};

About DateTimeTimeZone structure

According to MSDN:

Describes the date, time, and time zone of a point in time.

  • DateTime DateTime A single point of time in a combined date and time representation (T) according to ISO 8601 format.
  • TimeZone String One of the following time zone names.

How to determine timezone when the event was created

OriginalStartTimezone and OriginalEndTimezone are meant to reflect what timezone was set when the event was created or updated

Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • I just tried this and its still pulling back past and future events....the values are 2016-10-31T00:00:00.000Z and 2016-10-31T23:59:59.000Z using the above code – LDJ Oct 31 '16 at 06:55
1

Figured it out (or at least this SO question did it for me)

It turns out the times need to be enclosed in quotes!

var queryParams = {
                '$orderby': 'Start/DateTime desc',
                '$filter': "Start/DateTime ge '" + startDateString + "' and Start/DateTime le '" + endDateString + "'"

            };

And now its working.

Grrr!

Community
  • 1
  • 1
LDJ
  • 6,896
  • 9
  • 52
  • 87