Difference between created DateTime object and DateTime.Now

I am trying to use the Exchange 2007 API to request calendar availability for a specific user. In my sample code, the following exception is thrown:

The length of time specified for FreeBusyViewOptions.TimeWindow is not valid.

Here is an example code:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.AutodiscoverUrl(" email@domain.com "); 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@domain.com ") }, tw, AvailabilityData.FreeBusyAndSuggestions); 

The strangest thing is if I replace the startTime destination with the following:

 DateTime startTime = DateTime.Now; 

What is the difference between the created DateTime object and the object created by DateTime.Now. I studied them in detail during debugging and did not find the difference.

Any ideas?

+6
source share
6 answers

This is really a problem in the GetUserAvailability method, unlike any DateTime manipulation.

According to MSDN documentation :

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

+21
source

Perhaps this has something to do with the difference between your time zone and UTC, creating a negative time window. Try increasing from AddHours (8) to larger values ​​to AddHours (24) and see what happens.

+2
source

Indicate the view so that it is identical to Now:

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

With some of the odds that you really need Utc. Perhaps depends on the server configuration.

+2
source

I find out that the specified TimeWindow must contain at least one midnight. But I do not know why.

+2
source

Kind is different. It may be what he is looking for.

 new DateTime(2012, 1, 6, 7, 0, 0) 

has the form "Unspecified".

Till

 DateTime.Now 

has the form of "local".

Try using ToLocalTime to set the view to local:

 DateTime startTime = new DateTime(2012, 1, 6, 7, 0, 0).ToLocalTime(); 
+1
source

Take a look at the constructors and code for the DateTime class.

They all modify the private variable:

 private ulong dateData; 

So, all the constructors are the same, and DateTime.Now is an open static method that returns an instance of the DateTime class that does the same.

The error message indicated:

Invalid time duration specified for FreeBusyViewOptions.TimeWindow.

This is because it is not valid!

You will enter a date in the future and most likely check it. Try with the current date.

0
source

Source: https://habr.com/ru/post/905258/


All Articles