rtc_RtcTime2Sec() returns wrong seconds when RtcTime.year is 2016

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I'm using BCM20737S.

The followings are output of rtc_ctime() and rtc_RtcTime2Sec().

If RtcTime.year is 2016, it seems that rtc_RtcTime2Sec() ignores RtcTime.month.

Jan 1 12:00:00 2015 / seconds: 157809600
Feb 1 12:00:00 2015 / seconds: 160488000
Mar 1 12:00:00 2015 / seconds: 162907200
Apr 1 12:00:00 2015 / seconds: 165585600
May 1 12:00:00 2015 / seconds: 168177600
Jun 1 12:00:00 2015 / seconds: 170856000
Jul 1 12:00:00 2015 / seconds: 173448000
Aug 1 12:00:00 2015 / seconds: 176126400
Sep 1 12:00:00 2015 / seconds: 178804800
Oct 1 12:00:00 2015 / seconds: 181396800
Nov 1 12:00:00 2015 / seconds: 184075200
Dec 1 12:00:00 2015 / seconds: 186667200

Jan 1 12:00:00 2016 / seconds: 189345600
Feb 1 12:00:00 2016 / seconds: 189345600
Mar 1 12:00:00 2016 / seconds: 189345600
Apr 1 12:00:00 2016 / seconds: 189345600
May 1 12:00:00 2016 / seconds: 189345600
Jun 1 12:00:00 2016 / seconds: 189345600
Jul 1 12:00:00 2016 / seconds: 189345600
Aug 1 12:00:00 2016 / seconds: 189345600
Sep 1 12:00:00 2016 / seconds: 189345600
Oct 1 12:00:00 2016 / seconds: 189345600
Nov 1 12:00:00 2016 / seconds: 189345600
Dec 1 12:00:00 2016 / seconds: 189345600

Jan 15 12:00:00 2016 / seconds: 190555200
Feb 15 12:00:00 2016 / seconds: 190555200
Mar 15 12:00:00 2016 / seconds: 190555200
Apr 15 12:00:00 2016 / seconds: 190555200
May 15 12:00:00 2016 / seconds: 190555200
Jun 15 12:00:00 2016 / seconds: 190555200
Jul 15 12:00:00 2016 / seconds: 190555200
Aug 15 12:00:00 2016 / seconds: 190555200
Sep 15 12:00:00 2016 / seconds: 190555200
Oct 15 12:00:00 2016 / seconds: 190555200
Nov 15 12:00:00 2016 / seconds: 190555200
Dec 15 12:00:00 2016 / seconds: 190555200

Jan 28 12:00:00 2016 / seconds: 191678400
Feb 28 12:00:00 2016 / seconds: 191678400
Mar 28 12:00:00 2016 / seconds: 191678400
Apr 28 12:00:00 2016 / seconds: 191678400
May 28 12:00:00 2016 / seconds: 191678400
Jun 28 12:00:00 2016 / seconds: 191678400
Jul 28 12:00:00 2016 / seconds: 191678400
Aug 28 12:00:00 2016 / seconds: 191678400
Sep 28 12:00:00 2016 / seconds: 191678400
Oct 28 12:00:00 2016 / seconds: 191678400
Nov 28 12:00:00 2016 / seconds: 191678400
Dec 28 12:00:00 2016 / seconds: 191678400

Jan 1 12:00:00 2017 / seconds: 220968000
Feb 1 12:00:00 2017 / seconds: 223646400
Mar 1 12:00:00 2017 / seconds: 226065600
Apr 1 12:00:00 2017 / seconds: 228744000
May 1 12:00:00 2017 / seconds: 231336000
Jun 1 12:00:00 2017 / seconds: 234014400
Jul 1 12:00:00 2017 / seconds: 236606400
Aug 1 12:00:00 2017 / seconds: 239284800
Sep 1 12:00:00 2017 / seconds: 241963200
Oct 1 12:00:00 2017 / seconds: 244555200
Nov 1 12:00:00 2017 / seconds: 247233600
Dec 1 12:00:00 2017 / seconds: 249825600

Jan 1 12:00:00 2018 / seconds: 252504000
Feb 1 12:00:00 2018 / seconds: 255182400
Mar 1 12:00:00 2018 / seconds: 257601600
Apr 1 12:00:00 2018 / seconds: 260280000
May 1 12:00:00 2018 / seconds: 262872000
Jun 1 12:00:00 2018 / seconds: 265550400
Jul 1 12:00:00 2018 / seconds: 268142400
Aug 1 12:00:00 2018 / seconds: 270820800
Sep 1 12:00:00 2018 / seconds: 273499200
Oct 1 12:00:00 2018 / seconds: 276091200
Nov 1 12:00:00 2018 / seconds: 278769600
Dec 1 12:00:00 2018 / seconds: 281361600

0 Likes
1 Solution
Anonymous
Not applicable

Sorry for the delayed response, we were working on getting the fix for you.

Please see the code below for the RtcTime2Sec workaround.

#include "rtc.h"

/////////////////////////////////////////////////////////////////////
/// Conver from RTC_time format to UINT32 seconds format
///  
/// \param rtctime - timer object pointer to be converted 
/// \param second  - converted UINT32 seconds
/////////////////////////////////////////////////////////////////////
void _rtc_RtcTime2Sec(RtcTime *rtctime, UINT32 *second)
{
   UINT32      days;
   int         i;
   UINT8      months[12] ={31,28,31,30,31,30,31,31,30,31,30,31};
   //int         daysPerYear;

   i = BASE_LINE_REF_YEAR;
   days  =  0;

   while ( i < rtctime->year )
   {
       days += 365;

       if ( ( (i % 400) == 0 ) || ( ( (i % 4) == 0) && ( (i % 100) != 0 ) )  )
       {
           days ++;    // leap year
       }

       i ++;
   }

   // leap year
   if ( ( (rtctime->year % 400) == 0 ) || ( ( (rtctime->year % 4) == 0 ) && ( (rtctime->year % 100) != 0 ) )  )
   {
       months[1] = 29;
   }


   i=0;
   while ( i < rtctime->month )
   {
       days += months;

       i++;
   }

   days += (rtctime->day-1);      //notes : day from app/user is 1 base

   *second = days * (24*60*60) + rtctime->hour * (60*60) + rtctime->minute *60 + rtctime->second;
}

Thanks,

Kevin

View solution in original post

0 Likes
10 Replies