We have a Visual Studio workflow that I built with VS2013 and running on SharePoint 2013 (it is a SP2013 workflow).
The workflow is an application for leave, and after it had been in use for a few months, our head of HR asked me to have the workflow automatically calculate the number of leave days needed for a given leave.
After much googling, head-scratching, and cursing, I figured the fastest way to get this to work was writing a custom activity in C#. Which, to my surprise, has worked a lot better than I expected.
The activity takes into account that some employees only work four days as week, and it queries the user's Active Directory account to figure out what federal state she or he lives in - we're located in Germany, and while most holidays are federal, a few are holidays only in select states. So to find out if a given week day is a leave day, we need to find out what state the user lives in, and then figure out if this day is a holidy in that state.
Fortunately I found C# code that, given a date and a state, can say if that day is a holiday in that state, and integrating it into my custom activity worked quite smoothly, too.
All was well (well, mostly) until users started noticing that the number of leave days required for a given period did not match the number they had calculated manually beforehand. Obviously, the activity had a bug of some sort. I added a little code to write a log, so I can see, day by day, if my activity thinks that day is a holiday or not.
I was quite dismayed to discover that for a number of holidays, my code said they were regular work days. I wrote a simple command line application that referenced my custom activity DLL directly, parsed two dates from the command line, and using my activity code, calculates the number of leave days needed for that period, again logging day by day what the result of the check was.
This time I was not so much dismayed as confused. Baffled, really. Because the command line application I had written gave correct results every single time I checked.
I suspected some sort of region setting, but after careful study, I can honestly say that whatever environment the code runs in does not influence the way it checks for holidays. The part that checks if a given day is a holiday has most holidays defined in relation to the Easter weekend, which again is defined by the beginning of spring and the lunar cycle. (The other holidays are fixed, except for one or two oddballs that are defined as "last Thursday in November" or something like that.)
So how can this be? How can the fact my code is running as part of a SharePoint workflow affect the results it is giving? Has anyone ever run into a problem like this?
Thank you very much for any insights you might be able to share with me, Benjamin