kern

diff src/klibc/time.c @ 40:710739e33da8

- now read_rtc doesn't try to read weekday as it's probably wrong anyway, and doesn't set yearday either - mktime now fixes yearday and weekday - moved init_timer and init_rtc just before enabling the interrupts in main
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 12 Jun 2011 15:45:21 +0300
parents 92297f65aaef
children
line diff
     1.1 --- a/src/klibc/time.c	Sun Jun 12 01:46:53 2011 +0300
     1.2 +++ b/src/klibc/time.c	Sun Jun 12 15:45:21 2011 +0300
     1.3 @@ -9,6 +9,9 @@
     1.4  #define DAYSEC		(24 * HOURSEC)
     1.5  #define YEARDAYS(x)	(is_leap_year(x) ? 366 : 365)
     1.6  
     1.7 +/* 1-1-1970 was a thursday */
     1.8 +#define EPOCH_WDAY	4
     1.9 +
    1.10  static int is_leap_year(int yr);
    1.11  
    1.12  static int mdays[2][12] = {
    1.13 @@ -53,10 +56,16 @@
    1.14  	int year = 1970;
    1.15  	int days = day_of_year(tm->tm_year + 1900, tm->tm_mon, tm->tm_mday - 1);
    1.16  
    1.17 +	/* set correct yearday */
    1.18 +	tm->tm_yday = days;
    1.19 +
    1.20  	for(i=0; i<num_years; i++) {
    1.21  		days += YEARDAYS(year++);
    1.22  	}
    1.23  
    1.24 +	/* set wday correctly */
    1.25 +	tm->tm_wday = (days + EPOCH_WDAY) % 7;
    1.26 +
    1.27  	return (time_t)days * DAYSEC + tm->tm_hour * HOURSEC +
    1.28  		tm->tm_min * MINSEC + tm->tm_sec;
    1.29  }
    1.30 @@ -76,7 +85,7 @@
    1.31  	days = *tp / DAYSEC;
    1.32  	t = *tp % DAYSEC;
    1.33  
    1.34 -	tm->tm_wday = (days + 4) % 7;
    1.35 +	tm->tm_wday = (days + EPOCH_WDAY) % 7;
    1.36  
    1.37  	while(days >= (yrdays = YEARDAYS(year))) {
    1.38  		days -= yrdays;