Perf fix for month-day parsing ambiguity (#16782)
authorHugh Zabriskie <hugh.zabriskie@gmail.com>
Wed, 7 Mar 2018 22:39:22 +0000 (14:39 -0800)
committerDan Moseley <danmose@microsoft.com>
Wed, 7 Mar 2018 22:39:22 +0000 (14:39 -0800)
* Perf fix for month-day parsing ambiguity

* Use DateTime.TryCreate

src/mscorlib/shared/System/Globalization/GregorianCalendar.cs

index 1602320..94963a1 100644 (file)
@@ -520,25 +520,11 @@ namespace System.Globalization
             throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
         }
 
-        internal override Boolean TryToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era, out DateTime result)
+        internal override bool TryToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era, out DateTime result)
         {
             if (era == CurrentEra || era == ADEra)
             {
-                try
-                {
-                    result = new DateTime(year, month, day, hour, minute, second, millisecond);
-                    return true;
-                }
-                catch (ArgumentOutOfRangeException)
-                {
-                    result = DateTime.Now;
-                    return false;
-                }
-                catch (ArgumentException)
-                {
-                    result = DateTime.Now;
-                    return false;
-                }
+                return DateTime.TryCreate(year, month, day, hour, minute, second, millisecond, out result);
             }
             result = DateTime.MinValue;
             return false;