Fuzzy Date Time Picker Control in C# .NET?

后端 未结 4 1059
故里飘歌
故里飘歌 2020-12-05 06:01

I am implementing a Fuzzy Date control in C# for a winforms application. The Fuzzy Date should be able to take fuzzy values like

  • Last June
  • 2 Hours ago
4条回答
  •  感动是毒
    2020-12-05 06:32

    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".

提交回复
热议问题