This works because tuples are compared element by element and month/day are natural ordering. Any true condition evaluates to what's effectively 1 and a false condition to 0 - and we add that to the year to move it into the next if required.