BYMONTHDAY fixes

These are the fixes from bugzilla bugs 872195, 899326 & 899770 compiled together.
Tests have been added to check the functionality.