From bc5905fdad203dfdce18119044ccc393088b28fa Mon Sep 17 00:00:00 2001 From: Hugh Zabriskie Date: Wed, 7 Mar 2018 14:39:22 -0800 Subject: 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 --- .../shared/System/Globalization/GregorianCalendar.cs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src') 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; -- cgit v1.2.3