rework new time handling functions a bit to be more memory efficient
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22257 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
61cf783371
commit
eadfa483d1
1 changed files with 15 additions and 21 deletions
|
@ -196,7 +196,7 @@ time_t mktime(struct tm *t)
|
|||
|
||||
int day_of_week(int m, int d, int y)
|
||||
{
|
||||
char mo[12] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
|
||||
static const char mo[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
|
||||
|
||||
if(m == 0 || m == 1) y--;
|
||||
return (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
|
||||
|
@ -204,31 +204,25 @@ int day_of_week(int m, int d, int y)
|
|||
|
||||
void yearday_to_daymonth(int yd, int y, int *d, int *m)
|
||||
{
|
||||
short t[12] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||
int i;
|
||||
static const char tnl[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
static const char tl[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
const char *t;
|
||||
int i=0;
|
||||
|
||||
if((y%4 == 0 && y%100 != 0) || y%400 == 0)
|
||||
{
|
||||
for(i=1;i<12;i++)
|
||||
t[i]++;
|
||||
}
|
||||
|
||||
yd++;
|
||||
if(yd <= 31)
|
||||
{
|
||||
*d = yd;
|
||||
*m = 0;
|
||||
t=tl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=1;i<12;i++)
|
||||
{
|
||||
if(yd <= t[i])
|
||||
{
|
||||
*d = yd - t[i-1];
|
||||
*m = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
t=tnl;
|
||||
}
|
||||
|
||||
while(yd >= t[i] && i<12)
|
||||
{
|
||||
yd-=t[i];
|
||||
i++;
|
||||
}
|
||||
*d = yd+1;
|
||||
*m = i;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue