Add test case for applying last day and fix bug