Skip to content

Instantly share code, notes, and snippets.

@nbuss848
Created May 11, 2018 13:44
Show Gist options
  • Save nbuss848/332471c21f91a09f883c44935c8829bc to your computer and use it in GitHub Desktop.
Save nbuss848/332471c21f91a09f883c44935c8829bc to your computer and use it in GitHub Desktop.
public void ParseReportName(string reportName)
{
string Result = String.Empty;
// Example: '$My Report Name : week ending $d-1'
// $d-1 = get todays date and subtract one and format it into MM/dd/yyyy
if(reportName.Contains("$"))
{
string formula = String.Empty;
string type = String.Empty; // d = date is the only supported type atm
// $ marks the start of the formula
for (int i = reportName.IndexOf('$') + 1; i < reportName.Length; i++)
{
if(reportName[i] == '\"')
{
continue;
}
formula += reportName[i];
}
type = formula[0].ToString();
if(type == "d")
{
DateTime today = DateTime.Today;
char Operator = formula[1];
string [] split = formula.Split(new char[] { '+', '-' },StringSplitOptions.RemoveEmptyEntries);
int number = Convert.ToInt32(split[1]);
reportName = reportName.Substring(0, reportName.IndexOf('$')).Trim();
if (Operator == '+') Result = reportName + " " + (today.AddDays(number).ToString("MM/dd/yyyy"));
if (Operator == '-') Result = reportName + " " + (today.AddDays(-number).ToString("MM/dd/yyyy"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment