From 44ee2ab577d3de6f078327f76b3e378cb09cde68 Mon Sep 17 00:00:00 2001 From: Markus Braun Date: Tue, 27 May 2003 14:28:08 +0000 Subject: 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 --- apps/settings.c | 8 ++------ apps/settings_menu.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'apps') 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[]) while ( !done ) { /* calculate the number of days in febuary */ realyear = timedate[3] + 2000; - - if(realyear > 2030) - realyear = 2003; /* yeah, I believe this is now */ - if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0) daysinmonth[1] = 29; else @@ -1765,8 +1761,8 @@ bool set_time(char* string, int timedate[]) lcd_getstringsize(buffer, &width, &prev_line_height); - snprintf(buffer, sizeof(buffer), "%s %04d %s %02d ", - str(dayname[timedate[6]]), realyear, + snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d ", + str(dayname[timedate[6]]), timedate[3], str(monthname[timedate[4] - 1]), timedate[5]); lcd_puts(0, 2, buffer); 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) timedate[3] = rtc_read(0x07); /* year */ timedate[4] = rtc_read(0x06); /* month */ timedate[5] = rtc_read(0x05); /* day */ - /* day of week not read, calculated */ + + /* day of week not read, calculated in set_time() */ /* hour */ timedate[0] = ((timedate[0] & 0x30) >> 4) * 10 + (timedate[0] & 0x0f); /* minute */ @@ -534,6 +535,29 @@ static bool timedate_set(void) timedate[4] = ((timedate[4] & 0x10) >> 4) * 10 + (timedate[4] & 0x0f); /* day */ timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); + + /* do some range checks */ + /* This prevents problems with time/date setting after a power loss */ + if (timedate[0] < 0 || timedate[0] > 23 || + timedate[1] < 0 || timedate[1] > 59 || + timedate[2] < 0 || timedate[2] > 59 || + timedate[3] < 0 || timedate[3] > 99 || + timedate[4] < 0 || timedate[4] > 12 || + timedate[5] < 0 || timedate[5] > 31) + { + /* hour */ + timedate[0] = 0; + /* minute */ + timedate[1] = 0; + /* second */ + timedate[2] = 0; + /* year */ + timedate[3] = 3; + /* month */ + timedate[4] = 1; + /* day */ + timedate[5] = 1; + } #endif result = set_time(str(LANG_TIME),timedate); -- cgit v1.2.3