Would this be a good port?
C++ code:
Code:
void DateTime::splitTicks(time_t time) {
seconds = time % 60;
time /= 60;
minutes = time % 60;
time /= 60;
hours = time % 24;
time /= 24;
year = DateTime::reduceDaysToYear(time);
month = DateTime::reduceDaysToMonths(time,year);
day = int(time);
}
int DateTime::reduceDaysToYear(time_t &days) {
int year;
for (year=1970;days>daysInYear(year);year++) {
days -= daysInYear(year);
}
return year;
}
int DateTime::reduceDaysToMonths(time_t &days,int year) {
int month;
for (month=0;days>daysInMonth(month,year);month++)
days -= daysInMonth(month,year);
return month;
}
Lua Code:
Code:
function splitTicks( time_t, time )
seconds = time % 60
time = time / 60
minutes = time % 60
time = time / 60
hours = time % 24
time = time / 24
year = reduceDaysToYear( time )
month = reduceDaysToMonths( time, year )
day = math.floor( time )
end
function reduceDaysToYear( time_t, days )
math.floor( year )
for year=1970, daysInYear( year ), 1 do
days = days-daysInYear( year )
end
return year
end
function reduceDaysToMonths( time_t, days, math.floor( year ))
math.floor( month )
for month=0, daysInMonth( month, year ), 1 do
days = days-daysInMonth( month, year )
end
return month
end
Please tell me if any of that is wrong.
I have no C++ knowledge and only a small amount of lua knowledge.