Reduce instantiation of CultureInfo
Some checks failed
Build .NET Project / build (push) Has been cancelled

This commit is contained in:
2026-03-05 17:20:42 -05:00
parent d41832617d
commit 709285b590
5 changed files with 35 additions and 20 deletions

View File

@@ -11,6 +11,8 @@ namespace MarketData.Utils
{
public class FeedParser
{
private static readonly System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
private FeedParser()
{
}
@@ -58,6 +60,7 @@ namespace MarketData.Utils
periodEnding = periodEnding.Replace("Period Ending", "");
int length = periodEnding.Length;
int index = 0;
while (index < length)
{
String strMonth = periodEnding.Substring(index, 3);
@@ -69,7 +72,7 @@ namespace MarketData.Utils
sb = new StringBuilder();
for (int yIndex = 0; yIndex < 5; yIndex++) sb.Append(periodEnding[index++]);
String strYear = sb.ToString().Trim();
DateTime periodEndingDate = DateTime.ParseExact(strMonth + Utility.Pad(strDay, '0', 2) + strYear, "MMMddyyyy", new System.Globalization.CultureInfo("en-US"));
DateTime periodEndingDate = DateTime.ParseExact(strMonth + Utility.Pad(strDay, '0', 2) + strYear, "MMMddyyyy", cultureInfo);
periodEndingDates.Add(periodEndingDate);
}
return periodEndingDates;
@@ -85,12 +88,12 @@ namespace MarketData.Utils
strText = strText + " " + DateTime.Now.Year.ToString();
string[] items = strText.Split(' ');
strText = items[0] + "-" + Utility.Pad(items[1], '0', 2) + "-" + items[2];
return DateTime.ParseExact(strText, "MMM-dd-yyyy", new System.Globalization.CultureInfo("en-US"));
return DateTime.ParseExact(strText, "MMM-dd-yyyy", cultureInfo);
}
else
{
strText = strText.Replace(" ", "0");
return DateTime.ParseExact(strText, "dd-MMM-yy", new System.Globalization.CultureInfo("en-US"));
return DateTime.ParseExact(strText, "dd-MMM-yy", cultureInfo);
}
}
catch (Exception)