rendered paste body#define SECOND 1
#define MINUTE 60
#define HOUR 60 * MINUTE
#define DAY 24 * HOUR
mytime from_timestamp(int timestamp) {
mytime temp;
temp.year = 1970;
temp.month = 1;
temp.day = 1;
temp.hour = 0;
temp.minute = 0;
temp.second = 0;
// YEARS
while (timestamp > seconds_in_year(temp.year)) {
timestamp -= seconds_in_year(temp.year);
temp.year++;
}
// DAYS
while (timestamp > DAY) {
timestamp -= DAY;
temp.day++;
if (temp.day > days_in_month(temp.year, temp.month)) {
temp.month++;
temp.day=1;
}
}
// HOURS
while (timestamp > HOUR) {
timestamp -= HOUR;
temp.hour++;
}
// MINUTES
while (timestamp > MINUTE) {
timestamp -= MINUTE;
temp.minute++;
}
// SECONDS
temp.second = timestamp;
return temp;
}