Exemplo n.º 1
0
 // Uses the DateTimeRoutines library to parse the date
 // http://www.codeproject.com/Articles/33298/C-Date-Time-Parser
 public static DateTime FromFuzzyTime(string str, DateTimeRoutines.DateTimeFormat format = DateTimeRoutines.DateTimeFormat.USA_DATE)
 {
     DateTimeRoutines.ParsedDateTime dt;
     if (DateTimeRoutines.TryParseDateOrTime(str, format, out dt))
     {
         return(dt.DateTime);
     }
     throw new Exception("FromFuzzyTime parsing failed");
 }
 /// <summary>
 /// Tries to find date and time within the passed string and return it as ParsedDateTime object.
 /// </summary>
 /// <param name="str">string that contains date-time</param>
 /// <param name="default_format">format to be used preferably in ambivalent instances</param>
 /// <param name="parsed_date_time">parsed date-time output</param>
 /// <returns>true if both date and time were found, else false</returns>
 static public bool TryParseDateTime(this string str, DateTimeFormat default_format, out ParsedDateTime parsed_date_time)
 {
     if (DateTimeRoutines.TryParseDateOrTime(str, default_format, out parsed_date_time) &&
         parsed_date_time.IsDateFound &&
         parsed_date_time.IsTimeFound
         )
     {
         return(true);
     }
     parsed_date_time = null;
     return(false);
 }
Exemplo n.º 3
0
        // Uses the DateTimeRoutines library to parse the date
        // http://www.codeproject.com/Articles/33298/C-Date-Time-Parser
        public static DateTime FromFuzzyTime(string str, string format = null)
        {
            DateTimeRoutines.DateTimeFormat dt_format = DateTimeRoutines.DateTimeFormat.USA_DATE;
            if (format == "UK")
            {
                dt_format = DateTimeRoutines.DateTimeFormat.UK_DATE;
            }

            DateTimeRoutines.ParsedDateTime dt;
            if (DateTimeRoutines.TryParseDateOrTime(str, dt_format, out dt))
            {
                return(dt.DateTime);
            }
            throw new Exception("FromFuzzyTime parsing failed");
        }
Exemplo n.º 4
0
        public DateTime should_parse_date(string date)
        {
            DateTimeRoutines.TryParseDateOrTime(date, DateTimeRoutines.DateTimeFormat.USDate, out var parsedDateTime);

            return(parsedDateTime.DateTime);
        }