You could just follow your logic to the bitter end.

Starting with what you wrote, pseudo-code for the algorithm could look something like the following:



IF (year IS DIVISIBLE BY 400) THEN
...