A good way to comfort yourself is to design some tests,
but in this case, you are laboriously reinventing a wheel that's likely to leave you with buggy code.
Try DateTime or Date::Manip or Date::Calc.
By the way, I don't think xor does what you think it does.