This blog is about everything and anything. Generally I blog if I feel strongly about something or if I am inspired about something. I love responses, and would love to see that more people read my blog in the times to come! I hope that this note finds you in best of your health! Cheers! Aditya

Friday, June 12, 2009

Timecore Software issue


Mine is a electronic systems design and development company. We develop customized instruments. 

We have developed a instrument which monitors the vehicle fleet. One of the functions is that it logs the vehicle start time and vehicle stop time. This data is first downloaded from the vehicle to a handheld device and from there it is transferred to the computer.
On computer we have a VC++ MFC application running. Everything was running fine for nearly a month and we were getting all the data correctly.
Suddenly we started getting error: "Debug Assertion Failed. File Timecore.cpp Line 40"
On opening the Timecore file, I found this data:
CTime::CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST){
struct tm atm; atm.tm_sec = nSec;
atm.tm_min = nMin;
atm.tm_hour = nHour;
ASSERT(nDay >= 1 && nDay <= 31);
atm.tm_mday = nDay;
ASSERT(nMonth >= 1 && nMonth <= 12);
atm.tm_mon = nMonth - 1; // tm_mon is 0 based ASSERT(nYear >= 1900);
atm.tm_year = nYear - 1900; // tm_year is 1900 based
atm.tm_isdst = nDST;
m_time = mktime(&atm);
ASSERT(m_time != -1); // indicates an illegal input time
}
The text in blue is the text that is on line 40.
The engineer is in Vizag and top honcho of the customer is visiting site tomorrow. Effectively this put our balls in the compression mode. (We are based in Pune)
Since the error is in the initialization of CTime we thought that we had not init the declaration correctly. But the check up that followed revealed that there was no mistake on our side.

Further enquiries from the site revealed that one of the units from had its RTC (real time clock) programmed to year as 2063.
I initially ignored this because the CTime documentation said that
"The upper date limit is 12/31/3000. The lower limit is 1/1/1970 12:00:00 AM GMT."
source: http://msdn.microsoft.com/en-us/library/78zb0ese(VS.80).aspx
2063 falls well within the limit.
A possible pitfall here could have been that I am using VC++ 6.0 and the documentation could be for the current version.
I kept doing what every good engineer does when he does'nt have a solution. I kept googling. Nothing came up. Out of desperation I clicked on Translate the Page next to:
http://topic.csdn.net/t/20041214/16/3644707.html
What a useful thing that was. I came to know that CTime Line 40 uses the mktime function which can handle year upto 2038 only. Problem solved.
Technology is a great thing. It helps us solve all the problems that we created with the earlier technology.