application: fix month handling

This commit is contained in:
King Kévin 2017-08-01 11:49:43 +02:00
parent a69cdac1e1
commit 1792196219
1 changed files with 3 additions and 3 deletions

View File

@ -143,14 +143,14 @@ static void process_command(char* str)
if (!word) {
time_rtc = rtc_get_counter_val(); // get time from internal RTC
time_tm = localtime(&time_rtc); // convert time
printf("date: %d-%02d-%02d\n", 1900+time_tm->tm_year, time_tm->tm_mon, time_tm->tm_mday);
printf("date: %d-%02d-%02d\n", 1900+time_tm->tm_year, time_tm->tm_mon+1, time_tm->tm_mday);
} else if (strlen(word)!=10 || word[0]!='2' || word[1]!='0' || word[2]<'0' || word[2]>'9' || word[3]<'0' || word[3]>'9' || word[5]<'0' || word[5]>'1' || word[6]<'0' || word[6]>'9' || word[8]<'0' || word[8]>'3' || word[9]<'0' || word[9]>'9') {
goto error;
} else {
time_rtc = rtc_get_counter_val(); // get time from internal RTC
time_tm = localtime(&time_rtc); // convert time
time_tm->tm_year = ((word[0]-'0')*1000+(word[1]-'0')*100+(word[2]-'0')*10+(word[3]-'0')*1)-1900; // set year
time_tm->tm_mon = (word[5]-'0')*10+(word[6]-'0')*1; // set month
time_tm->tm_mon = (word[5]-'0')*10+(word[6]-'0')*1-1; // set month
time_tm->tm_mday = (word[8]-'0')*10+(word[9]-'0')*1; // set day
time_rtc = mktime(time_tm); // get back seconds
rtc_set_counter_val(time_rtc); // save time to internal RTC
@ -214,7 +214,7 @@ void main(void)
time_rtc= rtc_get_counter_val(); // get time from internal RTC
time_tm = localtime(&time_rtc); // convert time
printf("date: %d-%02d-%02d %02d:%02d:%02d\n", 1900+time_tm->tm_year, time_tm->tm_mon, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
printf("date: %d-%02d-%02d %02d:%02d:%02d\n", 1900+time_tm->tm_year, time_tm->tm_mon+1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
// main loop
printf("command input: ready\n");