user/u_time.c
/*
 * Reconstitute "struct tm" elements into a time_t count value.
 * Note that the year argument is offset from 1970.
 */
Reconstitute "struct tm" elements into a time_t count value.
Note that the year argument is offset from 1970.
Reconstitute " struct tm " elements into a time_t count value . Note that the year argument is offset from 1970 .
time_t tm_to_timet(struct tm_struc *tmel){	 
	int i;
	uint32_t seconds;
	seconds= tmel->Year*(SECS_PER_DAY * 365);
	for (i = 0; i < tmel->Year; i++) {
		if (LEAP_YEAR(i)) {
			seconds += SECS_PER_DAY;	
		}
	}
	for (i = 1; i < tmel->Month; i++) {
		if ( (i == 2) && LEAP_YEAR(tmel->Year)) { 
			seconds += SECS_PER_DAY * 29;
		} else {
			seconds += SECS_PER_DAY * monthDays[i-1];	
		}
	}
	seconds+= (tmel->Day-1) * SECS_PER_DAY;		
	seconds+= tmel->Hour * SECS_PER_HOUR;		
	seconds+= tmel->Minute * SECS_PER_MIN;		
	seconds+= tmel->Second;				
	return (time_t)seconds; 
}
time_t tm_to_timet ( struct tm_struc * tmel ) { int i ; uint32_t seconds ; seconds = tmel -> Year * ( SECS_PER_DAY * 365 ) ; for ( i = 0 ; i < tmel -> Year ; i ++ ) { if ( LEAP_YEAR ( i ) ) { seconds += SECS_PER_DAY ; } } for ( i = 1 ; i < tmel -> Month ; i ++ ) { if ( ( i == 2 ) && LEAP_YEAR ( tmel -> Year ) ) { seconds += SECS_PER_DAY * 29 ; } else { seconds += SECS_PER_DAY * monthDays [ i - 1 ] ; } } seconds += ( tmel -> Day - 1 ) * SECS_PER_DAY ; seconds += tmel -> Hour * SECS_PER_HOUR ; seconds += tmel -> Minute * SECS_PER_MIN ; seconds += tmel -> Second ; return ( time_t ) seconds ; }
Reconstitute "struct tm" elements into a time_t count value.
Reconstitute " struct tm " elements into a time_t count value .
// Seconds from 1970 till 1st Jan 00:00:00 of the given year. // Add extra days for leap years. // Add the number of elapsed days for the given year. Months start from 1. // "monthDay" array starts from 0. // Days... // Hours... // Minutes... // ...and finally, Seconds.