diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2009-08-11 17:54:47 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2009-08-11 17:54:47 +0000 |
commit | ed73a3274ca4bb3dec0cf067732bcdf4fe1a7d62 (patch) | |
tree | 8ac2786b04bc7149ced718b8c80e98010b7164fc /firmware/common | |
parent | 6cea3308d05c21aabe073f77c3d013485b0429a0 (diff) |
Add support for setting the clock using a special SCSI command. This is the same method that itunes uses, and there are host-side tools for it (e.g. libgpod)
Flyspray: FS#10514
Author: Laurent Papier and myself
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22255 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/timefuncs.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c index 6fdc0b7240..f5097c8e52 100644 --- a/firmware/common/timefuncs.c +++ b/firmware/common/timefuncs.c @@ -193,3 +193,42 @@ time_t mktime(struct tm *t) return(result); } #endif + +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 }; + + if(m == 0 || m == 1) y--; + return (d + mo[m] + y + y/4 - y/100 + y/400) % 7; +} + +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; + + 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; + } + else + { + for(i=1;i<12;i++) + { + if(yd <= t[i]) + { + *d = yd - t[i-1]; + *m = i; + break; + } + } + } +} |