samderlust / calendar_day_view

MIT License
6 stars 11 forks source link

Incorrect time is shown for 12:00 PM when using 12 hour time format #27

Closed ArizArmeidi closed 4 weeks ago

ArizArmeidi commented 4 weeks ago

image When using the 12 hour time format the time text is showing 00:00 PM which is incorrect instead it should show 12:00 PM image

after looking at the code I noticed the problem was caused by the date time extension specifically on the hourDisplay12 getter that is written like this

 String get hourDisplay12 =>
      "${(hour % 12).toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')} ${hour >= 12 ? 'PM' : 'AM'}";

Which is causing the 12 to be 0, I suggest you can modify the code to this so that it will display the time as expected

 String get hourDisplay12 {
    if (hour == 12) {
      return "${(hour).toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')} ${hour >= 12 ? 'PM' : 'AM'}";
    }
    return "${(hour % 12).toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')} ${hour >= 12 ? 'PM' : 'AM'}";
  }

image

samderlust commented 4 weeks ago

Hi @ArizArmeidi, Thanks so much for finding the issue. I'll release a patch soon

ArizArmeidi commented 4 weeks ago

Thanks for the quick response 😁