I am implementing a Fuzzy Date control in C# for a winforms application. The Fuzzy Date should be able to take fuzzy values like
There is a bug in Piotr Czapla's answer:
new RegexDateTimePattern (
@"([2-9]\d*) *h(ours)? +ago",
delegate (Match m) {
var val = int.Parse(m.Groups[1].Value);
return DateTime.Now.AddMonths(-val);
}
),
AddMonths is used instead of AddHours().
PS: I can't comment on his answer because of low forum points. I've already wasted time on debugging it of why it removes 5 days when I try with "5 hours ago".