diff options
Diffstat (limited to 'firmware')
-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) 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; } |