summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2009-08-11 18:54:13 +0000
committerFrank Gevaerts <frank@gevaerts.be>2009-08-11 18:54:13 +0000
commiteadfa483d1b014e39953669d79fb997d8cd1085d (patch)
treea2387c2e8ff023200f8e5dfff29a9b09287303e7 /firmware/common
parent61cf78337145759bed8f426d31c670ba4bb39bd8 (diff)
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
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/timefuncs.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index f5097c8e52..e59534eeba 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -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]++;
+ t=tl;
}
-
- yd++;
- if(yd <= 31)
+ else
{
- *d = yd;
- *m = 0;
+ t=tnl;
}
- else
+
+ while(yd >= t[i] && i<12)
{
- for(i=1;i<12;i++)
- {
- if(yd <= t[i])
- {
- *d = yd - t[i-1];
- *m = i;
- break;
- }
- }
+ yd-=t[i];
+ i++;
}
+ *d = yd+1;
+ *m = i;
}