From ac74e6d5db7ccad29001bb58d1a255c9cab51f4d Mon Sep 17 00:00:00 2001 From: xiaojiazhu Date: Fri, 8 Dec 2023 17:56:01 +0800 Subject: [PATCH] Fixed bug number 9763. --- .../UIFlowMenuCommonItem/MenuGeneral.c | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuGeneral.c b/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuGeneral.c index 6247c0f37..23aefcf7f 100644 --- a/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuGeneral.c +++ b/code/application/source/cardv/SrcCode/UIWnd/LVGL_SPORTCAM/UIFlowLVGL/UIFlowMenuCommonItem/MenuGeneral.c @@ -1045,7 +1045,36 @@ void Option_Operating_Time_Key(lv_obj_t* obj, uint32_t key) break; } } +UINT16 sf_get_month_days(UINT16 year, UINT16 month) +{ + UINT16 maxday = 0; + + printf("sf_get_month_days year=%d, month=%d\n", year, month); + + switch(month) + { + case 4: + case 6: + case 9: + case 11: + maxday = 30; + break; + case 2: + if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) + maxday = 29; + else + maxday = 28; + break; + default: + maxday = 31; + break; + } + + printf("maxday=%d\n", maxday); + + return maxday; +} // -------------------------------------------------------------------------- // DateTime // -------------------------------------------------------------------------- @@ -1084,7 +1113,10 @@ static void update_DateTime_Time_msg(lv_obj_t* obj) DBG_ERR("DateTime component is not initialized"); return; } - + if (gDateTime.Day > sf_get_month_days(gDateTime.Year, gDateTime.Mon)) + { + gDateTime.Day = sf_get_month_days(gDateTime.Year, gDateTime.Mon); + } // UIMenuStoreInfo *puiPara = sf_ui_para_get(); snprintf(DateTimeMOBuf, 3, "%02d", gDateTime.Mon); snprintf(DateTimeDDBuf, 3, "%02d", gDateTime.Day); @@ -1242,10 +1274,10 @@ void Option_DateTime_Key(lv_obj_t* obj, uint32_t key) } else if(DateTimeIndex == 2) { - if(gDateTime.Day > 1 && gDateTime.Day <= 31) + if(gDateTime.Day > 1 && gDateTime.Day <= sf_get_month_days(gDateTime.Year, gDateTime.Mon)) gDateTime.Day--; else - gDateTime.Day = 31; + gDateTime.Day = sf_get_month_days(gDateTime.Year, gDateTime.Mon); } else if(DateTimeIndex == 4) { @@ -1287,7 +1319,7 @@ void Option_DateTime_Key(lv_obj_t* obj, uint32_t key) } else if(DateTimeIndex == 2) { - if(gDateTime.Day >= 31) + if(gDateTime.Day >= sf_get_month_days(gDateTime.Year, gDateTime.Mon)) gDateTime.Day = 1; else gDateTime.Day++; @@ -1360,10 +1392,10 @@ void Option_DateTime_Key_Long_Press(lv_obj_t* obj, uint32_t key) } else if(DateTimeIndex == 2) { - if(gDateTime.Day > 0 && gDateTime.Day <= 31) + if(gDateTime.Day > 0 && gDateTime.Day <= sf_get_month_days(gDateTime.Year, gDateTime.Mon)) gDateTime.Day--; else - gDateTime.Day = 31; + gDateTime.Day = sf_get_month_days(gDateTime.Year, gDateTime.Mon); } else if(DateTimeIndex == 4) { @@ -1405,7 +1437,7 @@ void Option_DateTime_Key_Long_Press(lv_obj_t* obj, uint32_t key) } else if(DateTimeIndex == 2) { - if(gDateTime.Day >= 31) + if(gDateTime.Day >= sf_get_month_days(gDateTime.Year, gDateTime.Mon)) gDateTime.Day = 0; else gDateTime.Day++;