Fix year handling in mbus_data_tm_decode

According to ANSI C the member tm_year saves the years since
1900.
This commit is contained in:
Stefan Wahren
2016-07-23 07:56:38 +00:00
parent 6fd4ca2714
commit 094c9ef453
2 changed files with 8 additions and 8 deletions

View File

@ -878,7 +878,7 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real,
return -1; return -1;
} }
*value_out_str_size = snprintf(*value_out_str, 11, "%04d-%02d-%02d", *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_mon + 1),
time.tm_mday); time.tm_mday);
result = 0; result = 0;
@ -910,7 +910,7 @@ int mbus_variable_value_decode(mbus_data_record *record, double *value_out_real,
return -1; return -1;
} }
*value_out_str_size = snprintf(*value_out_str, 20, "%04d-%02d-%02dT%02d:%02d:%02d", *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_mon + 1),
time.tm_mday, time.tm_mday,
time.tm_hour, time.tm_hour,

View File

@ -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_hour = t_data[1] & 0x1F;
t->tm_mday = t_data[2] & 0x1F; t->tm_mday = t_data[2] & 0x1F;
t->tm_mon = (t_data[3] & 0x0F) - 1; t->tm_mon = (t_data[3] & 0x0F) - 1;
t->tm_year = ((t_data[2] & 0xE0) >> 5) | t->tm_year = 100 + (((t_data[2] & 0xE0) >> 5) |
((t_data[3] & 0xF0) >> 1); ((t_data[3] & 0xF0) >> 1));
t->tm_isdst = (t_data[1] & 0x80) ? 1 : 0; // day saving time 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_mday = t_data[0] & 0x1F;
t->tm_mon = (t_data[1] & 0x0F) - 1; t->tm_mon = (t_data[1] & 0x0F) - 1;
t->tm_year = ((t_data[0] & 0xE0) >> 5) | t->tm_year = 100 + (((t_data[0] & 0xE0) >> 5) |
((t_data[1] & 0xF0) >> 1); ((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); mbus_data_tm_decode(&time, record->data, 2);
snprintf(buff, sizeof(buff), "%04d-%02d-%02d", snprintf(buff, sizeof(buff), "%04d-%02d-%02d",
(time.tm_year + 2000), (time.tm_year + 1900),
(time.tm_mon + 1), (time.tm_mon + 1),
time.tm_mday); time.tm_mday);
} }
@ -2473,7 +2473,7 @@ mbus_data_record_decode(mbus_data_record *record)
{ {
mbus_data_tm_decode(&time, record->data, 4); mbus_data_tm_decode(&time, record->data, 4);
snprintf(buff, sizeof(buff), "%04d-%02d-%02dT%02d:%02d:%02d", snprintf(buff, sizeof(buff), "%04d-%02d-%02dT%02d:%02d:%02d",
(time.tm_year + 2000), (time.tm_year + 1900),
(time.tm_mon + 1), (time.tm_mon + 1),
time.tm_mday, time.tm_mday,
time.tm_hour, time.tm_hour,