summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2009-08-11 19:30:19 +0000
committerFrank Gevaerts <frank@gevaerts.be>2009-08-11 19:30:19 +0000
commit2dc50471ca17eaeb24b45abce4c0f8944cd781d5 (patch)
tree3e704d88f999b8ab071f6ca7753c06e692486cbf
parenteadfa483d1b014e39953669d79fb997d8cd1085d (diff)
downloadrockbox-2dc50471ca17eaeb24b45abce4c0f8944cd781d5.tar.gz
rockbox-2dc50471ca17eaeb24b45abce4c0f8944cd781d5.zip
Consolidate day of week calculation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22258 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/screens.c9
-rw-r--r--firmware/common/timefuncs.c7
-rw-r--r--firmware/include/timefuncs.h2
-rw-r--r--firmware/usbstack/usb_storage.c22
4 files changed, 19 insertions, 21 deletions
diff --git a/apps/screens.c b/apps/screens.c
index 9f1596cb7a..4ec35f9f57 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -511,7 +511,6 @@ bool set_time_screen(const char* title, struct tm *tm)
511 int button; 511 int button;
512 unsigned int i, j, s; 512 unsigned int i, j, s;
513 int cursorpos = 0; 513 int cursorpos = 0;
514 unsigned int julianday;
515 unsigned int realyear; 514 unsigned int realyear;
516 unsigned int width; 515 unsigned int width;
517 unsigned int min, max; 516 unsigned int min, max;
@@ -556,13 +555,7 @@ bool set_time_screen(const char* title, struct tm *tm)
556 tm->tm_mday = daysinmonth[tm->tm_mon]; 555 tm->tm_mday = daysinmonth[tm->tm_mon];
557 556
558 /* calculate day of week */ 557 /* calculate day of week */
559 julianday = tm->tm_mday; 558 set_day_of_week(tm);
560 for(i = 0; (int)i < tm->tm_mon; i++) {
561 julianday += daysinmonth[i];
562 }
563
564 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
565 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
566 559
567 /* put all the numbers we want from the tm struct into 560 /* put all the numbers we want from the tm struct into
568 an easily printable buffer */ 561 an easily printable buffer */
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index e59534eeba..774fba9ab0 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -194,12 +194,15 @@ time_t mktime(struct tm *t)
194} 194}
195#endif 195#endif
196 196
197int day_of_week(int m, int d, int y) 197void set_day_of_week(struct tm *tm)
198{ 198{
199 int y=tm->tm_year+1900;
200 int d=tm->tm_mday;
201 int m=tm->tm_mon;
199 static const char mo[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; 202 static const char mo[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
200 203
201 if(m == 0 || m == 1) y--; 204 if(m == 0 || m == 1) y--;
202 return (d + mo[m] + y + y/4 - y/100 + y/400) % 7; 205 tm->tm_wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
203} 206}
204 207
205void yearday_to_daymonth(int yd, int y, int *d, int *m) 208void yearday_to_daymonth(int yd, int y, int *d, int *m)
diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h
index 52d4608287..e9ef8075ac 100644
--- a/firmware/include/timefuncs.h
+++ b/firmware/include/timefuncs.h
@@ -29,7 +29,7 @@
29struct tm *get_time(void); 29struct tm *get_time(void);
30int set_time(const struct tm *tm); 30int set_time(const struct tm *tm);
31bool valid_time(const struct tm *tm); 31bool valid_time(const struct tm *tm);
32int day_of_week(int m, int d, int y); 32void set_day_of_week(struct tm *tm);
33void yearday_to_daymonth(int yd, int y, int *d, int *m); 33void yearday_to_daymonth(int yd, int y, int *d, int *m);
34#if CONFIG_RTC 34#if CONFIG_RTC
35time_t mktime(struct tm *t); 35time_t mktime(struct tm *t);
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 94f4f71dbb..a3664b074b 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -608,14 +608,13 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
608 } 608 }
609 break; 609 break;
610 case RECEIVING_TIME: 610 case RECEIVING_TIME:
611 tm.tm_year=(tb.transfer_buffer[0]<<8)+tb.transfer_buffer[1]; 611 tm.tm_year=(tb.transfer_buffer[0]<<8)+tb.transfer_buffer[1] - 1900;
612 tm.tm_yday=(tb.transfer_buffer[2]<<8)+tb.transfer_buffer[3]; 612 tm.tm_yday=(tb.transfer_buffer[2]<<8)+tb.transfer_buffer[3];
613 tm.tm_hour=tb.transfer_buffer[5]; 613 tm.tm_hour=tb.transfer_buffer[5];
614 tm.tm_min=tb.transfer_buffer[6]; 614 tm.tm_min=tb.transfer_buffer[6];
615 tm.tm_sec=tb.transfer_buffer[7]; 615 tm.tm_sec=tb.transfer_buffer[7];
616 yearday_to_daymonth(tm.tm_yday,tm.tm_year,&tm.tm_mday,&tm.tm_mon); 616 yearday_to_daymonth(tm.tm_yday,tm.tm_year + 1900,&tm.tm_mday,&tm.tm_mon);
617 tm.tm_wday=day_of_week(tm.tm_mon,tm.tm_mday,tm.tm_year); 617 set_day_of_week(&tm);
618 tm.tm_year -= 1900;
619 set_time(&tm); 618 set_time(&tm);
620 send_csw(UMS_STATUS_GOOD); 619 send_csw(UMS_STATUS_GOOD);
621 break; 620 break;
@@ -1081,16 +1080,19 @@ static void handle_scsi(struct command_block_wrapper* cbw)
1081 break; 1080 break;
1082 1081
1083 case SCSI_WRITE_BUFFER: 1082 case SCSI_WRITE_BUFFER:
1084 if(cbw->command_block[1]==1 1083 if(cbw->command_block[1]==1 /* mode = vendor specific */
1085 && cbw->command_block[2]==0 1084 && cbw->command_block[2]==0 /* buffer id = 0 */
1086 && cbw->command_block[3]==0x0c 1085
1086 && cbw->command_block[3]==0x0c /* offset (3 bytes) */
1087 && cbw->command_block[4]==0 1087 && cbw->command_block[4]==0
1088 && cbw->command_block[5]==0 1088 && cbw->command_block[5]==0
1089 && cbw->command_block[6]==0 1089
1090 /* Some versions of itunes set the parameter list length to 0.
1091 * Technically it should be 0x0c, which is what libgpod sends */
1092 && cbw->command_block[6]==0 /* parameter list (3 bytes) */
1090 && cbw->command_block[7]==0 1093 && cbw->command_block[7]==0
1091 /* Some versions of itunes set the next byte to 0. Technically
1092 * it should be 0x0c */
1093 && (cbw->command_block[8]==0 || cbw->command_block[8]==0x0c) 1094 && (cbw->command_block[8]==0 || cbw->command_block[8]==0x0c)
1095
1094 && cbw->command_block[9]==0) 1096 && cbw->command_block[9]==0)
1095 receive_time(); 1097 receive_time();
1096 break; 1098 break;