Interesting how it compares with the ClickHouse implementation, which uses a lookup table: https://github.com/ClickHouse/ClickHouse/blob/master/src/Com...
So that a day number can be directly mapped to year, month, and day, and the calendar date can be mapped back with a year-month LUT.
Simply, ClickHouse only works on a 399 years span while OP's algorith parses any date, over 3 trillion years.