private static DateTime GetWorkDate(IWorkComment comment, string partialComment) { using (MiniProfiler.Current.Step("Getting work date")) { var workPattern = new Regex($@"{_strWorkPattern}(.)*?({_strDatePattern})?{_strHourPattern}", RegexOptions.IgnoreCase); var matchWork = workPattern.Match(partialComment); if (matchWork.Success) { var dateFormat = new CultureInfo("pt-BR", false).DateTimeFormat; var matchDate = new Regex(_strDatePattern, RegexOptions.IgnoreCase).Match(matchWork.Value); var hourText = new Regex(_strHourPattern, RegexOptions.IgnoreCase).Match(matchWork.Value) .Value.Split(':') .Aggregate((text, next) => text.PadLeft(2, '0') + ":" + next.PadLeft(2, '0')); if (matchDate.Success) return Convert.ToDateTime($"{matchDate.Value} {hourText}:00", dateFormat); var dateTime = comment.When.ConvertUtcToFortalezaTimeZone(); return Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{dateTime.Day} {hourText}:00", dateFormat); } return comment.When.ConvertUtcToFortalezaTimeZone(); } }
private static IEnumerable<IWorkComment> ExtractWorkFromComment(IWorkComment comment) { using (MiniProfiler.Current.Step("Extract work from comment")) { var workPattern = new Regex($@"{_strWorkPattern}(.)*({_strDatePattern})?({_strHourPattern})?", RegexOptions.IgnoreCase); var matchesWork = workPattern.Matches(comment.RawComment); var workComments = new List<IWorkComment>(); if (matchesWork.Count > 0) { workComments.AddRange(from Match match in matchesWork select new WorkComment { Who = comment.Who, WorkEventType = GetWorkEventType(match.Value), When = GetWorkDate(comment, match.Value), RawComment = comment.RawComment }); } return workComments; } }