Reduce instantiation of CultureInfo
Some checks failed
Build .NET Project / build (push) Has been cancelled
Some checks failed
Build .NET Project / build (push) Has been cancelled
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace MarketData.Utils
|
||||
{
|
||||
public class Utility
|
||||
{
|
||||
private static DateTime epoch = DateTime.Parse("01-01-0001");
|
||||
private static TimeSpan oneDay=new TimeSpan(1,0,0,0);
|
||||
private static readonly DateTime epoch = DateTime.Parse("01-01-0001");
|
||||
private static readonly TimeSpan oneDay=new TimeSpan(1,0,0,0);
|
||||
private static readonly System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
|
||||
private static readonly String[] formats=new[] { "MMMM dd,yyyy" ,"yyyy-MM-dd HH:mm:ss","MM/dd/yyyy HH:MM tt", "yyyy-MM-dd","yy-MM-dd","yyyy-MM-dd hh:mm:ss tt","dddd, MMMM dd","MMM dd yyyy","yyyy-MM","ddd, MMM. d","ddd, MMM. dd","yyyy/MM/dd","M-d-yyyy","dd-MM-yyyy","MM-dd-yyyy","M.d.yyyy","dd.MM.yyyy","MM.dd.yyyy","yyyyMMdd" }.Union(cultureInfo.DateTimeFormat.GetAllDateTimePatterns()).ToArray();
|
||||
|
||||
public static bool IsProcessRunning(String processName, List<String> commandArgs)
|
||||
{
|
||||
@@ -608,9 +610,6 @@ namespace MarketData.Utils
|
||||
}
|
||||
public static DateTime ParseDate(String strDate)
|
||||
{
|
||||
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
|
||||
|
||||
String[] formats=new[] { "MMMM dd,yyyy" ,"yyyy-MM-dd HH:mm:ss","MM/dd/yyyy HH:MM tt", "yyyy-MM-dd","yy-MM-dd","yyyy-MM-dd hh:mm:ss tt","dddd, MMMM dd","MMM dd yyyy","yyyy-MM","ddd, MMM. d","ddd, MMM. dd","yyyy/MM/dd","M-d-yyyy","dd-MM-yyyy","MM-dd-yyyy","M.d.yyyy","dd.MM.yyyy","MM.dd.yyyy","yyyyMMdd" }.Union(cultureInfo.DateTimeFormat.GetAllDateTimePatterns()).ToArray();
|
||||
strDate = strDate.Trim();
|
||||
DateTime dateTime=DateTime.ParseExact(strDate, formats, cultureInfo, DateTimeStyles.AssumeLocal);
|
||||
return dateTime;
|
||||
|
||||
Reference in New Issue
Block a user