From ed73a3274ca4bb3dec0cf067732bcdf4fe1a7d62 Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Tue, 11 Aug 2009 17:54:47 +0000 Subject: 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 --- firmware/common/timefuncs.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'firmware/common/timefuncs.c') 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; + } + } + } +} -- cgit v1.2.3