Add tm->yday to RTC ports missing it

Change-Id: I86882262bafb8d06f925aabb87ebd1b5dcb0cd53
This commit is contained in:
Moshe Piekarski 2021-05-05 12:52:19 -04:00 committed by Solomon Peachy
parent 3f26fcf340
commit b895fb6643
14 changed files with 30 additions and 12 deletions

View file

@ -135,5 +135,21 @@ void set_day_of_week(struct tm *tm)
if(m == 0 || m == 1) y--;
tm->tm_wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
}
void set_day_of_year(struct tm *tm)
{
int y=tm->tm_year+1900;
int d=tm->tm_mday;
int m=tm->tm_mon;
d+=m*30;
if( ( (m>1) && !(y%4) ) && ( (y%100) || !(y%400) ) )
d++;
if(m>6)
{
d+=4;
m-=7;
}
tm->tm_yday = d + ((m+1) /2);
}
#endif /* CONFIG_RTC */

View file

@ -53,9 +53,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return rc;
}

View file

@ -126,9 +126,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(buf[4] & 0x3f);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return rc;
}

View file

@ -86,9 +86,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(buf[3] & 0x3f);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return read;
}

View file

@ -144,9 +144,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return rc;
}

View file

@ -52,9 +52,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return rc;
}

View file

@ -56,7 +56,7 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_hour = buf[2];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_yday = 0; /* Not implemented for now */
#ifdef IRIVER_H300_SERIES
/* Special kludge to coexist with the iriver firmware. The iriver firmware
stores the date as 1965+nn, and allows a range of 1980..2064. We use
@ -68,6 +68,7 @@ int rtc_read_datetime(struct tm *tm)
#endif /* IRIVER_H300_SERIES */
set_day_of_week(tm);
set_day_of_year(tm);
return rc;
}

View file

@ -52,9 +52,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return 1;
}

View file

@ -192,9 +192,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[TIME_DAY];
tm->tm_mon = buf[TIME_MONTH] - 1;
tm->tm_year = buf[TIME_YEAR] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return ret;
}

View file

@ -79,9 +79,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return ret;
}

View file

@ -39,9 +39,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(BCDDATE);
tm->tm_mon = BCD2DEC(BCDMON) - 1;
tm->tm_year = BCD2DEC(BCDYEAR) + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return 1;
}

View file

@ -31,6 +31,7 @@ int set_time(const struct tm *tm);
#if CONFIG_RTC
bool valid_time(const struct tm *tm);
void set_day_of_week(struct tm *tm);
void set_day_of_year(struct tm *tm);
#endif
#endif /* _TIMEFUNCS_H_ */

View file

@ -45,9 +45,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return 0;
}

View file

@ -45,9 +45,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
set_day_of_year(tm);
return 0;
}