Exemple #1
0
        public static DateTime ToDateTime(this string txt)
        {
            if (string.IsNullOrEmpty(txt))
            {
                return(DateTime.MinValue);
            }
            string text = txt.Trim().ToLower();

            if (!text.StartsWith("$"))
            {
                return(DateTime.Parse(text));
            }
            if (text == "${today}")
            {
                return(DateTime.Today);
            }
            if (text == "${yesterday}")
            {
                return(DateTime.Today.AddDays(-1.0));
            }
            if (text == "${tommorrow}")
            {
                return(DateTime.Today.AddDays(1.0));
            }
            if (text == "${t}")
            {
                return(DateTime.Today);
            }
            if (text == "${t-1}")
            {
                return(DateTime.Today.AddDays(-1.0));
            }
            if (text == "${t+1}")
            {
                return(DateTime.Today.AddDays(1.0));
            }
            if (text == "${today+1}")
            {
                return(DateTime.Today.AddDays(1.0));
            }
            if (text == "${today-1}")
            {
                return(DateTime.Today.AddDays(-1.0));
            }
            string dateStr = text.Substring(2, text.Length - 1 - 2);

            return(DateParser.ParseTPlusMinusX(dateStr));
        }
Exemple #2
0
		public static DateTime ParseTPlusMinusX(string dateStr)
		{
			return DateParser.ParseTPlusMinusX(dateStr, DateTime.MinValue);
		}