Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a DateTime object I create and DateTime.Now

I'm trying to use the Exchange 2007 API to query calendar availability for a specific user. My sample code is producing the following exception:

The time duration specified for FreeBusyViewOptions.TimeWindow is invalid.

Here's the sample code:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

service.AutodiscoverUrl("[email protected]");

DateTime startTime = new DateTime(2012, 1, 6, 7, 0, 0);

TimeWindow tw = new TimeWindow(startTime, startTime.AddHours(8));

GetUserAvailabilityResults result = service.GetUserAvailability(new List<AttendeeInfo> { new AttendeeInfo("[email protected]") }, tw, AvailabilityData.FreeBusyAndSuggestions);

The wierd thing is, if I replace my startTime assignment with the following it works:

DateTime startTime = DateTime.Now;

What's the difference between the DateTime object I created and the object produced by DateTime.Now. I've examined them in detail while debugging and can't find a difference.

Any ideas?

like image 699
joshb Avatar asked Jan 05 '12 22:01

joshb


2 Answers

This actually appears to be an issue in the GetUserAvailability method as opposed to any DateTime manipulation.

According to the MSDN documentation:

The GetUserAvailability(Generic ,TimeWindow,AvailabilityData,AvailabilityOptions) method supports only time periods that are a minimum of 24 hours long and that begin and end at 12:00a.m. To restrict the results of the method to a shorter time period, you must filter the results on the client.

like image 102
competent_tech Avatar answered Nov 15 '22 15:11

competent_tech


Maybe it has something to do with the difference between your time zone and UTC, producing a negative time window. Try increasing from AddHours(8) to bigger values up to AddHours(24) and see what happens.

like image 20
Ilya Kogan Avatar answered Nov 15 '22 16:11

Ilya Kogan