Consolidate day of week calculation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22258 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
eadfa483d1
commit
2dc50471ca
4 changed files with 19 additions and 21 deletions
|
@ -511,7 +511,6 @@ bool set_time_screen(const char* title, struct tm *tm)
|
|||
int button;
|
||||
unsigned int i, j, s;
|
||||
int cursorpos = 0;
|
||||
unsigned int julianday;
|
||||
unsigned int realyear;
|
||||
unsigned int width;
|
||||
unsigned int min, max;
|
||||
|
@ -556,13 +555,7 @@ bool set_time_screen(const char* title, struct tm *tm)
|
|||
tm->tm_mday = daysinmonth[tm->tm_mon];
|
||||
|
||||
/* calculate day of week */
|
||||
julianday = tm->tm_mday;
|
||||
for(i = 0; (int)i < tm->tm_mon; i++) {
|
||||
julianday += daysinmonth[i];
|
||||
}
|
||||
|
||||
tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
|
||||
(realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
|
||||
set_day_of_week(tm);
|
||||
|
||||
/* put all the numbers we want from the tm struct into
|
||||
an easily printable buffer */
|
||||
|
|
|
@ -194,12 +194,15 @@ time_t mktime(struct tm *t)
|
|||
}
|
||||
#endif
|
||||
|
||||
int day_of_week(int m, int d, int y)
|
||||
void set_day_of_week(struct tm *tm)
|
||||
{
|
||||
int y=tm->tm_year+1900;
|
||||
int d=tm->tm_mday;
|
||||
int m=tm->tm_mon;
|
||||
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;
|
||||
tm->tm_wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
|
||||
}
|
||||
|
||||
void yearday_to_daymonth(int yd, int y, int *d, int *m)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
struct tm *get_time(void);
|
||||
int set_time(const struct tm *tm);
|
||||
bool valid_time(const struct tm *tm);
|
||||
int day_of_week(int m, int d, int y);
|
||||
void set_day_of_week(struct tm *tm);
|
||||
void yearday_to_daymonth(int yd, int y, int *d, int *m);
|
||||
#if CONFIG_RTC
|
||||
time_t mktime(struct tm *t);
|
||||
|
|
|
@ -608,14 +608,13 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
|
|||
}
|
||||
break;
|
||||
case RECEIVING_TIME:
|
||||
tm.tm_year=(tb.transfer_buffer[0]<<8)+tb.transfer_buffer[1];
|
||||
tm.tm_year=(tb.transfer_buffer[0]<<8)+tb.transfer_buffer[1] - 1900;
|
||||
tm.tm_yday=(tb.transfer_buffer[2]<<8)+tb.transfer_buffer[3];
|
||||
tm.tm_hour=tb.transfer_buffer[5];
|
||||
tm.tm_min=tb.transfer_buffer[6];
|
||||
tm.tm_sec=tb.transfer_buffer[7];
|
||||
yearday_to_daymonth(tm.tm_yday,tm.tm_year,&tm.tm_mday,&tm.tm_mon);
|
||||
tm.tm_wday=day_of_week(tm.tm_mon,tm.tm_mday,tm.tm_year);
|
||||
tm.tm_year -= 1900;
|
||||
yearday_to_daymonth(tm.tm_yday,tm.tm_year + 1900,&tm.tm_mday,&tm.tm_mon);
|
||||
set_day_of_week(&tm);
|
||||
set_time(&tm);
|
||||
send_csw(UMS_STATUS_GOOD);
|
||||
break;
|
||||
|
@ -1081,16 +1080,19 @@ static void handle_scsi(struct command_block_wrapper* cbw)
|
|||
break;
|
||||
|
||||
case SCSI_WRITE_BUFFER:
|
||||
if(cbw->command_block[1]==1
|
||||
&& cbw->command_block[2]==0
|
||||
&& cbw->command_block[3]==0x0c
|
||||
if(cbw->command_block[1]==1 /* mode = vendor specific */
|
||||
&& cbw->command_block[2]==0 /* buffer id = 0 */
|
||||
|
||||
&& cbw->command_block[3]==0x0c /* offset (3 bytes) */
|
||||
&& cbw->command_block[4]==0
|
||||
&& cbw->command_block[5]==0
|
||||
&& cbw->command_block[6]==0
|
||||
|
||||
/* Some versions of itunes set the parameter list length to 0.
|
||||
* Technically it should be 0x0c, which is what libgpod sends */
|
||||
&& cbw->command_block[6]==0 /* parameter list (3 bytes) */
|
||||
&& cbw->command_block[7]==0
|
||||
/* Some versions of itunes set the next byte to 0. Technically
|
||||
* it should be 0x0c */
|
||||
&& (cbw->command_block[8]==0 || cbw->command_block[8]==0x0c)
|
||||
|
||||
&& cbw->command_block[9]==0)
|
||||
receive_time();
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue