/// <summary> /// /// </summary> /// <param name="selectedValue"></param> /// <returns></returns> public static string GetSelectedValue(string selectedValue) { string rtnVal = TextUtility.PruneText(selectedValue); // If it is the empty row added from the collection, the return value should be null if (String.IsNullOrEmpty(rtnVal)) { rtnVal = null; } return(rtnVal); }
public static DateTime?TextTimeToNullableDate(string strTime, bool roundUp = false) { DateTime?rtnVal = null; strTime = TextUtility.PruneText(strTime); if (!String.IsNullOrEmpty(strTime)) { string time = null; string strNumber = null; string strText = null; TimeParser(strTime, out strNumber, out strText); // Prepend hours if missing a digit if (!String.IsNullOrEmpty(strNumber) && (strNumber.Length == 1 || strNumber.Length == 3)) { strNumber = "0" + strNumber; } // Append the minutes if missing if (!String.IsNullOrEmpty(strNumber) && strNumber.Length < 4) { strNumber = strNumber + "00"; } if (!String.IsNullOrEmpty(strNumber)) { time = strNumber.Substring(0, 2) + ":" + strNumber.Substring(2, 2); int hour = Int32.Parse(strNumber.Substring(0, 2)); // Implys 24 format if (hour > 12) { time = String.Format("{0:##}:{1}pm", hour - 12, strNumber.Substring(2, 2)); } else { if (!String.IsNullOrEmpty(strText)) { if (strText[0] == 'p' || strText[0] == 'P') { time += "pm"; } else { time += "am"; } } else { time += "am"; } } } DateTime date; if (DateTime.TryParse(time, out date)) { if (roundUp) { rtnVal = RoundTime(date); } else { rtnVal = date; } } } return(rtnVal); }