From 387a6bf8f0ac3597b3c0cc7ef6c4b464679d570f Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 11 Jul 2014 20:55:35 +0200 Subject: [PATCH] libv4l2rds: fix date-time handling 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 --- lib/libv4l2rds/libv4l2rds.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/libv4l2rds/libv4l2rds.c b/lib/libv4l2rds/libv4l2rds.c index 913bdce..ac7adb2 100644 --- a/lib/libv4l2rds/libv4l2rds.c +++ b/lib/libv4l2rds/libv4l2rds.c @@ -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); -- 2.7.4