From 094c9ef453f791139db33c73a7b36904551680f4 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Sat, 23 Jul 2016 07:56:38 +0000 Subject: [PATCH] Fix year handling in mbus_data_tm_decode According to ANSI C the member tm_year saves the years since 1900. --- mbus/mbus-protocol-aux.c | 4 ++-- mbus/mbus-protocol.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index 4f465e9..24906b1 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -878,7 +878,7 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, return -1; } *value_out_str_size = snprintf(*value_out_str, 11, "%04d-%02d-%02d", - (time.tm_year + 2000), + (time.tm_year + 1900), (time.tm_mon + 1), time.tm_mday); result = 0; @@ -910,7 +910,7 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real, return -1; } *value_out_str_size = snprintf(*value_out_str, 20, "%04d-%02d-%02dT%02d:%02d:%02d", - (time.tm_year + 2000), + (time.tm_year + 1900), (time.tm_mon + 1), time.tm_mday, time.tm_hour, diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 546541f..68607f9 100755 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -781,8 +781,8 @@ mbus_data_tm_decode(struct tm *t, unsigned char *t_data, size_t t_data_size) t->tm_hour = t_data[1] & 0x1F; t->tm_mday = t_data[2] & 0x1F; t->tm_mon = (t_data[3] & 0x0F) - 1; - t->tm_year = ((t_data[2] & 0xE0) >> 5) | - ((t_data[3] & 0xF0) >> 1); + t->tm_year = 100 + (((t_data[2] & 0xE0) >> 5) | + ((t_data[3] & 0xF0) >> 1)); t->tm_isdst = (t_data[1] & 0x80) ? 1 : 0; // day saving time } } @@ -790,8 +790,8 @@ mbus_data_tm_decode(struct tm *t, unsigned char *t_data, size_t t_data_size) { t->tm_mday = t_data[0] & 0x1F; t->tm_mon = (t_data[1] & 0x0F) - 1; - t->tm_year = ((t_data[0] & 0xE0) >> 5) | - ((t_data[1] & 0xF0) >> 1); + t->tm_year = 100 + (((t_data[0] & 0xE0) >> 5) | + ((t_data[1] & 0xF0) >> 1)); } } } @@ -2436,7 +2436,7 @@ mbus_data_record_decode(mbus_data_record *record) { mbus_data_tm_decode(&time, record->data, 2); snprintf(buff, sizeof(buff), "%04d-%02d-%02d", - (time.tm_year + 2000), + (time.tm_year + 1900), (time.tm_mon + 1), time.tm_mday); } @@ -2473,7 +2473,7 @@ mbus_data_record_decode(mbus_data_record *record) { mbus_data_tm_decode(&time, record->data, 4); snprintf(buff, sizeof(buff), "%04d-%02d-%02dT%02d:%02d:%02d", - (time.tm_year + 2000), + (time.tm_year + 1900), (time.tm_mon + 1), time.tm_mday, time.tm_hour,