mardi 4 septembre 2018

Outlook.Interop Items.Find() doesn't seem to match correct

I want to search my Outlook calendar and shared calendars in my Network for appointments to check if there is a free time slot in the different calendars.

It was no problem to get all the Appointment-Items of the calendars which I prefiltered using Items.Restrict(string Filter) to only get Items from Today or newer. My searchpattern looks like that:

"[Start] >= '" + DateTime.Today.ToString("dd.MM.yyyy HH:mm") + "' AND [End] <= '" + DateTime.Parse("01.01.2019").ToString("dd.MM.yyyy HH:mm") + "'";

Everything works fine (Had problems with the Time format dd.MM.yyyy vs. dd/MM/yyyy but this was solved).

After I got my items, I search them to check if the appointment time is free or not, means: If the start or end time overlap with an appointment or if there is an appointment between the start and end time in any of the calendars then, if found, return that appointment, else return null.

This is my search pattern ({0} is temporary start time and {1} is temporary end time):

"(([Start] <= '{0}' AND '{0}' <= [End]) OR 
([Start] <= '{1}' AND '{1}' <= [End])) OR 
(('{0}' <= [Start] AND [Start] <= '{1}') OR 
('{0}' <= [End] AND [End] <= '{1}'))";

For my test I made an appointment Today from 08:00 to 08:30 and searched for the next appointment starting the search at 15:18. So the search should return null because it should not find a time overlap, but it returns the test appointment from the morning.

If I replace the values in the search string with my times and the times of the found appointment ({0} -> 15:18, {1} -> 16:18, [Start] -> 08:00, [End] -> 08:30) I got this:

((04.09.2018 08:00:00 <= '04.09.2018 15:25:09' AND '04.09.2018 15:25:09' <= 04.09.2018 08:30:00) OR (04.09.2018 08:00:00 <= '04.09.2018 16:25:09' AND '04.09.2018 16:25:09' <= 04.09.2018 08:30:00)) 
OR (('04.09.2018 15:25:09' <= 04.09.2018 08:00:00 AND 04.09.2018 08:00:00 <= '04.09.2018 16:25:09') OR ('04.09.2018 15:25:09' <= 04.09.2018 08:30:00 AND 04.09.2018 08:30:00 <= '04.09.2018 16:25:09'))

Checking the logic-statements :

//False OR False is False
(
    //False OR False is False
    (
        //True AND False is False
        (
            //Is True
            04.09.2018 08:00:00 <= '04.09.2018 15:25:09' 
            AND 
            //Is False
            '04.09.2018 15:25:09' <= 04.09.2018 08:30:00
        ) 
        OR 
        //True AND False is False
        (
            //Is True
            04.09.2018 08:00:00 <= '04.09.2018 16:25:09'
            AND 
            //Is False
            '04.09.2018 16:25:09' <= 04.09.2018 08:30:00
        )
    ) 
    OR
    //Fals OR Fals is False 
    (
        //False AND True is False
        (
            //Is Fale
            '04.09.2018 15:25:09' <= 04.09.2018 08:00:00 
            AND 
            //Is True
            04.09.2018 08:00:00 <= '04.09.2018 16:25:09'
        ) 
        OR 
        //False AND True is False
        (
            //Is False
            '04.09.2018 15:25:09' <= 04.09.2018 08:30:00 
            AND 
            //Is True
            04.09.2018 08:30:00 <= '04.09.2018 16:25:09'
        )
    )
)

I just don't get why this Search pattern returns True for that appointment which is not even near the checked time.

If I have no other appointments on that day it works (returning null, not an appointment from the next day).

I already checked the problem with the time-formatting (dd.MM.yyyy vs. dd/MM/yyyy etc.) so I guess that is not the cause of the behaviour (If I use '/' with seconds then the search pattern returns an appointment from Tomorrow, if I use '.' with seconds it returns the Today's appointment).

Is my search pattern wrong? Did I oversee something or is it the time-formatting which works different in the background?

Any ideas? Thanks.

Aucun commentaire:

Enregistrer un commentaire