/// <summary> /// Get time span from a <see cref="String"/> /// </summary> /// <param name="span">a string looks like "[Q1'18,Q1'18]"</param> /// <returns>Returns a <see cref="ProgramTimeSpan"/> structure.</returns> public static ProgramTimeSpan GetTimeSpan(string span) { ProgramTimeSpan mResult = new ProgramTimeSpan(); if (!span.Contains(",")) { return(mResult); } var mStr = span.Replace("[", "").Replace("]", "").ToUpper(); var mSpan = Strings.Split(mStr, ","); if (mSpan.Count() != 2) { return(mResult); } if (mSpan[0].Contains("'")) { var sQ = Strings.Split(mSpan[0], "'"); if (sQ[0].Contains("Q")) { if (!int.TryParse(sQ[0].Substring(1, 1), out var Quarterly)) { return(mResult); } if (!int.TryParse(sQ[1], out var Years)) { return(mResult); } Quarterly = Quarterly * 3 - 2; Years += 2000; var a = string.Format("{0}/01/{1}", Quarterly, Years); mResult.StartQuarterly = DateTime.ParseExact(string.Format("{0}/01/{1}", Quarterly, Years), "d", new CultureInfo("en-US")); } else { return(mResult); } } if (mSpan[1].Contains("'")) { var sQ = Strings.Split(mSpan[1], "'"); if (sQ[0].Contains("Q")) { if (!int.TryParse(sQ[0].Substring(1, 1), out var Quarterly)) { return(mResult); } if (!int.TryParse(sQ[1], out var Years)) { return(mResult); } Quarterly = Quarterly * 3; Years += 2000; mResult.EndQuarterly = DateTime.ParseExact(string.Format("{0}/30/{1}", Quarterly, Years), "d", new CultureInfo("en-US")); } else { return(mResult); } } return(mResult); }
/// <summary> /// Get time span from <see cref="ProgramTimeSpan"/> to <see cref="String"/> /// </summary> /// <returns>a string looks like "[Q1'18,Q1'18]"</returns> public static string GetTimeSpan(this ProgramTimeSpan span) => GetTimeSpan(span.StartQuarterly, span.EndQuarterly);