diff options
author | Hugh Zabriskie <hugh.zabriskie@gmail.com> | 2018-03-08 01:39:22 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-03-08 07:04:05 +0300 |
commit | bc5905fdad203dfdce18119044ccc393088b28fa (patch) | |
tree | 161cc5fe3cf92f510aac48eaa959aed88e8c97e3 | |
parent | 946b43eb13442627b7d736758362bc3807b3e8f6 (diff) |
Perf fix for month-day parsing ambiguity (dotnet/coreclr#16782)
* Perf fix for month-day parsing ambiguity
* Use DateTime.TryCreate
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs b/src/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs index 16023209e..94963a19c 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/GregorianCalendar.cs @@ -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; |