[NUI] Support last day of month when month change in DatePicker
authorWoochanlee <wc0917.lee@samsung.com>
Wed, 26 Jan 2022 09:18:48 +0000 (18:18 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 24 Feb 2022 06:57:08 +0000 (15:57 +0900)
Previously, DatePicker don't consider last day of month when month change.
It makes crash issue when create DateTime.

src/Tizen.NUI.Components/Controls/DatePicker.cs

index 1d8fa50..5b8b132 100755 (executable)
@@ -209,7 +209,7 @@ namespace Tizen.NUI.Components
 
             PickersOrderSet();
             SetMonthText();
-            MaxDaySet();
+            MaxDaySet(currentDate.Year, currentDate.Month);
         }
 
         private void OnDayValueChanged(object sender, ValueChangedEventArgs e)
@@ -225,8 +225,7 @@ namespace Tizen.NUI.Components
         { 
             if (currentDate.Month == e.Value) return;
 
-            currentDate = new DateTime(currentDate.Year, e.Value, currentDate.Day);
-            MaxDaySet();
+            MaxDaySet(currentDate.Year, e.Value);
 
             OnDateChanged();
         }
@@ -235,8 +234,7 @@ namespace Tizen.NUI.Components
         { 
             if (currentDate.Year == e.Value) return;
 
-            currentDate = new DateTime(e.Value, currentDate.Month, currentDate.Day);
-            MaxDaySet();
+            MaxDaySet(e.Value, currentDate.Month);
 
             OnDateChanged();
         }
@@ -247,17 +245,17 @@ namespace Tizen.NUI.Components
             DateChanged?.Invoke(this, eventArgs);
         }
 
-        private void MaxDaySet()
+        private void MaxDaySet(int year, int month)
         {
-            int maxDaysInMonth = DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
+            int maxDaysInMonth = DateTime.DaysInMonth(year, month);
             dayPicker.MaxValue = maxDaysInMonth;
             if (currentDate.Day > maxDaysInMonth)
             {
-                currentDate = new DateTime(currentDate.Year, currentDate.Month, maxDaysInMonth);
+                currentDate = new DateTime(year, month, maxDaysInMonth);
                 dayPicker.CurrentValue = maxDaysInMonth;
                 return;
             }
-            currentDate = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day);
+            currentDate = new DateTime(year, month, currentDate.Day);
         }
 
         //FIXME: There is no way to know when system locale changed in NUI.