CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DateTime compare
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Thu Apr 01, 2021 9:34 am     Reply with quote

Hi mr.Ttelmah,

Thanks for help! Now it's OK.

I've added this line "timeT->month -= 1;", but I don't know porpose of this "timeT->month %= 12;" and this :

Code:

    #ifdef TIME_T_USES_2010
            i = 110;
     #else
            i = 70;
     #endif


Last my code:
Code:

time_t mktime(rtc_time_t *timeT){
   
   time_t unixTime = 0;
   int1 isLeapYear = FALSE;
   unsigned int16 i = 0;
   unsigned int16 tmp_year;

   tmp_year = 2000+timeT->year;
   timeT->month -= 1;   

   if(timeT != '\0'){
   
      unixTime += timeT->second;
      unixTime += (unsigned int32)(timeT->minute) * 60;
      unixTime += (unsigned int32)(timeT->hour) * 3600;

      isLeapYear = LeapYear(tmp_year);
       /* Clamp the month to [0,11) */
      //timeT->month %= 12;
      for(i=1; i<=timeT->month; i++)
      {
         unixTime += (DaysInMonth(i - 1, isLeapYear) * 86400);
      }

      /* Clamp the days in the month */
      //timeT->tm_mday %= DaysInMonth(timeT->tm_mon,isLeapYear);
      unixTime += (timeT->dayOfMonth - 1) * 86400;

      #ifdef TIME_T_USES_2010
         i = 110;
      #else
         i = 70;
      #endif

      while(i < tmp_year){
            
       isLeapYear = LeapYear(i);
       if(isLeapYear)
            unixTime += (31622400); // seconds in 366 days
       else
            unixTime += (31536000); // seconds in 365 days

       i++;
      }   
   }

   return unixTime;
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19216

View user's profile Send private message

PostPosted: Thu Apr 01, 2021 9:54 am     Reply with quote

It's the offset from 1900.
70 for 1970 based or 110 for 2010 based.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group