Remove BigCharts pricing feed. Add Robinhood price feed

This commit is contained in:
2025-10-17 18:04:13 -04:00
parent a864a49cb3
commit 20cdbfa942
7 changed files with 678 additions and 965 deletions

View File

@@ -17,6 +17,8 @@ using MarketData.DataAccess;
using MarketData.Integration;
using System.Globalization;
using MarketDataLib.Utility;
using MarketData.Configuration;
using System.Text.Json;
//Zacks Rank - Zacks
//Splits - EODDATA
@@ -76,12 +78,8 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("No data returned for request {0}",strRequest));
return false;
}
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetWorldTime Received {0} bytes of data.",httpNetResponse.ResponseString.Length));
return true;
}
catch (Exception exception)
{
@@ -94,9 +92,6 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("MarketData.GetWorldTime: Done, took {0}(ms)", profiler.End()));
}
}
// ******************************************************************************************************************************************************************************
// ************************************************************************************ P R E M A R K E T D A T A ***********************************************************
// ******************************************************************************************************************************************************************************
@@ -4574,7 +4569,7 @@ namespace MarketData.Helper
return null;
}
DateTime currentMarketDate=PremarketDA.GetLatestMarketDate();
LatestPriceDelegate[] latestPriceDelegates=new LatestPriceDelegate[]{GetLatestPriceBarChart,GetLatestPriceYahoo,GetLatestPriceBigCharts,GetLatestPriceGoogle};
LatestPriceDelegate[] latestPriceDelegates=new LatestPriceDelegate[]{GetLatestPriceBarChart,GetLatestPriceYahoo,GetLatestPriceRobinhood,GetLatestPriceGoogle};
Price latestPrice=null;
foreach(LatestPriceDelegate latestPriceDelegate in latestPriceDelegates)
{
@@ -4591,10 +4586,7 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("The date retrieved for {0} via {1} does not match the current market date. Market Date: {2} Price Date: {3}",symbol,latestPriceDelegate.Method.Name,currentMarketDate.ToShortDateString(),latestPrice.Date.ToShortDateString()));
}
}
}
latestPrice=GetPriceAsOf(symbol,currentMarketDate); // try to get the price from MarketWatch historical feed using todays date
if(null!=latestPrice && latestPrice.Date.Date.Equals(currentMarketDate.Date)) return latestPrice;
}
if(null!=companyProfile && companyProfile.CanRollPrevious)
{
latestPrice=PricingMarketDataHelper.RollPriceForward(symbol);
@@ -4901,113 +4893,6 @@ namespace MarketData.Helper
}
}
// This is used in the intra-day price feed.
public static Price GetLatestPriceBigCharts(String symbol)
{
HttpNetResponse httpNetResponse=null;
MemoryStream memoryStream=null;
try
{
StringBuilder sb = new StringBuilder();
String strRequest;
if(null==symbol) return null;
sb.Append("http://bigcharts.marketwatch.com/quickchart/quickchart.asp?symb=").Append(symbol).Append("&insttype=Stock").Append(symbol);
strRequest = sb.ToString();
WebProxy webProxy=HttpNetRequest.GetProxy("GetLatestPriceBigCharts");
httpNetResponse=HttpNetRequest.GetRequestNoEncoding(strRequest,webProxy);
if(!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
return null;
}
Price price = new Price();
price.Symbol = symbol.ToUpper();
price.Date = DateTime.Now;
price.Source=Price.PriceSource.BigCharts;
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
memoryStream = new MemoryStream(streamBytes);
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.Load(memoryStream);
HtmlNodeCollection table = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"quickchart\"]");
if(null==table||0==table.Count)return null;
HtmlNodeCollection divSection = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"maincontent\"]");
if(null==divSection)return null;
HtmlNodeCollection rows = divSection[0].SelectNodes(".//tr");
if(rows.Count<3)return null;
HtmlNode softTimeNode = htmlDocument.DocumentNode.SelectSingleNode("//*[@class=\"soft time\"]");
if(null!=softTimeNode)
{
DateTime givenDate=ConvertBigChartsDate(softTimeNode.InnerHtml);
if(!Utility.IsEpoch(givenDate))price.Date=givenDate;
}
HtmlNodeCollection dataColumns = rows[2].SelectNodes(".//td");
for(int index=0;index<dataColumns.Count;index++)
{
String innerText=Utility.RemoveControlChars(dataColumns[index].InnerText).Trim();
String[] items=innerText.Split(':');
if(null==items||2!=items.Length)continue;
if("Last".Equals(items[0])){price.Close=FeedParser.ParseValue(items[1]);price.AdjClose=price.Close;}
else if("Open".Equals(items[0]))price.Open=FeedParser.ParseValue(items[1]);
else if("High".Equals(items[0]))price.High=FeedParser.ParseValue(items[1]);
else if("Low".Equals(items[0]))price.Low=FeedParser.ParseValue(items[1]);
else if("Volume".Equals(items[0]))price.Volume=FeedParser.ParseValueLong(items[1]);
}
if(double.IsNaN(price.Open)&&double.IsNaN(price.High)&&double.IsNaN(price.Low)&&double.IsNaN(price.Close))
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("*** No closing price for {0}",price.Symbol));
return null;
}
if(double.IsNaN(price.Open))price.Open=0.00;
if(double.IsNaN(price.Low))price.Low=0.00;
if(double.IsNaN(price.High))price.High=0.00;
if(0!=price.Close&&0==price.Open&&0==price.High&&0==price.Low)
{
price.Open=price.High=price.Low=price.Close;
}
return price;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
return null;
}
finally
{
if(null!=httpNetResponse)httpNetResponse.Dispose();
if(null!=memoryStream){memoryStream.Close();memoryStream.Dispose();}
}
}
// This seems necessary on ARM64. Utility.ParseDate() works on windows with the same exact string.
private static DateTime ConvertBigChartsDate(String strDate)
{
try
{
StringBuilder sb = new StringBuilder();
if(String.IsNullOrEmpty(strDate))return Utility.Epoch;
String[] elements = strDate.Split(' ');
if(3!=elements.Length)return Utility.Epoch;
String[] dateElements = elements[0].Split('/');
if(3!=dateElements.Length)return Utility.Epoch;
sb.Append(Utility.Pad(dateElements[0],'0',2));
sb.Append("/");
sb.Append(Utility.Pad(dateElements[1],'0',2));
sb.Append("/");
sb.Append(Utility.Pad(dateElements[2],'0',2));
sb.Append(" ");
sb.Append(elements[1]);
sb.Append(" ");
sb.Append(elements[2]);
return Convert.ToDateTime(sb.ToString());
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,$"[ConvertBigChartsDate] Date:{strDate} {exception.ToString()}");
return Utility.Epoch;
}
}
public static Price GetLatestPriceGoogle(String symbol)
{
HttpNetResponse httpNetResponse=null;
@@ -5205,62 +5090,45 @@ namespace MarketData.Helper
return barChartValues;
}
// *******************************************************************************************************************************************************************************
// ************************************************************** H I S T O R I C A L P R I C E S - B I G C H A R T S ********************************************************
// *******************************************************************************************************************************************************************************
// ************************************************************** L A T E S T P R I C E - R O B I N H O O D ******************************************************************
// *******************************************************************************************************************************************************************************
/// <summary>
/// Gets historical pricing from BigCharts
/// This version fetches the latest price from robinhood and ensures that the pricing date is what we expect
/// </summary>
/// <param name="symbol"></param>
/// <param name="startDate">Most recent date</param>
/// <param name="endDate">Most historical date</param>
/// <returns>Prices</returns>
public static Prices GetPricesAsOf(String symbol, DateTime startDate, DateTime endDate)
/// <param name="startDate"></param>
/// <returns></returns>
public static Price GetPriceRobinHood(String symbol, DateTime startDate)
{
Prices prices = new Prices();
if (null == symbol) return null;
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
if (null != companyProfile && companyProfile.FreezePricing)
try
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
Price price = GetLatestPriceRobinhood(symbol);
if (null == price) return null;
if (!price.Date.Date.Equals(startDate.Date))
{
MDTrace.WriteLine(LogLevel.DEBUG, $"Error, the price retrieved from Robinhood for : {symbol} is dated {price.Date.Date.ToShortDateString()} , expected {startDate.Date.ToShortDateString()}.");
return null;
}
return price;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception : {0}", exception.ToString()));
return null;
}
DateGenerator dateGenerator = new DateGenerator();
List<DateTime> dates = dateGenerator.GenerateHistoricalDates(startDate, endDate);
for (int index = 0; index < dates.Count; index++)
{
DateTime currentDate = dates[index];
Price price = GetPriceAsOfV2(symbol, currentDate);
if (null == price)
{
price = GetPriceAsOf(symbol, currentDate);
if (null == price)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("No price for {0} on {1}", symbol, Utility.DateTimeToStringMMHDDHYYYY(currentDate)));
continue;
}
}
prices.Add(price);
}
return prices;
}
/// <summary>
/// The main BigChart Feed which is no longer working
/// This version fetches the latest price from Robinhood
/// </summary>
/// <param name="symbol"></param>
/// <param name="asOf"></param>
/// <returns></returns>
public static Price GetPriceAsOf(String symbol, DateTime asOf)
public static Price GetLatestPriceRobinhood(string symbol)
{
HttpNetResponse httpNetResponse = null;
try
{
String strRequest;
StringBuilder sb = null;
if (null == symbol) return null;
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
if (null != companyProfile && companyProfile.FreezePricing)
@@ -5268,18 +5136,54 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
return null;
}
StringBuilder sb = new StringBuilder();
String requestSymbol = symbol;
String strRequest = default;
if (requestSymbol.StartsWith("^")) requestSymbol = requestSymbol.Substring(1);
sb = new StringBuilder();
sb.Append("http://bigcharts.marketwatch.com/historical/default.asp?symb=");
sb.Append(requestSymbol);
sb.Append("&closeDate=");
sb.Append(asOf.Month.ToString());
sb.Append("%2F");
sb.Append(asOf.Day.ToString());
sb.Append("%2F");
sb.Append((asOf.Year - 2000).ToString());
sb.Append("&x=38&y=25");
sb.Append("https://robinhood.com/us/en/stocks/").Append(symbol).Append("/");
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG, $"{strRequest}");
httpNetResponse = HttpNetRequest.GetRequestNoEncoding(strRequest);
if (!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
return null;
}
String strInstrumentId = Utility.BetweenString(httpNetResponse.ResponseString, "<meta content=\"robinhood://instrument?id=", "\"");
if (null == strInstrumentId) return null;
List<String> spanSections = Sections.GetAllItemsInSections(httpNetResponse.ResponseString, "span");
String strOpen = Sections.ScanSectionsFindStartWithReturnIndexAfter(spanSections, "<span class=\"css-eimp3v\">Open price</span>", 1);
if (null == strOpen) return null;
strOpen = Utility.BetweenString(strOpen, ">", "<");
if (null == strOpen) return null;
if (strOpen.Equals("???")) strOpen = null;
String strHigh = Sections.ScanSectionsFindStartWithReturnIndexAfter(spanSections, "<span class=\"css-eimp3v\">High today</span>", 1);
if (null == strHigh) return null;
strHigh = Utility.BetweenString(strHigh, ">", "<");
if (null == strHigh) return null;
if (strHigh.Equals("???")) strHigh = null;
String strLow = Sections.ScanSectionsFindStartWithReturnIndexAfter(spanSections, "<span class=\"css-eimp3v\">Low today</span>", 1);
if (null == strLow) return null;
strLow = Utility.BetweenString(strLow, ">", "<");
if (null == strLow) return null;
if (strLow.Equals("???")) strLow = null;
String strVolume = Sections.ScanSectionsFindStartWithReturnIndexAfter(spanSections, "<span class=\"css-v72tci\">Volume</span>", 1);
if (null == strVolume) return null;
strVolume = Utility.BetweenString(strVolume, ">", "<");
if (null == strVolume) return null;
if (strVolume.Equals("???")) strVolume = null;
// Fetch the current price
httpNetResponse.Dispose();
sb = new StringBuilder();
sb.Append("https://bonfire.robinhood.com/instruments/").Append(strInstrumentId).Append("/detail-page-live-updating-data/?display_span=day&hide_extended_hours=false");
strRequest = sb.ToString();
httpNetResponse = HttpNetRequest.GetRequestNoEncoding(strRequest);
if (!httpNetResponse.Success)
@@ -5287,164 +5191,43 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
return null;
}
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
MemoryStream memoryStream = new MemoryStream(streamBytes);
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.Load(memoryStream);
HtmlNodeCollection tables = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"historicalquote fatbottomed\"]");
if (null == tables || 0 == tables.Count) return null;
HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");
if (rows.Count < 7) return null;
JsonDocument jsonDocument = JsonDocument.Parse(httpNetResponse.ResponseString);
JsonElement root = jsonDocument.RootElement;
JsonElement chartSection = root.GetProperty("chart_section");
JsonElement quoteSection = chartSection.GetProperty("quote");
String strLastTradePrice = quoteSection.GetProperty("last_trade_price").GetString();
String strUpdatedAt = quoteSection.GetProperty("updated_at").GetString();
String strSymbol = quoteSection.GetProperty("symbol").GetString();
DateTime lastUpdatedAt = DateTime.Parse(strUpdatedAt, null, System.Globalization.DateTimeStyles.RoundtripKind);
Price price = new Price();
price.Source = Price.PriceSource.BigCharts;
price.Symbol = symbol.ToUpper();
price.Date = FeedParser.ParseValueDateTimeMonthFormatFromMarketWatch(rows[1].InnerText);
price.Close = FeedParser.ParseValueFromMarketWatch("Closing Price:", rows[2].InnerText);
price.AdjClose = price.Close;
price.Open = FeedParser.ParseValueFromMarketWatch("Open:", rows[3].InnerText);
price.High = FeedParser.ParseValueFromMarketWatch("High:", rows[4].InnerText);
price.Low = FeedParser.ParseValueFromMarketWatch("Low:", rows[5].InnerText);
price.Volume = FeedParser.ParseLongValueFromMarketWatch("Volume:", rows[6].InnerText);
if (!(price.Date.Date.Equals(asOf.Date.Date)))
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("The price retrieved for {0} does not contain the requested date. Requested date {1} Retrieved date {2}", symbol, price.Date.ToShortDateString(), asOf.ToShortDateString()));
return null;
}
price.Symbol = strSymbol;
price.Date = lastUpdatedAt;
price.Source = Price.PriceSource.Robinhood;
price.Close = price.AdjClose = FeedParser.ParseValueDouble(strLastTradePrice);
price.Open = Utility.ParseCurrency(strOpen);
price.High = Utility.ParseCurrency(strHigh);
price.Low = Utility.ParseCurrency(strLow);
price.Volume = (long)FeedParser.ParseValueDouble(strVolume);
CheckPrice(price);
if (!price.IsValid) return null;
if (!price.Symbol.Equals(symbol)) return null;
MDTrace.WriteLine(LogLevel.DEBUG, $"Got price from Robinhood for {symbol} : {price.ToString()}");
return price;
}
catch (Exception)
{
return null;
}
finally
{
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
/// <summary>
/// This is a modified version of the above query. It uses a cookie collection that contains the datadome cookie.
/// If this query starts to fail then you should try the query in developer tools in the chromium browser and capture the
/// datadome value and update it here in the GetCookieCollection() below.
/// </summary>
/// <param name="symbol"></param>
/// <param name="asOf"></param>
/// <returns></returns>
public static Price GetPriceAsOfV2(String symbol, DateTime asOf)
{
HttpNetResponse httpNetResponse = null;
try
{
String strRequest;
StringBuilder sb = null;
if (null == symbol) return null;
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
if (null != companyProfile && companyProfile.FreezePricing)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
return null;
}
String requestSymbol = symbol;
if (requestSymbol.StartsWith("^")) requestSymbol = requestSymbol.Substring(1);
sb = new StringBuilder();
sb.Append("http://bigcharts.marketwatch.com/historical/default.asp?symb=");
sb.Append(requestSymbol);
sb.Append("&closeDate=");
sb.Append(asOf.Month.ToString());
sb.Append("%2F");
sb.Append(asOf.Day.ToString());
sb.Append("%2F");
sb.Append((asOf.Year - 2000).ToString());
sb.Append("&x=38&y=25");
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG,$"{strRequest}");
CookieCollection cookieCollection = GetCookieCollection("www.marketwatch.com");
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV2(strRequest,cookieCollection,new Uri("https://www.marketwatch.com/investing"));
if (!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
return null;
}
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
MemoryStream memoryStream = new MemoryStream(streamBytes);
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.Load(memoryStream);
HtmlNodeCollection tables = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"table table--overflow align--center\"]");
if (null == tables || 0 == tables.Count) return null;
HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");
if (rows.Count < 2) return null;
Prices prices = new Prices();
for (int rowIndex = 1; rowIndex < rows.Count; rowIndex++)
{
HtmlNodeCollection data = rows[rowIndex].SelectNodes(".//td");
if (data.Count != 6)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("The price retrieved for {0} does not contain the correct number of data elements (expected 6 data elements).", symbol));
return null;
}
Price price = new Price();
price.Source = Price.PriceSource.BigCharts;
price.Symbol = symbol.ToUpper();
String[] dateElements = data[0].InnerText.Trim().Split(" ");
price.Date = Utility.ParseDate(dateElements[0].Replace("\n", null));
price.Open = Utility.ParseCurrency(data[1].InnerText.Trim().Replace("\n", null));
price.High = Utility.ParseCurrency(data[2].InnerText.Trim().Replace("\n", null));
price.Low = Utility.ParseCurrency(data[3].InnerText.Trim().Replace("\n", null));
price.Close = price.AdjClose = Utility.ParseCurrency(data[4].InnerText.Trim().Replace("\n", null));
price.Volume = FeedParser.ParseValueLong(data[5].InnerText.Trim());
prices.Add(price);
}
Price selectedPrice = prices.Where(x => x.Date.Date.Equals(asOf.Date.Date)).FirstOrDefault();
if (null == selectedPrice)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("No price for {0} on {1}", symbol, asOf.ToShortDateString()));
return null;
}
return selectedPrice;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception : {0}", exception.ToString()));
return null;
return null;
}
finally
{
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
private static CookieCollection GetCookieCollection(String cookieDomain)
{
String[] cookies = {
"datadome=VLSWQ1PWL4SV2rljkJEV7GUOK3T11Sm73RP17IwDEtRzfWHykYwy7ZoeSPrjwmbwvGRAenazmLVTpyCB6Yqlw6vUL6Wbqq4zML5DGuHLxNU4LgAQ7Ko9tztglqjIGLZE",
};
CookieCollection cookieCollection = new CookieCollection();
for (int index = 0; index < cookies.Count(); index++)
{
String strCookie = cookies[index];
if (strCookie.EndsWith(";")) strCookie = strCookie.Substring(0, strCookie.Length - 1);
String[] pairs = strCookie.Split('=');
cookieCollection.Add(new Cookie()
{
Name = pairs[0],
Value = pairs[1],
Domain = cookieDomain
});
}
return cookieCollection;
}
//********************************************************************************************************************************************************************************************************
//********************************************************************************************************************************************************************************************************
// ******************************************************************************** H I S T O R I C A L P R I C I N G Y A H O O *********************************************************************
//********************************************************************************************************************************************************************************************************
@@ -5737,43 +5520,57 @@ namespace MarketData.Helper
}
}
public static List<String> FindItemsInTag(String item, List<List<String>> itemTags)
{
List<String> foundItems = new List<String>();
if (null == itemTags || 0 == itemTags.Count) return null;
for (int index = 0; index < itemTags.Count; index++)
{
List<String> itemTag = itemTags[index];
if (itemTag[0].Equals(item)) foundItems.Add(itemTag[1]);
}
return foundItems;
}
private static DateTime ProcessNASDAQRelativeDate(String relativeDate)
{
DateTime referenceDate=DateTime.Now;
string[] items=relativeDate.Split(' ');
if(items.Length<2)return Utility.Epoch;
if("days".Equals(items[1])||"day".Equals(items[1]))
{
TimeSpan timeSpan=new TimeSpan(int.Parse(items[0]),0,0,0,0);
referenceDate-=timeSpan;
}
else if("hours".Equals(items[1])||"hour".Equals(items[1]))
{
TimeSpan timeSpan=new TimeSpan(int.Parse(items[0]),0,0);
referenceDate-=timeSpan;
}
else if("mins".Equals(items[1]) || "minutes".Equals(items[1]))
{
TimeSpan timeSpan=new TimeSpan(0,int.Parse(items[0]),0);
referenceDate-=timeSpan;
}
else if( (new string[]{"Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun"}).Any(x=>x.Equals(items[0])))
{
DateTime now=DateTime.Now;
StringBuilder sb=new StringBuilder();
sb.Append(items[0]).Append(" ").Append(Utility.Pad(items[1],'0',2)).Append(" ").Append(referenceDate.Year);
referenceDate=Utility.ParseDate(sb.ToString());
if(referenceDate>now)
{
sb=new StringBuilder();
sb.Append(items[0]).Append(" ").Append(Utility.Pad(items[1],'0',2)).Append(" ").Append(referenceDate.Year-1);
referenceDate=Utility.ParseDate(sb.ToString());
}
}
else referenceDate=Utility.Epoch;
if(referenceDate>DateTime.Now)referenceDate=Utility.Epoch;
return referenceDate;
}
{
DateTime referenceDate = DateTime.Now;
string[] items = relativeDate.Split(' ');
if (items.Length < 2) return Utility.Epoch;
if ("days".Equals(items[1]) || "day".Equals(items[1]))
{
TimeSpan timeSpan = new TimeSpan(int.Parse(items[0]), 0, 0, 0, 0);
referenceDate -= timeSpan;
}
else if ("hours".Equals(items[1]) || "hour".Equals(items[1]))
{
TimeSpan timeSpan = new TimeSpan(int.Parse(items[0]), 0, 0);
referenceDate -= timeSpan;
}
else if ("mins".Equals(items[1]) || "minutes".Equals(items[1]))
{
TimeSpan timeSpan = new TimeSpan(0, int.Parse(items[0]), 0);
referenceDate -= timeSpan;
}
else if ((new string[] { "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun" }).Any(x => x.Equals(items[0])))
{
DateTime now = DateTime.Now;
StringBuilder sb = new StringBuilder();
sb.Append(items[0]).Append(" ").Append(Utility.Pad(items[1], '0', 2)).Append(" ").Append(referenceDate.Year);
referenceDate = Utility.ParseDate(sb.ToString());
if (referenceDate > now)
{
sb = new StringBuilder();
sb.Append(items[0]).Append(" ").Append(Utility.Pad(items[1], '0', 2)).Append(" ").Append(referenceDate.Year - 1);
referenceDate = Utility.ParseDate(sb.ToString());
}
}
else referenceDate = Utility.Epoch;
if (referenceDate > DateTime.Now) referenceDate = Utility.Epoch;
return referenceDate;
}
// ****************************************************************************************************************************************************************************************
// **************************************************************************** H E L P E R M E T H O D S *******************************************************************************

File diff suppressed because it is too large Load Diff