WeekDay field of adl_rtcTime starts from Sunday


I found that WeekDay parameter of adl_rtcTime type gets between values 0-6. What is more, Sunday is not 6, it is 0. Parameter flows between Sunday-Saturday not Monday-Sunday. Look at the following:

WeekDay=0: Sunday
WeekDay=1: Monday
WeekDay=2: Tue
WeekDay=3: Wed
WeekDay=4: Thu
WeekDay=5: Fri
WeekDay=6: Sat

That makes some confusion. I write a piece of code to show that. The code is following:

char strMessage[100]={0};
	adl_rtcTime_t rtcNow;
	int i=7;

	AddHour(&rtcNow, 1); // just init the WeekDay param for the first use
	while(i != 0)
		wm_sprintf(strMessage, "Rtc Date:%d/%d/%d,%d:%d:%d Weekday:%d\r\n", rtcNow.Year, rtcNow.Month, rtcNow.Day, rtcNow.Hour, rtcNow.Minute, rtcNow.Second, rtcNow.WeekDay);

		adl_atSendResponse(ADL_AT_RSP, strMessage);
		AddHour(&rtcNow, -24); // adds -24 hours

And this code outputs the following lines. You can check from your calender.

Rtc Date:2011/10/5,11:5:58 Weekday:3 // Wed
Rtc Date:2011/10/4,11:5:58 Weekday:2 // Tue
Rtc Date:2011/10/3,11:5:58 Weekday:1 // Monday
Rtc Date:2011/10/2,11:5:58 Weekday:0 // Sunday
Rtc Date:2011/10/1,11:5:58 Weekday:6 // Saturday
Rtc Date:2011/9/30,11:5:58 Weekday:5 // Fri
Rtc Date:2011/9/29,11:5:58 Weekday:4 // Thu

What is more, the both documantation “ADL User Guide for Open AT® OS 6.35” and “ADL User Guide for Open AT® OS 6.32” tells that WeekDay is between 1-7. I now see this information is wrong.

If you want to use WeekDay field for some calculations, you need to be careful.

I tested my code on R7.43 and R7.45.


I just added the following line in the rtc sample :

TRACE((1,"Weekday : %d",StartTime.WeekDay));

I set the date to 9 oct sunday using at+cclk,following is the output:

11/10/05,15:29:14:64 - 001;ADL;1;Start RTC timer
11/10/05,15:29:14:79 - 001;ADL;1;RTC sample : StartTime = 9/10/2011 15:19:3
11/10/05,15:29:14:79 - 002;ADL;1;Weekday : 7

I tested this with 7.45.I get the weekday value as 7 for sunday, this is
correct according to the document.


Then what is wrong with my code? Or enverioment? i use Fastract Xtend R7.43, R7.45 both. And i build my application on SDK 2.35, FW 7.45.
Why do i get a different result? Any opinions?



I’ve the same problem, the field WeekDay from adl_rtcTime_t is in the range [0; 6] with 0 for Sunday and not in the range [1; 7] as said in the documentation and header file.

Here is a simple unitary test:

int nGetWeekDay(u32 timestampValue)
	adl_rtcTimeStamp_t ts;
	adl_rtcTime_t time;

	ts.TimeStamp = timestampValue;
	ts.SecondFracPart = 0;

	if(adl_rtcConvertTime(&time, &ts, ADL_RTC_CONVERT_FROM_TIMESTAMP) == OK)
		return  time.WeekDay;
		return -1;

void main_task ( void )
	adl_InitType_e adl_InitType = adl_InitGetType ();
	TRACE (( 1, "Embedded : Appli Init" ));
	int nWeekDay;
	ascii log[256];
	u32 ts;
	u32 timeInterval;
	int i;
	// 24 hours in seconds
	timeInterval = 24*3600;
	// See http://www.timestamp.fr/
	// 1346569200 timestamp is 2012 September 02 at 09:00:00 UTC which is a SUNDAY
	for(i = 0; i <= 7; i++)
		ts = 1346569200 + i*timeInterval;
		nWeekDay = nGetWeekDay(ts);
		wm_sprintf(log, "Input timestamp:%ld => Weekday=%d", ts, nWeekDay);
		TRACE((1, log));

The output is:

The first timestamp value 1346569200 is 2012 September 02 at 09:00:00 UTC which is a SUNDAY (you can use the URL http://www.timestamp.fr)
The weekday result is 0.
I add 24 hours between 2 test values.

My configuration is



Hi Mark,
My problem is still alive. However, i accept the fact that WeekDay parameter is in the range [0,6] and not [1.7]. I created my logic according to [0,6] range.
But there is possibility that with an update it can turn to [1,7] what the documantation says. So we have to check this everytime we have an firmware update or change the product type i think.

My code says: Monday:1,Tuesday:2,Wed:3,.........Sat:6,Sunday:0
Source code and documantation say: u8  WeekDay;        ///< Day of Week [1..7]

I have tested on R7.43, R7.45, R7.46 and Fastract Xtend, Airprime Q2687RD


This should be addressed by 60952 in Firmware 7.51 & Open AT OS 6.51.