From 38d6bb9e713972c33e7c9e57b85ce10a71b32091 Mon Sep 17 00:00:00 2001 From: ydong10 Date: Thu, 28 Jul 2011 02:14:29 +0000 Subject: [PATCH] Adjust the day field when update the month and year field. Signed-off-by:ydong10 Reviewed-by:lgao4 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12054 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/SetupBrowserDxe/InputHandler.c | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c b/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c index 8f3b9e72dc..ecaf1d7429 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c @@ -214,6 +214,70 @@ ReadString ( } +/** + Adjust the value to the correct one. Rules follow the sample: + like: Year change: 2012.02.29 -> 2013.02.29 -> 2013.02.01 + Month change: 2013.03.29 -> 2013.02.29 -> 2013.02.28 + + @param Question Pointer to current question. + @param Sequence The sequence of the field in the question. +**/ +VOID +AdjustQuestionValue ( + IN FORM_BROWSER_STATEMENT *Question, + IN UINT8 Sequence + ) +{ + UINT8 Month; + UINT16 Year; + UINT8 Maximum; + UINT8 Minimum; + + if (Question->Operand != EFI_IFR_DATE_OP) { + return; + } + + Month = Question->HiiValue.Value.date.Month; + Year = Question->HiiValue.Value.date.Year; + Minimum = 1; + + switch (Month) { + case 2: + if ((Year % 4) == 0 && ((Year % 100) != 0 || (Year % 400) == 0)) { + Maximum = 29; + } else { + Maximum = 28; + } + break; + case 4: + case 6: + case 9: + case 11: + Maximum = 30; + break; + default: + Maximum = 31; + break; + } + + // + // Change the month area. + // + if (Sequence == 0) { + if (Question->HiiValue.Value.date.Day > Maximum) { + Question->HiiValue.Value.date.Day = Maximum; + } + } + + // + // Change the Year area. + // + if (Sequence == 2) { + if (Question->HiiValue.Value.date.Day > Maximum) { + Question->HiiValue.Value.date.Day = Minimum; + } + } +} /** This routine reads a numeric value from the user input. @@ -646,6 +710,16 @@ EnterCarriageReturn: QuestionValue->Value.u64 = EditValue; } + // + // Adjust the value to the correct one. + // Sample like: 2012.02.29 -> 2013.02.29 -> 2013.02.01 + // 2013.03.29 -> 2013.02.29 -> 2013.02.28 + // + if (Question->Operand == EFI_IFR_DATE_OP && + (MenuOption->Sequence == 0 || MenuOption->Sequence == 2)) { + AdjustQuestionValue (Question, (UINT8)MenuOption->Sequence); + } + // // Check to see if the Value is something reasonable against consistency limitations. // If not, let's kick the error specified. -- 2.39.2