fixed bug in AM/PM logic