diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 90edc613c..212aad7f8 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -388,7 +388,7 @@ int cliSet(const char ** argv) struct gtm t; int year, month, day, hour, minute, second; if (toInt(argv, 2, &year) > 0 && toInt(argv, 3, &month) > 0 && toInt(argv, 4, &day) > 0 && toInt(argv, 5, &hour) > 0 && toInt(argv, 6, &minute) > 0 && toInt(argv, 7, &second) > 0) { - t.tm_year = year-1900; + t.tm_year = year-TM_YEAR_BASE; t.tm_mon = month-1; t.tm_mday = day; t.tm_hour = hour; @@ -587,7 +587,7 @@ int cliDisplay(const char ** argv) else if (!strcmp(argv[1], "rtc")) { struct gtm utm; gettime(&utm); - serialPrint("rtc = %4d-%02d-%02d %02d:%02d:%02d.%02d0", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); + serialPrint("rtc = %4d-%02d-%02d %02d:%02d:%02d.%02d0", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); } else if (!strcmp(argv[1], "volume")) { serialPrint("volume = %d", getVolume()); diff --git a/radio/src/debug.cpp b/radio/src/debug.cpp index ac98ce7cd..da30be14e 100644 --- a/radio/src/debug.cpp +++ b/radio/src/debug.cpp @@ -88,7 +88,7 @@ void dumpTraceBuffer() struct gtm tp; filltm(&traceBuffer[n].time, &tp); TRACE_NOCRLF("%02d ", n); - TRACE_NOCRLF("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+1900, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms); + TRACE_NOCRLF("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+TM_YEAR_BASE, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms); TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data); if (traceBuffer[n].time == 0 && traceBuffer[n].time_ms == 0) break; #if !defined(SIMU) diff --git a/radio/src/gui/128x64/radio_setup.cpp b/radio/src/gui/128x64/radio_setup.cpp index ba54eb55e..aba344d10 100644 --- a/radio/src/gui/128x64/radio_setup.cpp +++ b/radio/src/gui/128x64/radio_setup.cpp @@ -163,7 +163,7 @@ void menuRadioSetup(event_t event) uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0); switch (j) { case 0: - lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+1900, rowattr|RIGHT); + lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+TM_YEAR_BASE, rowattr|RIGHT); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0); break; case 1: @@ -172,7 +172,7 @@ void menuRadioSetup(event_t event) break; case 2: { - int16_t year = 1900 + t.tm_year; + int16_t year = TM_YEAR_BASE + t.tm_year; int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0); static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; dlim += pgm_read_byte(&dmon[t.tm_mon]); diff --git a/radio/src/gui/212x64/radio_setup.cpp b/radio/src/gui/212x64/radio_setup.cpp index a964319c5..cdf781db7 100644 --- a/radio/src/gui/212x64/radio_setup.cpp +++ b/radio/src/gui/212x64/radio_setup.cpp @@ -137,7 +137,7 @@ void menuRadioSetup(event_t event) uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0); switch (j) { case 0: - lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+1900, rowattr|RIGHT); + lcdDrawNumber(RADIO_SETUP_DATE_COLUMN, y, t.tm_year+TM_YEAR_BASE, rowattr|RIGHT); if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0); break; case 1: @@ -146,7 +146,7 @@ void menuRadioSetup(event_t event) break; case 2: { - int16_t year = 1900 + t.tm_year; + int16_t year = TM_YEAR_BASE + t.tm_year; int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0); static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; dlim += pgm_read_byte(&dmon[t.tm_mon]); diff --git a/radio/src/gui/480x272/radio_setup.cpp b/radio/src/gui/480x272/radio_setup.cpp index 1451b3663..5d3d258ed 100644 --- a/radio/src/gui/480x272/radio_setup.cpp +++ b/radio/src/gui/480x272/radio_setup.cpp @@ -143,7 +143,7 @@ bool menuRadioSetup(event_t event) uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0); switch (j) { case 0: - lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, t.tm_year+1900, flags|rowattr); + lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, t.tm_year+TM_YEAR_BASE, flags|rowattr); if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0); lcdDrawText(lcdNextPos+3, y, "-", flags); break; @@ -154,7 +154,7 @@ bool menuRadioSetup(event_t event) break; case 2: { - int16_t year = 1900 + t.tm_year; + int16_t year = TM_YEAR_BASE + t.tm_year; int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0); static const pm_uint8_t dmon[] PROGMEM = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; dlim += pgm_read_byte(&dmon[t.tm_mon]); diff --git a/radio/src/logs.cpp b/radio/src/logs.cpp index e30f9b3b7..53fc1d192 100644 --- a/radio/src/logs.cpp +++ b/radio/src/logs.cpp @@ -236,7 +236,7 @@ void logsWrite() lastRtcTime = g_rtcTime; gettime(&utm); } - f_printf(&g_oLogFile, "%4d-%02d-%02d,%02d:%02d:%02d.%02d0,", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); + f_printf(&g_oLogFile, "%4d-%02d-%02d,%02d:%02d:%02d.%02d0,", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); } #else f_printf(&g_oLogFile, "%d,", tmr10ms); diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 7c65dc8e1..4fff1df59 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -141,7 +141,7 @@ static int luaGetDateTime(lua_State * L) { struct gtm utm; gettime(&utm); - luaPushDateTime(L, utm.tm_year + 1900, utm.tm_mon + 1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec); + luaPushDateTime(L, utm.tm_year + TM_YEAR_BASE, utm.tm_mon + 1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec); return 1; } diff --git a/radio/src/rtc.cpp b/radio/src/rtc.cpp index 49135c4e2..baa5fadce 100644 --- a/radio/src/rtc.cpp +++ b/radio/src/rtc.cpp @@ -87,7 +87,6 @@ static_assert(TYPE_TWOS_COMPLEMENT(int), "twos complement arithmetic"); diagnostic on some hosts. */ #define EPOCH_YEAR 1970 -#define TM_YEAR_BASE 1900 static_assert(TM_YEAR_BASE % 100 == 0, "base year is not a multiple of 100"); /* Return 1 if YEAR + TM_YEAR_BASE is a leap year. */ @@ -148,8 +147,8 @@ int __offtime(const gtime_t * t, long int offset, struct gtm * tp) days -= ((yg - y) * 365 + LEAPS_THRU_END_OF(yg - 1) - LEAPS_THRU_END_OF(y - 1)); y = yg; } - tp->tm_year = y - 1900; - if (tp->tm_year != y - 1900) { + tp->tm_year = y - TM_YEAR_BASE; + if (tp->tm_year != y - TM_YEAR_BASE) { /* The year cannot be represented due to overflow. */ // __set_errno (EOVERFLOW); return 0; @@ -465,7 +464,7 @@ uint8_t rtcAdjust(uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t // convert given UTC time to local time (to seconds) and compare it with RTC struct gtm t; - t.tm_year = year - 1900; + t.tm_year = year - TM_YEAR_BASE; t.tm_mon = mon - 1; t.tm_mday = day; t.tm_hour = hour; diff --git a/radio/src/rtc.h b/radio/src/rtc.h index efbe8f3fb..01464cb86 100644 --- a/radio/src/rtc.h +++ b/radio/src/rtc.h @@ -25,6 +25,7 @@ #define SECS_PER_HOUR 3600ul #define SECS_PER_DAY 86400ul +#define TM_YEAR_BASE 1900 typedef long int gtime_t; diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index 8f98ad749..5f7f15c63 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -425,7 +425,7 @@ char * strAppendDate(char * str, bool time) str[0] = '-'; struct gtm utm; gettime(&utm); - div_t qr = div(utm.tm_year+1900, 10); + div_t qr = div(utm.tm_year+TM_YEAR_BASE, 10); str[4] = '0' + qr.rem; qr = div(qr.quot, 10); str[3] = '0' + qr.rem; diff --git a/radio/src/targets/gruvin9x/rtc_driver.cpp b/radio/src/targets/gruvin9x/rtc_driver.cpp index 3d5eda507..e1d25b2e2 100644 --- a/radio/src/targets/gruvin9x/rtc_driver.cpp +++ b/radio/src/targets/gruvin9x/rtc_driver.cpp @@ -254,7 +254,7 @@ void rtcGetTime(struct gtm * utm) g9x_rtcGetTime(&rtc); - utm->tm_year = rtc.year - 1900; + utm->tm_year = rtc.year - TM_YEAR_BASE; utm->tm_mon = rtc.month - 1; utm->tm_mday = rtc.mday; utm->tm_hour = rtc.hour; @@ -268,7 +268,7 @@ void rtcSetTime(const struct gtm * t) g_ms100 = 0; // start of next second begins now RTC rtc; - rtc.year = t->tm_year + 1900; + rtc.year = t->tm_year + TM_YEAR_BASE; rtc.month = t->tm_mon + 1; rtc.mday = t->tm_mday; rtc.hour = t->tm_hour; diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 2a2b4e3b7..6e64a879c 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -1203,7 +1203,7 @@ void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef * RTC_DateStruct) time_t tme; time(&tme); struct tm * timeinfo = localtime(&tme); - RTC_DateStruct->RTC_Year = timeinfo->tm_year - 1900; + RTC_DateStruct->RTC_Year = timeinfo->tm_year - TM_YEAR_BASE; RTC_DateStruct->RTC_Month = timeinfo->tm_mon + 1; RTC_DateStruct->RTC_Date = timeinfo->tm_mday; } diff --git a/radio/src/targets/sky9x/coproc_driver.cpp b/radio/src/targets/sky9x/coproc_driver.cpp index e6dc9a40d..d94106cdc 100644 --- a/radio/src/targets/sky9x/coproc_driver.cpp +++ b/radio/src/targets/sky9x/coproc_driver.cpp @@ -164,7 +164,7 @@ extern "C" void TWI0_IRQHandler() utm.tm_hour = Co_proc_status[3] ; utm.tm_mday = Co_proc_status[4] ; utm.tm_mon = Co_proc_status[5] - 1; - utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - 1900; + utm.tm_year = (Co_proc_status[6] + ( Co_proc_status[7] << 8 )) - TM_YEAR_BASE; g_rtcTime = gmktime(&utm); } Coproc_temp = Co_proc_status[8]; diff --git a/radio/src/targets/sky9x/rtc_driver.cpp b/radio/src/targets/sky9x/rtc_driver.cpp index 0035aa30e..a70a6cdf7 100644 --- a/radio/src/targets/sky9x/rtc_driver.cpp +++ b/radio/src/targets/sky9x/rtc_driver.cpp @@ -246,8 +246,8 @@ void rtcSetTime(const struct gtm * t) I2CTime.Time[2] = t->tm_hour ; I2CTime.Time[3] = t->tm_mday ; I2CTime.Time[4] = t->tm_mon+1 ; - I2CTime.Time[5] = (uint8_t) (t->tm_year+1900); - I2CTime.Time[6] = (t->tm_year+1900) >> 8; + I2CTime.Time[5] = (uint8_t) (t->tm_year+TM_YEAR_BASE); + I2CTime.Time[6] = (t->tm_year+TM_YEAR_BASE) >> 8; #if defined(REVX) writeRTC((uint8_t *)&I2CTime.Time[0]) ; #elif defined(COPROCESSOR) diff --git a/radio/src/telemetry/telemetry.cpp b/radio/src/telemetry/telemetry.cpp index 9977528d4..c93c65284 100644 --- a/radio/src/telemetry/telemetry.cpp +++ b/radio/src/telemetry/telemetry.cpp @@ -470,7 +470,7 @@ void logTelemetryWriteStart() if (lastTime != newTime) { struct gtm utm; gettime(&utm); - f_printf(&g_telemetryFile, "\r\n%4d-%02d-%02d,%02d:%02d:%02d.%02d0:", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); + f_printf(&g_telemetryFile, "\r\n%4d-%02d-%02d,%02d:%02d:%02d.%02d0:", utm.tm_year+TM_YEAR_BASE, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100); lastTime = newTime; } }