]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Adjust the day field when update the month and year field.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Jul 2011 02:14:29 +0000 (02:14 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Jul 2011 02:14:29 +0000 (02:14 +0000)
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

MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c

index 8f3b9e72dc61f4699c1c587df8f317606ea239ac..ecaf1d74294515f38b79a1a898740121789a2338 100644 (file)
@@ -214,6 +214,70 @@ ReadString (
 \r
 }\r
 \r
+/**\r
+  Adjust the value to the correct one. Rules follow the sample:\r
+  like:  Year change:  2012.02.29 -> 2013.02.29 -> 2013.02.01\r
+         Month change: 2013.03.29 -> 2013.02.29 -> 2013.02.28\r
+\r
+  @param  Question          Pointer to current question.\r
+  @param  Sequence          The sequence of the field in the question.\r
+**/\r
+VOID\r
+AdjustQuestionValue (\r
+  IN  FORM_BROWSER_STATEMENT  *Question,\r
+  IN  UINT8                   Sequence\r
+  )\r
+{\r
+  UINT8     Month;\r
+  UINT16    Year;\r
+  UINT8     Maximum;\r
+  UINT8     Minimum;\r
+\r
+  if (Question->Operand != EFI_IFR_DATE_OP) {\r
+    return;\r
+  }\r
+\r
+  Month   = Question->HiiValue.Value.date.Month;\r
+  Year    = Question->HiiValue.Value.date.Year;\r
+  Minimum = 1;\r
+\r
+  switch (Month) {\r
+  case 2:\r
+    if ((Year % 4) == 0 && ((Year % 100) != 0 || (Year % 400) == 0)) {\r
+      Maximum = 29;\r
+    } else {\r
+      Maximum = 28;\r
+    }\r
+    break;\r
+  case 4:\r
+  case 6:\r
+  case 9:\r
+  case 11:\r
+    Maximum = 30;\r
+    break;\r
+  default:\r
+    Maximum = 31;\r
+    break;\r
+  }\r
+\r
+  //\r
+  // Change the month area.\r
+  //\r
+  if (Sequence == 0) {\r
+    if (Question->HiiValue.Value.date.Day > Maximum) {\r
+      Question->HiiValue.Value.date.Day = Maximum;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Change the Year area.\r
+  //\r
+  if (Sequence == 2) {\r
+    if (Question->HiiValue.Value.date.Day > Maximum) {\r
+      Question->HiiValue.Value.date.Day = Minimum;\r
+    }\r
+  }\r
+}\r
 \r
 /**\r
   This routine reads a numeric value from the user input.\r
@@ -646,6 +710,16 @@ EnterCarriageReturn:
         QuestionValue->Value.u64 = EditValue;\r
       }\r
 \r
+      //\r
+      // Adjust the value to the correct one.\r
+      // Sample like: 2012.02.29 -> 2013.02.29 -> 2013.02.01\r
+      //              2013.03.29 -> 2013.02.29 -> 2013.02.28\r
+      //\r
+      if (Question->Operand == EFI_IFR_DATE_OP && \r
+        (MenuOption->Sequence == 0 || MenuOption->Sequence == 2)) {\r
+        AdjustQuestionValue (Question, (UINT8)MenuOption->Sequence);\r
+      }\r
+\r
       //\r
       // Check to see if the Value is something reasonable against consistency limitations.\r
       // If not, let's kick the error specified.\r