All pastes #2127904 Raw Edit

Stuff

public c v1 · immutable
#2127904 ·published 2012-03-13 18:27 UTC
rendered paste body
/* * Convert seconds to time */void seconds_to_time(int seconds, struct time *t){	int year_i;	int year = EPOCH_YEAR, month = 1, day = 1, hour = 0, min = 0, sec = 0;	while(seconds != 0){				// Year		while(1){			// Do we have enough seconds for a year			if(seconds > 60*60*24*365){				if(leap_year(year)){ // Is leap year?					if(seconds > 60*60*24*366) // and do we have enough seconds left for a full leap year?						// Remove a leap year in seconds						seconds -= 60*60*24*366;					else // Year is not over yet, because it's one day longer than a normal year.						break;				} else {					// Remove a year in seconds					seconds -= 60*60*24*365;				}			} else {				// Not enough seconds for a year or leap year				break;			}		}	}	// Set time struct	t->year = year;	t->month = month;	t->day = day;	t->hour = hour;	t->min = min;	t->sec = sec;	}