andersnm / ExcelNumberFormat

Parse and render Excel number format strings
MIT License
79 stars 27 forks source link

Date Formatting treating 12hr AM/PM as 24hr #17

Closed franknorton closed 4 years ago

franknorton commented 4 years ago

Date formatting isn't correctly taking into account AM/PM or A/P tokens when formatting the hour portion.

When given a format string such as h:mm:ss AM/PM and a date value with an hour component over 12 hours, such as 14, the result is in 24hr time instead of 12hr time, 14:00:00 PM.

The problem is in Formatter.cs. For the h token it is doing date.Hour.ToString("D" + digits) regardless of the existence of an AM/PM token.

andersnm commented 4 years ago

Thanks for the bug report and fix! Made a few tweaks to it. Just released as 1.0.8.