From 51c347924000d4220e509f2248ffde390611e45e Mon Sep 17 00:00:00 2001 From: petermcs Date: Wed, 3 Mar 2010 22:55:51 +0000 Subject: [PATCH] Add in check for clients that send invalid start of epoch time with all 0s in the date. --- bacnet-stack/demo/object/trendlog.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index b5de54a9..3536d253 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -946,10 +946,22 @@ bool TL_Is_Enabled(int iLog) time_t TL_BAC_Time_To_Local(BACNET_DATE_TIME *SourceTime) { struct tm LocalTime; - + int iTemp; + LocalTime.tm_year = SourceTime->date.year - 1900; /* We store BACnet year in full format */ - LocalTime.tm_mon = SourceTime->date.month - 1; - LocalTime.tm_mday = SourceTime->date.day; + /* Some clients send a date of all 0s to indicate start of epoch + * even though this is not a valid date. Pick this up here and + * correct the day and month for the local time functions. + */ + iTemp = SourceTime->date.year + SourceTime->date.month +SourceTime->date.day; + if(iTemp == 1900) { + LocalTime.tm_mon = 0; + LocalTime.tm_mday = 1; + } else { + LocalTime.tm_mon = SourceTime->date.month - 1; + LocalTime.tm_mday = SourceTime->date.day; + } + LocalTime.tm_hour = SourceTime->time.hour; LocalTime.tm_min = SourceTime->time.min; LocalTime.tm_sec = SourceTime->time.sec;