summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarkus Braun <markus.braun@krawel.de>2003-05-27 14:28:08 +0000
committerMarkus Braun <markus.braun@krawel.de>2003-05-27 14:28:08 +0000
commit44ee2ab577d3de6f078327f76b3e378cb09cde68 (patch)
treeafc4a9d8bd124ff65bbca2cb919e6858805d8ccb /apps
parent9c76ee92aa54f9309bbece73031e0f356fdf8821 (diff)
downloadrockbox-44ee2ab577d3de6f078327f76b3e378cb09cde68.tar.gz
rockbox-44ee2ab577d3de6f078327f76b3e378cb09cde68.zip
Fix for time/date setting after power loss (battery change).
After a power loss, the time in the setting screen is set to 00:00 01/01/2003. Fixes Bug report #715081, #741391, #742672 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3700 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/settings.c8
-rw-r--r--apps/settings_menu.c26
2 files changed, 27 insertions, 7 deletions
diff --git a/apps/settings.c b/apps/settings.c
index a6d31341f8..368f05ff9e 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -1707,10 +1707,6 @@ bool set_time(char* string, int timedate[])
1707 while ( !done ) { 1707 while ( !done ) {
1708 /* calculate the number of days in febuary */ 1708 /* calculate the number of days in febuary */
1709 realyear = timedate[3] + 2000; 1709 realyear = timedate[3] + 2000;
1710
1711 if(realyear > 2030)
1712 realyear = 2003; /* yeah, I believe this is now */
1713
1714 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0) 1710 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
1715 daysinmonth[1] = 29; 1711 daysinmonth[1] = 29;
1716 else 1712 else
@@ -1765,8 +1761,8 @@ bool set_time(char* string, int timedate[])
1765 1761
1766 lcd_getstringsize(buffer, &width, &prev_line_height); 1762 lcd_getstringsize(buffer, &width, &prev_line_height);
1767 1763
1768 snprintf(buffer, sizeof(buffer), "%s %04d %s %02d ", 1764 snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d ",
1769 str(dayname[timedate[6]]), realyear, 1765 str(dayname[timedate[6]]), timedate[3],
1770 str(monthname[timedate[4] - 1]), timedate[5]); 1766 str(monthname[timedate[4] - 1]), timedate[5]);
1771 lcd_puts(0, 2, buffer); 1767 lcd_puts(0, 2, buffer);
1772 1768
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index db6499a313..4fa80676d8 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -521,7 +521,8 @@ static bool timedate_set(void)
521 timedate[3] = rtc_read(0x07); /* year */ 521 timedate[3] = rtc_read(0x07); /* year */
522 timedate[4] = rtc_read(0x06); /* month */ 522 timedate[4] = rtc_read(0x06); /* month */
523 timedate[5] = rtc_read(0x05); /* day */ 523 timedate[5] = rtc_read(0x05); /* day */
524 /* day of week not read, calculated */ 524
525 /* day of week not read, calculated in set_time() */
525 /* hour */ 526 /* hour */
526 timedate[0] = ((timedate[0] & 0x30) >> 4) * 10 + (timedate[0] & 0x0f); 527 timedate[0] = ((timedate[0] & 0x30) >> 4) * 10 + (timedate[0] & 0x0f);
527 /* minute */ 528 /* minute */
@@ -534,6 +535,29 @@ static bool timedate_set(void)
534 timedate[4] = ((timedate[4] & 0x10) >> 4) * 10 + (timedate[4] & 0x0f); 535 timedate[4] = ((timedate[4] & 0x10) >> 4) * 10 + (timedate[4] & 0x0f);
535 /* day */ 536 /* day */
536 timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); 537 timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f);
538
539 /* do some range checks */
540 /* This prevents problems with time/date setting after a power loss */
541 if (timedate[0] < 0 || timedate[0] > 23 ||
542 timedate[1] < 0 || timedate[1] > 59 ||
543 timedate[2] < 0 || timedate[2] > 59 ||
544 timedate[3] < 0 || timedate[3] > 99 ||
545 timedate[4] < 0 || timedate[4] > 12 ||
546 timedate[5] < 0 || timedate[5] > 31)
547 {
548 /* hour */
549 timedate[0] = 0;
550 /* minute */
551 timedate[1] = 0;
552 /* second */
553 timedate[2] = 0;
554 /* year */
555 timedate[3] = 3;
556 /* month */
557 timedate[4] = 1;
558 /* day */
559 timedate[5] = 1;
560 }
537#endif 561#endif
538 562
539 result = set_time(str(LANG_TIME),timedate); 563 result = set_time(str(LANG_TIME),timedate);