Skip to contentSkip to conversation

Fix conversion between 12 hours and 24 hours modes.

PATCH New Antoine Mathys 1 participant 1 message Dec 14, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix conversion between 12 hours and 24 hours modes.

The proper mapping between 24 hours and 12 hours modes is:
0 12 AM
1-11 1-11 AM
12 12 PM
13-23 1-11 PM
Fix code accordingly.

---
 hw/ds1338.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/ds1338.c +4 -4
index 1aefa3b..9e6b490 100644
@@ -59,8 +59,8 @@ static void capture_current_time(DS1338State *s)
     s->nvram[1] = to_bcd(now.tm_min);
     if (s->nvram[2] & HOURS_12) {
         int tmp = now.tm_hour;
-        if (tmp == 0) {
-            tmp = 24;
+        if (tmp % 12 == 0) {
+            tmp += 12;
         }
         if (tmp <= 12) {
             s->nvram[2] = HOURS_12 | to_bcd(tmp);
@@ -145,8 +145,8 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data)
                 if (data & HOURS_PM) {
                     tmp += 12;
                 }
-                if (tmp == 24) {
-                    tmp = 0;
+                if (tmp % 12 == 0) {
+                    tmp -= 12;
                 }
                 now.tm_hour = tmp;
             } else {
Signature · 1 line
1.7.10.4