Add in check for clients that send invalid start of epoch time with all 0s in the date.

This commit is contained in:
petermcs
2010-03-03 22:55:51 +00:00
parent 8fdc3b113a
commit 51c3479240
+14 -2
View File
@@ -946,10 +946,22 @@ bool TL_Is_Enabled(int iLog)
time_t TL_BAC_Time_To_Local(BACNET_DATE_TIME *SourceTime) time_t TL_BAC_Time_To_Local(BACNET_DATE_TIME *SourceTime)
{ {
struct tm LocalTime; struct tm LocalTime;
int iTemp;
LocalTime.tm_year = SourceTime->date.year - 1900; /* We store BACnet year in full format */ LocalTime.tm_year = SourceTime->date.year - 1900; /* We store BACnet year in full format */
LocalTime.tm_mon = SourceTime->date.month - 1; /* Some clients send a date of all 0s to indicate start of epoch
LocalTime.tm_mday = SourceTime->date.day; * 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_hour = SourceTime->time.hour;
LocalTime.tm_min = SourceTime->time.min; LocalTime.tm_min = SourceTime->time.min;
LocalTime.tm_sec = SourceTime->time.sec; LocalTime.tm_sec = SourceTime->time.sec;