Why don't you just implement the algorithm mentioned on wikipedia in a Microflow?
As Achiel said i would suggest to just use one of the algorithms that are provided on wikipedia. I also suggest to take a look at the expresions documentation as this will give you a good idea about what is possible within microflows and how to solve some of your problems like calculating the difference in date.