diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2009-08-11 18:54:13 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2009-08-11 18:54:13 +0000 |
commit | eadfa483d1b014e39953669d79fb997d8cd1085d (patch) | |
tree | a2387c2e8ff023200f8e5dfff29a9b09287303e7 | |
parent | 61cf78337145759bed8f426d31c670ba4bb39bd8 (diff) | |
download | rockbox-eadfa483d1b014e39953669d79fb997d8cd1085d.tar.gz rockbox-eadfa483d1b014e39953669d79fb997d8cd1085d.zip |
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
-rw-r--r-- | firmware/common/timefuncs.c | 34 |
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) | |||
196 | 196 | ||
197 | int day_of_week(int m, int d, int y) | 197 | int day_of_week(int m, int d, int y) |
198 | { | 198 | { |
199 | char mo[12] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; | 199 | static const char mo[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; |
200 | 200 | ||
201 | if(m == 0 || m == 1) y--; | 201 | if(m == 0 || m == 1) y--; |
202 | return (d + mo[m] + y + y/4 - y/100 + y/400) % 7; | 202 | 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) | |||
204 | 204 | ||
205 | void yearday_to_daymonth(int yd, int y, int *d, int *m) | 205 | void yearday_to_daymonth(int yd, int y, int *d, int *m) |
206 | { | 206 | { |
207 | short t[12] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; | 207 | static const char tnl[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
208 | int i; | 208 | static const char tl[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
209 | const char *t; | ||
210 | int i=0; | ||
209 | 211 | ||
210 | if((y%4 == 0 && y%100 != 0) || y%400 == 0) | 212 | if((y%4 == 0 && y%100 != 0) || y%400 == 0) |
211 | { | 213 | { |
212 | for(i=1;i<12;i++) | 214 | t=tl; |
213 | t[i]++; | ||
214 | } | 215 | } |
215 | 216 | else | |
216 | yd++; | ||
217 | if(yd <= 31) | ||
218 | { | 217 | { |
219 | *d = yd; | 218 | t=tnl; |
220 | *m = 0; | ||
221 | } | 219 | } |
222 | else | 220 | |
221 | while(yd >= t[i] && i<12) | ||
223 | { | 222 | { |
224 | for(i=1;i<12;i++) | 223 | yd-=t[i]; |
225 | { | 224 | i++; |
226 | if(yd <= t[i]) | ||
227 | { | ||
228 | *d = yd - t[i-1]; | ||
229 | *m = i; | ||
230 | break; | ||
231 | } | ||
232 | } | ||
233 | } | 225 | } |
226 | *d = yd+1; | ||
227 | *m = i; | ||
234 | } | 228 | } |