libv4l2rds: fix date-time handling
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 18:55:35 +0000 (20:55 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 18:55:35 +0000 (20:55 +0200)
The way the offset was handled was wrong: the fact that RDS specifies
the timezone offset in units of 30 minutes clearly was confusing.

Fixed the calculations.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
lib/libv4l2rds/libv4l2rds.c

index 913bdce..ac7adb2 100644 (file)
@@ -1022,10 +1022,10 @@ static time_t rds_decode_mjd(const struct rds_private_state *priv_state)
        /* add / subtract the local offset to get the local time.
         * The offset is expressed in multiples of half hours */
        if (priv_state->utc_offset & 0x20) { /* bit 5 indicates -/+ */
-               local_hour -= (offset * 2);
+               local_hour -= offset / 2;
                local_minute -= (offset % 2) * 30;
        } else {
-               local_hour += (offset * 2);
+               local_hour += offset / 2;
                local_minute += (offset % 2) * 30;
        }
 
@@ -1044,14 +1044,14 @@ static time_t rds_decode_mjd(const struct rds_private_state *priv_state)
        new_time.tm_min = local_minute;
        new_time.tm_hour = local_hour;
        new_time.tm_mday = d;
-       new_time.tm_mon = m;
+       new_time.tm_mon = m - 1;
        new_time.tm_year = y;
        /* offset (submitted by RDS) that was used to compute the local time,
         * expressed in multiples of half hours, bit 5 indicates -/+ */
        if (priv_state->utc_offset & 0x20)
-               new_time.tm_gmtoff = -2 * offset * 3600;
+               new_time.tm_gmtoff = -offset * 1800;
        else
-               new_time.tm_gmtoff = 2 * offset * 3600;
+               new_time.tm_gmtoff = offset * 1800;
 
        /* convert tm struct to time_t value and return it */
        return mktime(&new_time);