user/u_time.c
/*
 * Convert the "timeInput" time_t count into "struct tm" time components.
 * This is a more compact version of the C library localtime function.
 * Note that year is offset from 1970 !!!
 */
Convert the "timeInput" time_t count into "struct tm" time components.
This is a more compact version of the C library localtime function.
Note that year is offset from 1970
Convert the " timeInput " time_t count into " struct tm " time components . This is a more compact version of the C library localtime function . Note that year is offset from 1970
void timet_to_tm(time_t timeInput, struct tm_struc *tmel){
	uint8_t year;
	uint8_t month, monthLength;
	uint32_t time;
	unsigned long days;
	time = (uint32_t)timeInput;
	tmel->Second = time % 60;
	time /= 60;		
	tmel->Minute = time % 60;
	time /= 60;		
	tmel->Hour = time % 24;
	time /= 24;		
	tmel->Wday = ((time + 4) % 7) + 1;	
	year = 0;	
	days = 0;
	while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) {
		year++;
	}
	tmel->Year = year;	
	days -= LEAP_YEAR(year) ? 366 : 365;
	time	-= days;	
	days=0;
	month=0;
	monthLength=0;
	for (month=0; month<12; month++) {
		if (month==1) {	
			if (LEAP_YEAR(year)) {
				monthLength=29;
			} else {
				monthLength=28;
			}
		} else {
			monthLength = monthDays[month];
		}
		if (time >= monthLength) {
			time -= monthLength;
		} else {
				break;
		}
	}
	tmel->Month = month + 1;	
	tmel->Day = time + 1;		
}
void timet_to_tm ( time_t timeInput , struct tm_struc * tmel ) { uint8_t year ; uint8_t month , monthLength ; uint32_t time ; unsigned long days ; time = ( uint32_t ) timeInput ; tmel -> Second = time % 60 ; time /= 60 ; tmel -> Minute = time % 60 ; time /= 60 ; tmel -> Hour = time % 24 ; time /= 24 ; tmel -> Wday = ( ( time + 4 ) % 7 ) + 1 ; year = 0 ; days = 0 ; while ( ( unsigned ) ( days += ( LEAP_YEAR ( year ) ? 366 : 365 ) ) <= time ) { year ++ ; } tmel -> Year = year ; days -= LEAP_YEAR ( year ) ? 366 : 365 ; time -= days ; days = 0 ; month = 0 ; monthLength = 0 ; for ( month = 0 ; month < 12 ; month ++ ) { if ( month == 1 ) { if ( LEAP_YEAR ( year ) ) { monthLength = 29 ; } else { monthLength = 28 ; } } else { monthLength = monthDays [ month ] ; } if ( time >= monthLength ) { time -= monthLength ; } else { break ; } } tmel -> Month = month + 1 ; tmel -> Day = time + 1 ; }
Convert the "timeInput" time_t count into "struct tm" time components.
Convert the " timeInput " time_t count into " struct tm " time components .
// Now it is minutes. // Now it is hours. // Now it is days. // Sunday is day 1. // The year is offset from 1970. // Now it is days in this year, starting at 0. // February. // Jan is month 1. // Day of month.