FS#8820 - Misformatted time in "Rockbox Info" screen when in 12-hour clock mode

Attached to Project: Rockbox
Opened by Christopher Williams (christop) - Friday, 28 March 2008, 20:15 GMT
Last edited by Linus Nielsen Feltzing (linusnielsen) - Monday, 31 March 2008, 07:38 GMT
Task Type Bugs
Category User Interface
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


As of today's build (r16867-080328), the Main Menu / System / Rockbox Info screen shows a misformatted time when the Time Format is set to "12 Hour Clock" (global_settings.timeformat != 0). The hour goes negative in the morning, and the hour at noon is 0. For example, when the time is 9 am, it displays "-3:00:00 A", and when it is 12 pm (noon), the info screen displays "00:00:00 P".

This is caused by a small logic/arithmetic error in apps/menus/main_menu.c. This small patch should fix the format of the hour in 12-hour mode.
This task depends upon

Closed by  Linus Nielsen Feltzing (linusnielsen)
Monday, 31 March 2008, 07:38 GMT
Reason for closing:  Fixed
Additional comments about closing:  Thanks for the report and the fix.
Comment by Marc Guay (Marc_Guay) - Sunday, 30 March 2008, 19:52 GMT
Not having this problem on the Sansa e200 w/r16890. Perhaps it's caused by something besides the 12 hour clock setting?
Comment by Christopher Williams (christop) - Monday, 31 March 2008, 07:01 GMT
It is still present in builds r16894, r16896, and r16898 (I tested all three for good measure). These three builds also seem to hang when I plug it into USB (apparently starting with some build after r16873), but that's a bug for a different task.

Are you sure you're looking at the System / Rockbox Info screen during the range of times I described (particularly in the AM)? That's the only place I've seen this bug occur. It doesn't show up in the status bar line at the top.

The source file /apps/menus/main_menu.c is the only one that I found which might be the culprit (it's one of the only files that matches the regex "%.*d:%.*d:%.*d %"), and the logic in the original code seems wrong to me:

global_settings.timeformat == 0 ? tm->tm_hour : tm->tm_hour-12

When timeformat is non-zero (ie, 12-hour clock mode), this code subtracts 12 from the hour, whether the hour is greater than 12 or not. Note that tm->tm_hour is always in the range [0, 23], even in 12-hour mode. This changes the range of hours to -[12, 11], so the formatted string gets a zero or negative value when the hour is 12 or less.

It may be possible that it's caused by something besides the 12-hour clock setting, but I don't see how anything else could affect it, given how simple that line of code (above) is.