public Task(string task, DateTime today, ILinkValidator linkValidator = null) { Description = task; var pattern = new Regex(@"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s(\d{1,2})"); if (pattern.IsMatch(task)) { var match = pattern.Match(task); var month = match.Groups[1].Value; var mValue = DateTime.ParseExact(month, "MMM", CultureInfo.CurrentCulture).Month; var day = Convert.ToInt32(match.Groups[2].Value); var year = today.Year; if (mValue < today.Month || (mValue == today.Month && day < today.Day)) { year++; } if (day <= DateTime.DaysInMonth(year, mValue)) { DueDate = new DateTime(year, mValue, day); } } var linkpattern = new Regex(@"(http://[^\s]+)"); if (linkpattern.IsMatch(task)) { var link = linkpattern.Match(task).Groups[1].Value; linkValidator.Validate(link); Link = link; } }
//ILinkValidator linkValidator = null public Task(string task, DateTime today, ILinkValidator linkValidator = null) { Description = task; var dueDatePattern = new Regex(@"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s(\d+)"); var hasDueDate = dueDatePattern.IsMatch(task); if (hasDueDate) { var dueDate = dueDatePattern.Match(task); var monthInput = dueDate.Groups[1].Value; var year = today.Year; var month = DateTime.ParseExact(monthInput, "MMM", CultureInfo.CurrentCulture).Month; var day = Convert.ToInt32(dueDate.Groups[2].Value); var shouldWrapYear = month < today.Month || (month == today.Month && day < today.Day); if (shouldWrapYear) year++; if (day <= DateTime.DaysInMonth(year, month)) { DueDate = new DateTime(year, month, day); } } var linkPattern = new Regex(@"(http://[^\s]+)"); var hasLink = linkPattern.IsMatch(task); if (hasLink) { var link = linkPattern.Match(task).Groups[1].Value; linkValidator.Validate(link); Link = link; } }
public Task(string task, DateTime today, ILinkValidator linkValidator = null) { Description = task; var dueDatePattern = new Regex(@"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s(\d+)"); var hasDueDate = dueDatePattern.IsMatch(task); if (hasDueDate) { var dueDate = dueDatePattern.Match(task); var monthInput = dueDate.Groups[1].Value; var month = DateTime.ParseExact(monthInput, "MMM", CultureInfo.CurrentCulture).Month; var day = Convert.ToInt32(dueDate.Groups[2].Value); var year = today.Year; var shouldWrapYear = month < today.Month || (month == today.Month && day < today.Day); if (shouldWrapYear) { year++; } if (day <= DateTime.DaysInMonth(year, month)) { DueDate = new DateTime(year, month, day); } } var priorityPattern = new Regex(@"!(\d)"); var hasPriority = priorityPattern.IsMatch(task); if (hasPriority) { var priority = priorityPattern.Match(task); Priority = priority.Groups[1].Value; } else { Priority = "Not Set"; } var linkPattern = new Regex(@"(http://[^\s]+)"); var hasLink = linkPattern.IsMatch(task); if (hasLink) { var link = linkPattern.Match(task).Groups[1].Value; linkValidator.Validate(link); Link = link; } }