simpletime refactor away 28 bytes

This commit is contained in:
Øyvind Kolås 2011-08-03 16:47:44 +01:00 committed by Stefan `Sec` Zehl
parent 5244d1cda2
commit c4c67865e8
1 changed files with 7 additions and 6 deletions

View File

@ -4,9 +4,8 @@
time_t _timet=0;
int _ytab[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
char _ytab[12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
struct tm * mygmtime(register const time_t time) {
@ -14,6 +13,7 @@ struct tm * mygmtime(register const time_t time) {
register struct tm *timep = &br_time;
register unsigned long dayclock, dayno;
int year = EPOCH_YR;
int month_days;
dayclock = (unsigned long)time % SECS_DAY;
dayno = (unsigned long)time / SECS_DAY;
@ -29,8 +29,9 @@ struct tm * mygmtime(register const time_t time) {
timep->tm_year = year - YEAR0;
timep->tm_yday = dayno;
timep->tm_mon = 0;
while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {
dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
while (dayno >= (month_days = _ytab[timep->tm_mon] +
(LEAPYEAR (year) && timep->tm_mon==2)?1:0)) {
dayno -= month_days;
timep->tm_mon++;
}
timep->tm_mday = dayno + 1;