Mktime does not set tm_isdst


#1

Hello,
I want to determine if i should add an hour for DST(daylight saving time) or not. In order to achive this, i use mktime function to determine whether the given time is DST or not.

static bool DetermineIsDST(adl_rtcTime_t * time)
{
	struct tm tmTime;

	tmTime.tm_year= time->Year-1900;
	tmTime.tm_mon= time->Month-1;  /* Jan = 0, Feb = 1,.. Dec = 11 */
	tmTime.tm_mday=time->Day;
	tmTime.tm_hour=time->Hour;
	tmTime.tm_min=time->Minute;
	tmTime.tm_sec=0;
	tmTime.tm_isdst=-1; /* will be set after mktime, -1=not avaliable, 0=no dst, >0=dst active */

	mktime(&tmTime);

	if(tmTime.tm_isdst > 0)
		return TRUE;
	else
		return FALSE;
}

On windows enverioment the function sets correctly tm_isdst variable of tm structure but in my Open AT application mktime always sets tm_isdst parameter as -1.
So can not i use this approach to determine DST flag?

Using: Airprime Q2687RD, FW:R743

Thanks.


#2

Only if you have correctly configured the Region settings for your Windows environment!

I think you’ll find that this relies upon support provided by the environment - and Open-AT provides no such support.

Check your ‘C’ runtime library documentation for details…


#3

Well, i solved the problem in an other way. I have written such a function that does the same job as tm_isdst.
Here is my code

static bool DetermineIsDST(adl_rtcTime_t * time)
{
	adl_rtcTime_t dstBegin, dstEnd;
	bool isDst = FALSE;
	// Init DST begin/end dates without UTC offset
	dstBegin.Year = dstEnd.Year = time->Year;
	dstBegin.Month = 3;	dstEnd.Month = 10;
	dstBegin.Day = dstEnd.Day = 31;
	dstBegin.Hour = 1;	dstEnd.Hour = 2;
	dstBegin.Minute = dstEnd.Minute = 0;
	dstBegin.Second = dstEnd.Second = 0;
	// Go until last sunday
	while(dstBegin.WeekDay != 6)
	{
		AddHour(&dstBegin, -24);
	}
	while(dstEnd.WeekDay != 6)
	{
		AddHour(&dstEnd, -24);
	}
	// DST is FALSE if given date is graeter than DST end date(October)
        // DST is TRUE if given date is less than DST end date(October) and is greater than DST begin date(March)
	// DST is FALSE if given date is less then both DST begin date(March) and DST end date(October)
	if(CompareTimes(time, &dstEnd, FALSE) == 1)
		isDst = FALSE;
	else if(CompareTimes(time, &dstBegin, FALSE) == 1)
		isDst = TRUE;
	else
		isDst = FALSE;

	return isDst;
}

And comparetimes function just compare two given dates and returns 1 if first date is greater, returns 0 otherwise.


#4

You are assuming that the DST begin date is always some time in March, and the DST end date is always some time in October - is that a valid assumption :question:


#5

i know some countries apply different dates for DST. But in my country, it is always same logic being used for DST. So this solution suits my problem for now. If something happens in the future, i will just change the DST calculation function and download my new application via DOTA.